How to put a struct into a VARIANT?
-
hi folks;) I need to put a struct (in which i have another struct...) into a VARIANT to pass it between DCOM client and server methods. I would like to avoid custom marshaling (i've never done it and the customer is getting angry... so I have no time to spend on it...). How can I do? Thanks in advance! Morenz
-
hi folks;) I need to put a struct (in which i have another struct...) into a VARIANT to pass it between DCOM client and server methods. I would like to avoid custom marshaling (i've never done it and the customer is getting angry... so I have no time to spend on it...). How can I do? Thanks in advance! Morenz
-
Maybe this could help` http://www.mvps.org/vcfaq/com/4.htm[^]
Hi, First of all, thanks for your prompt reply! Well, I can say that in 3 sheets of paper there's the informations I searched for days! Only one thing, SafeArrayCreateEx function and VT_RECORD vartype are not declared in my Visual Studio 6. Can I get access to them installing service packs? Many thanks, you're great! Hope can help you back in future, bye for now, Morenz
-
Hi, First of all, thanks for your prompt reply! Well, I can say that in 3 sheets of paper there's the informations I searched for days! Only one thing, SafeArrayCreateEx function and VT_RECORD vartype are not declared in my Visual Studio 6. Can I get access to them installing service packs? Many thanks, you're great! Hope can help you back in future, bye for now, Morenz
They are declared in my installation of Visual Studio 6. I'm using SP5. The easiest way to find out your service pack level is to launch Visual Basic, since the service pack number is included in the splash screen graphic. Download service packs from here[^]. Stability. What an interesting concept. -- Chris Maunder
-
hi folks;) I need to put a struct (in which i have another struct...) into a VARIANT to pass it between DCOM client and server methods. I would like to avoid custom marshaling (i've never done it and the customer is getting angry... so I have no time to spend on it...). How can I do? Thanks in advance! Morenz
If you've written both client and server (and so can control alignment and other compile-time issues), you could create a common header file for both applications that contains the struct definition and then embed the data as a byte stream (VT_UI1|VT_ARRAY) in a VARIANT and pass that over (D)COM. I've used that method successfully in the past and its reasonably flexible.
-
They are declared in my installation of Visual Studio 6. I'm using SP5. The easiest way to find out your service pack level is to launch Visual Basic, since the service pack number is included in the splash screen graphic. Download service packs from here[^]. Stability. What an interesting concept. -- Chris Maunder
Many thanks. My problem was that I did not know if that new function was implemented in a later service pack or other stuff. Telling me that you have that function in your SP5 resolved me the problem, so I'm installing SP6 (that I had in the past, on the other computer). OK, let's implement those final functions and make the customer happy! ;) Thanks to everyone again! Morenz
-
Many thanks. My problem was that I did not know if that new function was implemented in a later service pack or other stuff. Telling me that you have that function in your SP5 resolved me the problem, so I'm installing SP6 (that I had in the past, on the other computer). OK, let's implement those final functions and make the customer happy! ;) Thanks to everyone again! Morenz
Hello again... it was too good to be real.... I used what that HOWTO said (implementing a struct into my IDL file, giving it a UUID and managing it with VARIANTs). Now, I got a problem. If I write in IDL typedef [uuid(...)] struct myStruct { ... ... ... }my; , when I compile my project, MIDL is OK, but I get C2787 when compiling: no GUID has been associated with this object. I tried to use, in IDL, [uuid(....)] struct myStruct { ... ... .. }my; and now I get MIDL2072: inapplicable attribute: [uuid][Struct 'myStruct'] How can I get it compiled? I'm going crazy! thanx again! -- modified at 6:37 Friday 30th September, 2005
-
If you've written both client and server (and so can control alignment and other compile-time issues), you could create a common header file for both applications that contains the struct definition and then embed the data as a byte stream (VT_UI1|VT_ARRAY) in a VARIANT and pass that over (D)COM. I've used that method successfully in the past and its reasonably flexible.
-
Hello again... it was too good to be real.... I used what that HOWTO said (implementing a struct into my IDL file, giving it a UUID and managing it with VARIANTs). Now, I got a problem. If I write in IDL typedef [uuid(...)] struct myStruct { ... ... ... }my; , when I compile my project, MIDL is OK, but I get C2787 when compiling: no GUID has been associated with this object. I tried to use, in IDL, [uuid(....)] struct myStruct { ... ... .. }my; and now I get MIDL2072: inapplicable attribute: [uuid][Struct 'myStruct'] How can I get it compiled? I'm going crazy! thanx again! -- modified at 6:37 Friday 30th September, 2005
OK OK OK , I got the problem. I think. Probably I need February 2003 Platform SDK (the last one released for VS 6.0). I tried to compile that code with VS.NET 2002 and it worked. Now the problem is to get that SDK, that is not downloadable anymore from Microsoft website...:( I will search, in worst case I will order the CD.... Bye
-
Hi! What you're saying is to brutally force custom serialization This should be a good method, but how can I declare my safearray dimension? With sizeof()? I've got some structs that has inside an array of another struct.... Thanks again...
Yes, use sizeof(YourStruct). If you have embedded structs, you're going to have to be more creative e.g. sizeof(YourStruct) + (sizeof(YourEmbeddedStruct) * NumberOfEmbeddedStructs) etc. It can get tricky if your structs contain "variable" data, such as strings. In the past, I've either defined the maximum size of the string (and therefore constrained the array inside the struct definition) or I've added a counter then a pointer, e.g. ... unsigned long ByteCount; unsigned char* pByteData; }; The count tells the caller how big the variable data is. Hope that helps.
-
If you've written both client and server (and so can control alignment and other compile-time issues), you could create a common header file for both applications that contains the struct definition and then embed the data as a byte stream (VT_UI1|VT_ARRAY) in a VARIANT and pass that over (D)COM. I've used that method successfully in the past and its reasonably flexible.
Why do that, when you can define the structure in IDL? :~ -- Look straight into the light!
-
Why do that, when you can define the structure in IDL? :~ -- Look straight into the light!
Yep, that's perfectly valid (and arguably the "right" way) but then you have an extra step of publishing the interface and managing proxy stubs. My way keeps things simple and flexible.
-
Why do that, when you can define the structure in IDL? :~ -- Look straight into the light!
Because my structs contain, in some cases, arrays, that have to be defined as SAFEARRAYS. In any case, I implemented this way... I will debug the application when I will resolve my new problems (It's since a month that, when I manage to resolve a strange problem, there comes in another problem, even stranger, if possible! :sigh:) If you're curious, look above.... :) Thanks again, Morenz