`
阿尔萨斯
  • 浏览: 4179786 次
社区版块
存档分类
最新评论

[C#]C++调用dotNet组件的步骤

 
阅读更多
<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog336280.html" frameborder="0" width="336" scrolling="no" height="280"></iframe>

郑昀记录 200409<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

C#写的组件,一般C++无法调用。除非在C#中这么做:

第一步,修改HTMLParser工程属性:

Build信息页中“Register for COM interop”设置为True

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></path><lock aspectratio="t" v:ext="edit"></lock></shapetype>

第二步,在class特意声明:

namespace HTMLParser

{

[Guid("<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="1" unitname="F">1F</chmetcnv>6EBDEF-1111-2222<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="True" hasspace="False" sourcevalue="86" unitname="F">-86F</chmetcnv>2-0CEF0ED302E0")]

[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]

public interface _ParseHTML

{

[DispId(1)]

String GetVersion();

[DispId(2)]

String GetLastError();

[DispId(3)]

String ParseFile(String strRegularExpression);

}

[Guid("C<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="11113" unitname="C">11113C</chmetcnv>6<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="True" hasspace="False" sourcevalue="23" unitname="F">-23F</chmetcnv>3-4db5-2222-BF5BD<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="95" unitname="a">95A</chmetcnv><chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="5" unitname="C">5C</chmetcnv>81")]

[ClassInterface(ClassInterfaceType.None)]

[ProgId("HTMLParser.ParseHTML")]

public class ParseHTML : _ParseHTML

{。。。

这样,就能够像调用一个普普通通的COM组件一样了。

当然在Visual C++调用该组件时也需要第三个技巧:

///////////////////////////////////////////////////

///

/// 对于这种特殊的C#写的COM组件,必须以特殊方式调用

HTMLParser::_ParseHTML *com_ptr_Parser;

HTMLParser::_ParseHTMLPtr pPaser(__uuidof(HTMLParser::ParseHTML));

com_ptr_Parser = pPaser;

_bstr_t bstrXMLFilePath =

com_ptr_Parser->ParseFile(

_bstr_t(strRegularExpression.c_str()));


更多信息参见《Creating a CCW for COM enabled non .NET applications

Nick Parker http://www.codeproject.com/dotnet/nettocom.asp)。




郑昀记录 200409<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

C#写的组件,一般C++无法调用。除非在C#中这么做:

第一步,修改HTMLParser工程属性:

Build信息页中“Register for COM interop”设置为True

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></path><lock aspectratio="t" v:ext="edit"></lock></shapetype>

第二步,在class特意声明:

namespace HTMLParser

{

[Guid("<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="1" unitname="F">1F</chmetcnv>6EBDEF-1111-2222<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="True" hasspace="False" sourcevalue="86" unitname="F">-86F</chmetcnv>2-0CEF0ED302E0")]

[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]

public interface _ParseHTML

{

[DispId(1)]

String GetVersion();

[DispId(2)]

String GetLastError();

[DispId(3)]

String ParseFile(String strRegularExpression);

}

[Guid("C<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="11113" unitname="C">11113C</chmetcnv>6<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="True" hasspace="False" sourcevalue="23" unitname="F">-23F</chmetcnv>3-4db5-2222-BF5BD<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="95" unitname="a">95A</chmetcnv><chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="5" unitname="C">5C</chmetcnv>81")]

[ClassInterface(ClassInterfaceType.None)]

[ProgId("HTMLParser.ParseHTML")]

public class ParseHTML : _ParseHTML

{。。。

这样,就能够像调用一个普普通通的COM组件一样了。

当然在Visual C++调用该组件时也需要第三个技巧:

///////////////////////////////////////////////////

///

/// 对于这种特殊的C#写的COM组件,必须以特殊方式调用

HTMLParser::_ParseHTML *com_ptr_Parser;

HTMLParser::_ParseHTMLPtr pPaser(__uuidof(HTMLParser::ParseHTML));

com_ptr_Parser = pPaser;

_bstr_t bstrXMLFilePath =

com_ptr_Parser->ParseFile(

_bstr_t(strRegularExpression.c_str()));


更多信息参见《Creating a CCW for COM enabled non .NET applications

Nick Parker http://www.codeproject.com/dotnet/nettocom.asp)。




郑昀记录 200409<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

C#写的组件,一般C++无法调用。除非在C#中这么做:

第一步,修改HTMLParser工程属性:

Build信息页中“Register for COM interop”设置为True

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></path><lock aspectratio="t" v:ext="edit"></lock></shapetype>

第二步,在class特意声明:

namespace HTMLParser

{

[Guid("<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="1" unitname="F">1F</chmetcnv>6EBDEF-1111-2222<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="True" hasspace="False" sourcevalue="86" unitname="F">-86F</chmetcnv>2-0CEF0ED302E0")]

[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]

public interface _ParseHTML

{

[DispId(1)]

String GetVersion();

[DispId(2)]

String GetLastError();

[DispId(3)]

String ParseFile(String strRegularExpression);

}

[Guid("C<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="11113" unitname="C">11113C</chmetcnv>6<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="True" hasspace="False" sourcevalue="23" unitname="F">-23F</chmetcnv>3-4db5-2222-BF5BD<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="95" unitname="a">95A</chmetcnv><chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="5" unitname="C">5C</chmetcnv>81")]

[ClassInterface(ClassInterfaceType.None)]

[ProgId("HTMLParser.ParseHTML")]

public class ParseHTML : _ParseHTML

{。。。

这样,就能够像调用一个普普通通的COM组件一样了。

当然在Visual C++调用该组件时也需要第三个技巧:

///////////////////////////////////////////////////

///

/// 对于这种特殊的C#写的COM组件,必须以特殊方式调用

HTMLParser::_ParseHTML *com_ptr_Parser;

HTMLParser::_ParseHTMLPtr pPaser(__uuidof(HTMLParser::ParseHTML));

com_ptr_Parser = pPaser;

_bstr_t bstrXMLFilePath =

com_ptr_Parser->ParseFile(

_bstr_t(strRegularExpression.c_str()));


更多信息参见《Creating a CCW for COM enabled non .NET applications

Nick Parker http://www.codeproject.com/dotnet/nettocom.asp)。




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics