Monday, 15 July 2013

C# pass int and string by reference to C++ ActiveX Control: type mismatch -


I have a problem passing the reference int or string variable through the C + + activate control. Besides, I have C ++ DLL These variations pass by context and everything works fine.

C ++ DLL:.

  __ declspec (dllexport) executed zero (LPCTSTR cmd, & amp; resultCode, LPCTSTR & message, long and receipt number in integer) {message = _T ("reply process"); Resultcode = 100; Receipt number = -1; } Public static extern executed null (string cmd, etc.): [/ p> 

[DllImport ("MyCOM.dll", charset = CharSet.Unicode) Out the int result code, outside the string message, the int receipt number out); ... int resultCode = 0; String message = ""; Int Receipt Number = 0; Execute ("CMD", resulting result, out message, received receipt number); // OK

How is this done in ActiveX control? I & amp; Reference symbol, but MIDL compiler did not allow

MyCOM.idl:.

  [id (1025315)] zero executed (LPCTSTR cmd, [outside] long & returnCode); // MIDL2025: Syntax error  

I modified ways to use signals *.

MyCOM.idl:

  [ID (1025315)] executed zero (LPCTSTR cmd, [outside] long * returnCode);  

MyCOMCtrl.h:

  // Dispat map afx_msg executed zero (LPCTSTR cmd, long * resultCode);  

MyCOMCtrl.cpp

  // Dispat map ... DISP_FUNCTION_ID (MyCOMCtrl, "execute", DISPID_EXECUTE_METHOD, execute, VT_EMPTY, VTS_PI4). Zero MyCOMCtrl :: Execute (LPCTSTR cmd, long * resultCode) {* resultcode = 111; }  

C #:

  using MyCOMLib; ... MyCOM Client = New MyCOM (); Int result code = 0; // comexception: type mismatch (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH)) client.Execute ("test order", outcomeCode out);  

The same exception is in C ++ and LPCTSTR * instead of the string type in C ++ ActiveX. Any suggestions or suggestions will be appreciated.

Resolve:

In MyCOMCtrl.cpp:

  // Dispat map ... DISP_FUNCTION_ID (MyCOMCtrl, "execute", DISPID_EXECUTE_METHOD, execute, VT_EMPTY, VTS_PI4) ...  

should be:

< Pre> DISP_FUNCTION_ID (MyCOMCtrl, "execute", DISPID_EXECUTE_METHOD, execute, VT_EMPTY, VTS_BSTR VTS_PI4) // two VTS logic

No comments:

Post a Comment