473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

BSTR from COM to C# always null

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

Nov 17 '05 #1
3 2845
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" <vo***********@gmx.de> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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

Nov 17 '05 #2
Hi,

i use the tlbimp to generate a wrapper an in C# it is shown as ref
string.

In C++ it is marked as [out].

Thanks

Volker

Nov 17 '05 #3

"Volker Kugler" <vo***********@gmx.de> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi,

i use the tlbimp to generate a wrapper an in C# it is shown as ref
string.

In C++ it is marked as [out].

Thanks

Volker

The question was how does it look like in IL. Run ildasm.exe on the interop
assembly and check the method signature.

Willy.
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris | last post by:
I am not sure if this is the right newsgroup. But does anyone know what is the difference between a BSTR and a LPOLESTR? The only thing I could find out is that the advantage of taking BSTR...
0
by: T. | last post by:
How do you assign a value of type OLE BSTR to a C# string as shown by this code snippet. I am getting an 'EXCEPTION_ACCESS_VIOLATION...' runtime error. SQLDMO.SQLServer; SQLDMO.Database db;...
7
by: Gilad Walden | last post by:
I use C# in .NET framework. I have an ActiveX implemented in C++ that has a COM interface method that gets as it’s out parameter a BSTR* . The interop translates this BSTR* into C# string. From...
4
by: EdInPhoenix | last post by:
Hi All, I'm not a c++ programmer, but I find myself writing an extended stored procedure to call a web service. I got this part working. I want to pass parameters through the extended proc on...
8
by: Michael Tissington | last post by:
I have a C++ function in a DLL of the form BSTR WINAPI DoSomeWork(LPCSTR szConnection, LPCSTR szGUID) I use SysAllocStringByteLen to return a BSTR. For the most part this works accept when...
5
by: Karthik | last post by:
Hello! I am not a wizard in this area! Just need some help out in this. I am trying to convert bstr string to new character string. Here is the snippet of my code. **** Code Start**** ...
5
by: Matt Helm | last post by:
I am using win32com to access a third party COM interface but am having trouble using the string that is returned. The vendor's docs show the following method: HRESULT CookString(BSTR param_a,...
5
by: bluter | last post by:
We have server components which were created by a third party and compiled in VC++5 (sp3). They run fine on NT4 and 2000, however during testing of our migration to Server 2003, these components...
37
by: Egbert Nierop \(MVP for IIS\) | last post by:
In win32 mode, a BSTR was UINT length prefixed and terminated exactly by a zero char. So if you allocated "Hello World" that would allocate 28 bytes. In x64 and (IA64 as well) it would become...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.