Not sure how you managed to compile this, a BSTR* should be marked as an
[out] argument in the wrapper class, that means it should be passed as out
argument in C#.
..... (1,out sAdapterName);
I suggest you check the wrapper method signature using ildasm
Willy.
"Volker Kugler" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> i want to transmit a string from a C++-COM-DLL to C#. I wrote this
> code:
>
> STDMETHODIMP CWinpcap::hrGetAdapterNameFromAdapterNumber(int
> iAdapterNumber, BSTR * AdapterName)
> {
> int index = 1;
> dev = alldevs;
>
> CComBSTR bstr = A2BSTR(dev->name);
> *AdapterName = bstr.Copy();
>
> return S_OK;
> }
>
> in VCC6. Then i generate the DLL and use tlbimp to generate a Wrapper
> for C#.
>
> In C# i use this code:
>
> int nr = 0;
>
> string sAdapterName = null;
> WINPCAP_COM_ZUGRIFFLib.WinpcapClass wpcap = new
> WINPCAP_COM_ZUGRIFFLib.WinpcapClass();
> wpcap.hrGetNumberOfAdapters(ref nr);
> wpcap.hrGetAdapterNameFromAdapterNumber(1,ref sAdapterName);
>
> But when debugging in C#, sAdapterName is always empty. When i debug
> the C++-DLL, i can see, that AdapterName points to the first character
> of the BSTR.
>
> Does anybody know what i made wrong?
>
> Thanks for your help
>
> Volker Kugler
>
|