473,387 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

Oct 23 '06 #1
4 4187
"Claus77" <cm******@web.dewrote in message
news:11*********************@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?
Oct 23 '06 #2

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*

Oct 23 '06 #3
"Claus77" <cm******@web.dewrote in message
news:11*********************@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

Oct 23 '06 #4
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

Oct 24 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: C. N. Sridhar | last post by:
Hi, I'm writing a wrapper to a win32 dll in C#. I need to call a method in DLL which has a Variant type reference parameter. How to marshal variant type from win32 (unmanaged code) to C#...
2
by: ZhangZQ | last post by:
If I have a method in an OCX, the definition is void Test1(VARIANT* a); After I add reference to this OCX in Visual studio .net, it generates 2 dlls, and I look at the object browser, the...
16
by: Jon Davis | last post by:
Hi guys! Just wanted to let you all know that I created a Variant structure, inspired by the old VB6 days. // Here is an example of use: // start with a string of "1" Variant da = new...
3
by: G Gerard | last post by:
Hello If Variant type is the data type that contains any kind of data type is there a reason why one would not always use Variant when declaring variables? Thanks G Gerard
1
by: darrenbenn | last post by:
I need to convert this code to VB .NET (2003). Dim FaxMsg As IFaxMessage Set FaxMsg = gFC.NewMessage Dim Recip As Variant ' add a recipient to the fax recipients collection Set Recip =...
3
by: empire5 | last post by:
I'm trying to convert a MS-Sql 6.5 VB application to SQL 2005 and vb.net. The vb app has uses a variant data type. When I try to read the variant data type from the sql 2005 database I get 8,000...
2
by: Bjoern | last post by:
Hi I have a COM object which fires an event where I have to pass an array of SHORTs as a parameter to the listening object. The array of SHORTs is encapsulated in a the CComSafeArray-class and...
1
by: captainc | last post by:
I have C++ code to import a .tlb and use a .dll that has functions that return VARIANT types and accepts BSTRs (bstrings). I have seen that python has modules that can manipulate VARIANTs and BSTRs...
4
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
How can I define type variant in c#?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.