Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   VARIANT type (http://www.velocityreviews.com/forums/t457807-variant-type.html)

Claus77 10-23-2006 08:30 AM

VARIANT type
 
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


Jim Langston 10-23-2006 08:52 AM

Re: VARIANT type
 
"Claus77" <cmassion@web.de> wrote in message
news:1161592203.696547.28250@h48g2000cwc.googlegro ups.com...
> 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?



Claus77 10-23-2006 09:12 AM

Re: VARIANT type
 


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


Jim Langston 10-23-2006 11:09 AM

Re: VARIANT type
 
"Claus77" <cmassion@web.de> wrote in message
news:1161592203.696547.28250@h48g2000cwc.googlegro ups.com...
> 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.

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




Claus77 10-24-2006 08:43 AM

Re: VARIANT type
 
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



All times are GMT. The time now is 05:40 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.