日期:2014-05-18  浏览次数:21320 次

[技术分享]C#中使用IFELanguage进行分词和注音处理
from
http://blog.sina.com.cn/s/blog_589d32f501000aya.html
IFELanguage这个接口MSDN里可以查到
但C#的例子没有搜索到过
这里贴一个和大家分享

效果是这样:
=qǐngnínduìníndeyánxíngfùzézūnshǒuzhōnghuárénmíngònghéguóyǒuguānfǎlǜfǎguīzūnzhòngwǎngshàngdàodé
请(qǐng)
您(nín)
对(duì)
您(nín)
的(de)
言行(yánxíng)
负责(fùzé)

遵守(zūnshǒu)
中华人民共和国(zhōnghuárénmíngònghéguó)
有关(yǒuguān)
法律(fǎlǜ)

法规(fǎguī)
,
尊重(zūnzhòng)
网上(wǎngshàng)
道德(dàodé)

using   System.Runtime.InteropServices;
using   System.Runtime.CompilerServices;

[DllImport( "ole32.dll ")]
public   static   extern   int   CLSIDFromString(
        [MarshalAs(UnmanagedType.LPWStr)]   string   lpsz,  
        out   Guid   clsid);

[DllImport( "ole32.dll ")]
public   static   extern   int   CoCreateInstance(
        [In,   MarshalAs(UnmanagedType.LPStruct)]   Guid   clsid,
        IntPtr   pUnkOuter,   uint   dwClsContext,
        [In,   MarshalAs(UnmanagedType.LPStruct)]   Guid   iid,
        out   IntPtr   pv);

[DllImport( "ole32.dll ",   CallingConvention   =   CallingConvention.StdCall)]
public   static   extern   int   CoInitialize(IntPtr   pvReserved);

public   const   int   FELANG_REQ_REV   =   0x00030000;
public   const   int   FELANG_CMODE_PINYIN   =   0x00000100;
public   const   int   FELANG_CMODE_NOINVISIBLECHAR   =   0x40000000;

[ComImport]
[Guid( "019F7152-E6DB-11D0-83C3-00C04FDDB82E ")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public   interface   IFELanguage
{
        [MethodImpl(MethodImplOptions.InternalCall,  
                MethodCodeType   =   MethodCodeType.Runtime)]
        int   Open();
        [MethodImpl(MethodImplOptions.InternalCall,
                MethodCodeType   =   MethodCodeType.Runtime)]
        int   Close();
        [MethodImpl(MethodImplOptions.InternalCall,
                MethodCodeType   =   MethodCodeType.Runtime)]
        int   GetJMorphResult(
            [In]   uint   dwRequest,
            [In]   uint   dwCMode,
            [In]   int   cwchInput,
            [In,   MarshalAs(UnmanagedType.LPWStr)]   string   pwchInput,
            [In]   IntPtr   pfCInfo,
            [Out]   out   IntPtr   ppResult
        );
}

public   const   int   CLSCTX_INPROC_SERVER   =   1;
public   const   int   CLSCTX_INPROC_HANDLER   =   2;
public   const   int   CLSCTX_LOCAL_SERVER   =   4;
public