VARIANT type

C

Claus77

Hi there,

I've got a little problem with the following:

I'm just writing a com-application in C++ with VS-6, which should also
be
used with VB-Script, so I have to use variables of type VARIANT in my
functions in order to get no problems with VB-Script.

I try to transform them into C++-Variables somehow like this:


function a(VARIANT var)

bstr ch = var.bstr;


But C++ only puts the first character of the string into my variable
ch... Why?
What have I done wrong?

Thanks for your help,
Claus
 
J

Jim Langston

Claus77 said:
Hi there,

I've got a little problem with the following:

I'm just writing a com-application in C++ with VS-6, which should also
be
used with VB-Script, so I have to use variables of type VARIANT in my
functions in order to get no problems with VB-Script.

I try to transform them into C++-Variables somehow like this:


function a(VARIANT var)

bstr ch = var.bstr;


But C++ only puts the first character of the string into my variable
ch... Why?
What have I done wrong?

Thanks for your help,
Claus

How is VARIANT defined?
How is bstr defined?
 
C

Claus77

How is VARIANT defined?

you mean this?:

typedef /* [wire_marshal] */ struct tagVARIANT VARIANT;

struct tagVARIANT
{
union
{
struct __tagVARIANT
{
VARTYPE vt;
WORD wReserved1;
WORD wReserved2;
WORD wReserved3;
union
{
LONGLONG llVal;
LONG lVal;
BYTE bVal;
SHORT iVal;
FLOAT fltVal;
DOUBLE dblVal;
VARIANT_BOOL boolVal;
_VARIANT_BOOL bool;
SCODE scode;
CY cyVal;
DATE date;
BSTR bstrVal;
IUnknown *punkVal;
IDispatch *pdispVal;
SAFEARRAY *parray;
BYTE *pbVal;
SHORT *piVal;
LONG *plVal;
LONGLONG *pllVal;
FLOAT *pfltVal;
DOUBLE *pdblVal;
VARIANT_BOOL *pboolVal;
_VARIANT_BOOL *pbool;
SCODE *pscode;
CY *pcyVal;
DATE *pdate;
BSTR *pbstrVal;
IUnknown **ppunkVal;
IDispatch **ppdispVal;
SAFEARRAY **pparray;
VARIANT *pvarVal;
PVOID byref;
CHAR cVal;
USHORT uiVal;
ULONG ulVal;
ULONGLONG ullVal;
INT intVal;
UINT uintVal;
DECIMAL *pdecVal;
CHAR *pcVal;
USHORT *puiVal;
ULONG *pulVal;
ULONGLONG *pullVal;
INT *pintVal;
UINT *puintVal;
struct __tagBRECORD
{
PVOID pvRecord;
IRecordInfo *pRecInfo;
} __VARIANT_NAME_4;
} __VARIANT_NAME_3;
} __VARIANT_NAME_2;
DECIMAL decVal;
} __VARIANT_NAME_1;
} ;

How is bstr defined?


bstr is a wchar_t*
 
J

Jim Langston

Claus77 said:
Hi there,

I've got a little problem with the following:

I'm just writing a com-application in C++ with VS-6, which should also
be
used with VB-Script, so I have to use variables of type VARIANT in my
functions in order to get no problems with VB-Script.

I try to transform them into C++-Variables somehow like this:


function a(VARIANT var)

bstr ch = var.bstr;

In the definition of VARIANT you gave me, there is no bstr. So how can you
be using var.bst if bstr is not defined within VARIENT?

In the definition of bstr you gave me, it is a wchar_t*, or a wide char
pointer. So it would seem that you are assinging the pointer ch to point to
whatever bstr is, which is probably another wchar_t. You haven't copied
anything though.

You need to look at thwat bstr is pointing to, the text string I'm fairly
sure, but is it null terminated? If not, you need to get the length out of
your var and determine how long it is.

So basically what you want to do is copy the text that bstr is pointing to
into some C++ type string. I would probably go with a std::string, but you
could go with a char array. Then copy the contents. Since you haven't
given me a full defintion of VARIANT I can't help you with where the length
is stored in VARIANT.

Consider asking in a windows newsgroup if you can't figure it out.
 
C

Claus77

ah, i've got it now on my own... thanks for your help,
if someone is interested in the solution, i can post it here...

greets,
claus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top