Passing a buffer to a COM call?

I have an external COM interface written in C++. The method I'm interested in looks like this in ildasm:

.method public hidebysig newslot virtual
instance void OpenChartDirect([in] string marshal( bstr) bstrChartName,
[out] uint8& pbData,
[in][out] uint32& cbSize) runtime managed internalcall
{
.override CHARTSERVERLib.INcxServer2::OpenChartDirect
} // end of method NcxServerClass::OpenChartDirect

The signature in the .idl file looks like this:

[id(31), helpstring("method OpenChartDirect")] HRESULT OpenChartDirect([in] BSTR bstrChartName, [out] unsigned char* pbData, [in,out] unsigned long* cbSize);

I have yet to figure out the magic formula for passing an empty array in to this method via a pointer and getting anything back, and I can't find examples of such things.

Help



Answer this question

Passing a buffer to a COM call?

  • santosh k singh

    A couple of questions...

    First, I don't find anything that exactly applies. If I have the following in my .idl file:

    [id(31), helpstring("method OpenChartDirect")] HRESULT OpenChartDirect([in] BSTR bstrChartName, [out] unsigned char* pbData, [in,out] unsigned long* cbSize);

    and the following in the .il file generated by ildasm:

    .method public hidebysig newslot virtual
    instance void OpenChartDirect([in] string marshal( bstr) bstrChartName,
    [out] uint8& pbData,
    [in][out] uint32& cbSize) runtime managed internalcall
    {
    .override CHARTSERVERLib.INcxServer2::OpenChartDirect
    } // end of method NcxServerClass::OpenChartDirect

    (btw, don't know if it matters, but I don't have access to a .tlb file). What should the modified .il file look like in order to get something that works for me And then what does the code look like to call it

    Second, the page you reference says,

    4. At the command prompt, type the following command to produce a new New.dll defining
    the proper syntax:

       ilasm New.il 
    I'm not finding the ilasm utility. Where does that live 
     

  • Brenden

    The section "Conformant C-Style Arrays" is what applies best. Try changing the signature to

    ... [out] uint8[] marshal([]) pbData, ...

    It will appear as a regular byte[] parameter from the calling C# code.

    Ilasm.exe should be in your framework directory. %WINDIR%\Microsoft.NET\Framework\vX.Y.ZZZZ. And don't forget to specify the /dll switch to create a library assembly.



  • Justin Niemetscheck

    I kinda had the same thought, but that's what I got when I used tlbimp to generate the DLL I'm using in the C# code.  Maybe I need to do something different there

     p.s.  I probably should have mentioned that I'm *really* green at this...

     


  • anayconsultancy

  • Tim Haynes

    How is a reference to a uint8 the same as an unsigned char *



  • Passing a buffer to a COM call?