Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. How to put a struct into a VARIANT?

How to put a struct into a VARIANT?

Scheduled Pinned Locked Moved COM
questionsysadminsalestutorial
13 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    morenz
    wrote on last edited by
    #1

    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

    G R 2 Replies Last reply
    0
    • M 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

      G Offline
      G Offline
      GizzoF
      wrote on last edited by
      #2

      Maybe this could help` http://www.mvps.org/vcfaq/com/4.htm[^]

      M 1 Reply Last reply
      0
      • G GizzoF

        Maybe this could help` http://www.mvps.org/vcfaq/com/4.htm[^]

        M Offline
        M Offline
        morenz
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • M 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

          M Offline
          M Offline
          Mike Dimmick
          wrote on last edited by
          #4

          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

          M 1 Reply Last reply
          0
          • M 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

            R Offline
            R Offline
            Rory Solley
            wrote on last edited by
            #5

            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.

            M J 2 Replies Last reply
            0
            • M Mike Dimmick

              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

              M Offline
              M Offline
              morenz
              wrote on last edited by
              #6

              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

              M 1 Reply Last reply
              0
              • M 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

                M Offline
                M Offline
                morenz
                wrote on last edited by
                #7

                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

                M 1 Reply Last reply
                0
                • R Rory Solley

                  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.

                  M Offline
                  M Offline
                  morenz
                  wrote on last edited by
                  #8

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

                  R 1 Reply Last reply
                  0
                  • M 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

                    M Offline
                    M Offline
                    morenz
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    • M morenz

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

                      R Offline
                      R Offline
                      Rory Solley
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • R Rory Solley

                        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.

                        J Offline
                        J Offline
                        Jorgen Sigvardsson
                        wrote on last edited by
                        #11

                        Why do that, when you can define the structure in IDL? :~ -- Look straight into the light!

                        R M 2 Replies Last reply
                        0
                        • J Jorgen Sigvardsson

                          Why do that, when you can define the structure in IDL? :~ -- Look straight into the light!

                          R Offline
                          R Offline
                          Rory Solley
                          wrote on last edited by
                          #12

                          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.

                          1 Reply Last reply
                          0
                          • J Jorgen Sigvardsson

                            Why do that, when you can define the structure in IDL? :~ -- Look straight into the light!

                            M Offline
                            M Offline
                            morenz
                            wrote on last edited by
                            #13

                            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

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups