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?

What is VARIANT?

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 *.

What is the actual structure of this variable? What is its definition?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.