Here is a snippet

myfunc (VARIANT *dmessage){

long len;

I get error :
cannot convert parameter 1 from 'struct tagVariant' to 'const char *'
I want to pass a pointer to a function.
I have tried, below, but I got a differ error.

myfunc (char* dmessage){
long len;

Any suggestions?

5 Years
Discussion Span
Last Post by Ancient Dragon

i think it'll be more helpful if you can paste the whole code, or at least on what is in the struct tagVariant and how you are passing the values to myfunc()


strlen expects a const char *.

You are not passing it a const char *.

You are passing it a VARIANT *. You have to pass it a const char *, or something that the compiler knows how to convert into a const char *.


A VARIANT is standard Microsoft structure used to pass object across COM objects. Use heavily in COM programming and to pass strings between VB and c/c++.

The vt member of the VARIANT object tells what kind of object the VARIANT contains. Then the remainder of the structure is a union of several object types, one that is commonly used to pass strings is BSTR. The BSTR itself is commonly encoded with UNICODE strings which are wchar_t* instead of char*. The length of the BSTR is actually a long integer stored 4 bytes before the beginning of the BSTR pointer. So if you want the length of the BSTR then its just like this:

BSTR b = SysAllocString( L"Hello"); // Create a BSTR

long len = *(long *)(b-2);

google will give you links to several threads that indicate how to convert from BSTR to char*. Here is just one of them.

Here is another good tutorial

Edited by Ancient Dragon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.