Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ managed code calling unmanaged code with handles
    primarykey
    data
    text
    <p>After an afternoon of searching this problem has got me stumped! I'm writing a managed C++ application which needs to call some unmanaged code. This is the function I need to call:</p> <pre><code>public: void Connect( [out] LONG* pCookieID, [out] LONG* pNumberOfStreams, [out] VARIANT* pMediaType ); </code></pre> <p>And the documentation has this note: Parameter <code>pMediaType</code> must be set to null in <code>C#</code> and nothing in <code>VB .NET</code> before calling Connect, otherwise an exception with error code <code>DISP_E_TYPEMISMATCH = 0x80020005</code> will be thrown.</p> <p>So I need to pass 3 handles to the function for it to return data in them. The two <code>LONG</code> handles seem reasonably straightforward but I can't figure out how to pass a handle for a variant. </p> <p>This is where I've got to:</p> <pre><code>int ^cookieID; int ^numberOfStreams; System::Object ^buffer; GCHandle hcookieID = GCHandle::Alloc(cookieID, GCHandleType::Pinned); GCHandle hnumberOfStreams = GCHandle::Alloc(numberOfStreams, GCHandleType::Pinned); GCHandle hbuffer = GCHandle::Alloc(buffer, GCHandleType::Pinned); parser-&gt;Connect(hcookieID.AddrOfPinnedObject().ToInt32(), hnumberOfStreams.AddrOfPinnedObject().ToInt32(), (System::Object^)hbuffer.AddrOfPinnedObject().ToInt32()); hcookieID.Free(); hnumberOfStreams.Free(); hbuffer.Free(); </code></pre> <p>The compiler accepts this but when the <code>Connect</code> method is called I get the following error: </p> <blockquote> <p><code>"Type mismatch. (Exception from HRESULT: 0x80020005</code> <br> <code>(DISP_E_TYPEMISMATCH))"} System::Exception^</code></p> </blockquote> <p>I've searched high and low and tried all sorts of solutions but I can't find any. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload