Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extremely urgent (2hours) variant to struct

Status
Not open for further replies.

Themuppeteer

Programmer
Apr 4, 2001
449
BE
How do I convert a var from type vaiant to a structure I made ? (I have only 2 hours before deadline)
please help (quickely). Greetz,
muppeteer.gif

NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

Don't eat yellow snow...and don't mess with your fstab!
 
Hi there:

Are you talking about COleVariant data type? Can you be more specific?

I can give you one small example, let's say you define an structure like this:
struct {

int Year;
int Month;
int Day;

} mydate ;

And you have a COlevariant datatype like this

COleDateTime cdtDate;

you could write something like this

mydate.Month = cdtDate.GetMonth();
mydate.Day = cdtDate.GetDay();
mydate.Year = cdtDate.GetYear();

Regards,

Ricardo
 
no, just a var of the type VARIANT
it comes in by doing a soap call, and it should be of the type struct that we made. We ant to get our data out of the variant and into the struct but with casting it won't compile. Greetz,
muppeteer.gif

NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

Don't eat yellow snow...and don't mess with your fstab!
 
A VARIANT can only hold a pointer to that structure (unless it fits in the VARIANT and doesn't overwrite the VT tag). So casting the VARIANT won't do the trick. Even worse; casting a VARIANT never does the trick, you've got to use the member vars to extract the value you want (or point to the right address in the VARIANT yourself).
Greetings,
Rick
 
so lets say that the VARIANT should point to the following struct
MESSAGE{
int error
char* description;
char* value;
}

could you just address the values with

myvariant->error ?

(meanwhile deadline has passed and we used strings instead of structs after a lot of searching...) Greetz,
muppeteer.gif

NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

Don't eat yellow snow...and don't mess with your fstab!
 
You could store a pointer to it in the VT_I4 member (lVal) and cast THAT when needed.
Greetings,
Rick
 
Just for the record, I know C++ but NOT VC++,so...what is VT_I4 ? is it a type? (sorry for these stupid questions..)
Greetz,
muppeteer.gif

NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

Don't eat yellow snow...and don't mess with your fstab!
 
It's a tag used by the VARIANT type (hence VT), which specifies the union to be of type long.
Greetings,
Rick
 
hmmm ok,...
I think its very complicated..
Greetz,
muppeteer.gif

NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

Don't eat yellow snow...and don't mess with your fstab!
 
It is, VARIANTs are a pain in the ... (and don't even talk about SAFEARRAYS), but he, that's why you're a C++ programmer. If you want things to be easy, you should stick to VB. They handle the Variant quite elegant....
Greetings,
Rick
 
Well actually its visual c++ only that does it that way. I'm no VC++ programmer. But I do wish I knew something more about it. Its just that the learning curve is rather high, and my time on earth is limited :)
I just recently found out (about a week ago) how to let something happen when one clicks on a button, and to put something in an textbox, because somebody explained it to me. (Never saw a tutorial explaining things that simple.Think I'll write one for very very beginners explaining you have to hang a variable on textbox and about Updatedata().) It not easy when you are used to the VB kind of visual working (from school) with textbox.text and so on.

But hey, thanks for the time and effort Lazyme.

Best regards,
themupeteer Greetz,
muppeteer.gif

NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

Don't eat yellow snow...and don't mess with your fstab!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top