为了在插件中调用.NET控件,或者通过.NET库来开发插件,我需要接口描述文件(Interface Description File),这个文件描述了.NET程序中的接口,我们完全可以在C++中通过IDF(接口描述文件)来调用这个DLL中的接口。
C++插件可以识别这样的接口描述文件,并且可以在插件管理器中看到所有的接口描述信息。例如在BTradePrice.DLL中有如下的接口描述文件内容:
<?xml version="1.0" encoding="GB2312"?>
<Methods >
<Method Name=TradePrice.CustPrice.ShowPriceDialog(int nTradeCustomerID Description=这是显示价格的函数/>
<Method Name=TradePrice.CustPrice.ShowCustomerInfo(int nBTradeCustomerID) Description=这是显示客户信息的函数/>
</Methods>
在C++的插件中可以通过接口函数CString GetIDF()获得接口描述文件的内容,通过接口函数bool ExecuteNetMethod (CString sMethod)来实现对.NET接口的调用。
通过bool IsClrPlugin()判断是否是CLR类型的插件。
这需要在插件基类中增加这样的三个函数,并且在基类中可以判断是否存在该插件对应的XML配置,如果存在,则判断其中是否定义了.NET插件库。
<?xml version="1.0" encoding="GB2312"?>
<Setting>
<ClrPlugin>BTradePrice.DLL</ClrPlugin>
</Setting>
如果存在BTradePrice.DLL,则需要从BTradePrice中调用一个函数BTradePrice.NDKPlugin.IsNDKPlugin()函数判断是否是一个插件,通过BTradePrice.NDKPlugin.GetIDF()返回一个IDF字符串(XML格式)
这样,通过.NET开发插件只要创建一个DLL,然后在其中增加如下的两个函数即可:
NDKPlugin.IsNDKPlugin()
NDKPlugin.GetIDF()
可以实现在C++中调用.NET库中的函数。但是,C++中的Windows消息如何传递给.NET插件呢?这需要在C++插件的基类中将Window消息转发给.NET插件。
C++插件可以识别这样的接口描述文件,并且可以在插件管理器中看到所有的接口描述信息。例如在BTradePrice.DLL中有如下的接口描述文件内容:
<?xml version="1.0" encoding="GB2312"?>
<Methods >
<Method Name=TradePrice.CustPrice.ShowPriceDialog(int nTradeCustomerID Description=这是显示价格的函数/>
<Method Name=TradePrice.CustPrice.ShowCustomerInfo(int nBTradeCustomerID) Description=这是显示客户信息的函数/>
</Methods>
在C++的插件中可以通过接口函数CString GetIDF()获得接口描述文件的内容,通过接口函数bool ExecuteNetMethod (CString sMethod)来实现对.NET接口的调用。
通过bool IsClrPlugin()判断是否是CLR类型的插件。
这需要在插件基类中增加这样的三个函数,并且在基类中可以判断是否存在该插件对应的XML配置,如果存在,则判断其中是否定义了.NET插件库。
<?xml version="1.0" encoding="GB2312"?>
<Setting>
<ClrPlugin>BTradePrice.DLL</ClrPlugin>
</Setting>
如果存在BTradePrice.DLL,则需要从BTradePrice中调用一个函数BTradePrice.NDKPlugin.IsNDKPlugin()函数判断是否是一个插件,通过BTradePrice.NDKPlugin.GetIDF()返回一个IDF字符串(XML格式)
这样,通过.NET开发插件只要创建一个DLL,然后在其中增加如下的两个函数即可:
NDKPlugin.IsNDKPlugin()
NDKPlugin.GetIDF()
可以实现在C++中调用.NET库中的函数。但是,C++中的Windows消息如何传递给.NET插件呢?这需要在C++插件的基类中将Window消息转发给.NET插件。