Here is a snippet

myfunc (VARIANT *dmessage){

long len;
len=strlen(dmessage);

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;
len=strlen(dmessage)

Any suggestions?
TIA

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 5 Years Ago by Ancient Dragon: n/a

This article has been dead for over six months. Start a new discussion instead.