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. C / C++ / MFC
  4. How to pass structure or complex data in IDispatch using invoke() method .

How to pass structure or complex data in IDispatch using invoke() method .

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
8 Posts 3 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.
  • T Offline
    T Offline
    Thomas_Mathews
    wrote on last edited by
    #1

    How To pass structure or complex data in IDispatch using invoke() method. for example I want to pass complex data or structure like below to invoke() method. struct tag{ int i[10]; char str[40]; }sample; Below is sample code to access method passing argument. // Code omitted for brevity. szMember = “On”; dispparams.rgvarg[0].vt = VT_BOOL; dispparams.rgvarg[0].bool = FALSE; dispparams.rgdispidNamedArgs = &mydispid; dispparams.cArgs = 1; dispparams.cNamedArgs = 1; hresult = pdisp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid); hresult = pdisp->Invoke( dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);

    S R 2 Replies Last reply
    0
    • T Thomas_Mathews

      How To pass structure or complex data in IDispatch using invoke() method. for example I want to pass complex data or structure like below to invoke() method. struct tag{ int i[10]; char str[40]; }sample; Below is sample code to access method passing argument. // Code omitted for brevity. szMember = “On”; dispparams.rgvarg[0].vt = VT_BOOL; dispparams.rgvarg[0].bool = FALSE; dispparams.rgdispidNamedArgs = &mydispid; dispparams.cArgs = 1; dispparams.cNamedArgs = 1; hresult = pdisp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid); hresult = pdisp->Invoke( dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      IIRC, a dispinterface can't take complex data like that - can't take anything that can't be represented in a VARIANT, in fact. The usual way in which structs can be passed over COM methods is for the struct to be defined in the IDL file that defines the interface you have a pointer to. That way, COM can generate code that will marshall instances of the struct through the interface.

      1 Reply Last reply
      0
      • T Thomas_Mathews

        How To pass structure or complex data in IDispatch using invoke() method. for example I want to pass complex data or structure like below to invoke() method. struct tag{ int i[10]; char str[40]; }sample; Below is sample code to access method passing argument. // Code omitted for brevity. szMember = “On”; dispparams.rgvarg[0].vt = VT_BOOL; dispparams.rgvarg[0].bool = FALSE; dispparams.rgdispidNamedArgs = &mydispid; dispparams.cArgs = 1; dispparams.cNamedArgs = 1; hresult = pdisp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid); hresult = pdisp->Invoke( dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);

        R Offline
        R Offline
        Radhakrishnan G
        wrote on last edited by
        #3

        Please try with VT_DISPATCH by struct tagSample: public IDispatch { int nIntArray[ 10 ]; char szString[ 40 ]; }smaple; Is it possible?

        S 1 Reply Last reply
        0
        • R Radhakrishnan G

          Please try with VT_DISPATCH by struct tagSample: public IDispatch { int nIntArray[ 10 ]; char szString[ 40 ]; }smaple; Is it possible?

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          You can define a struct like that, but there's no type-safe way of accessing the data members if you pass an IDispatch pointer.

          T 1 Reply Last reply
          0
          • S Stuart Dootson

            You can define a struct like that, but there's no type-safe way of accessing the data members if you pass an IDispatch pointer.

            T Offline
            T Offline
            Thomas_Mathews
            wrote on last edited by
            #5

            Thanks for the reply but my question remain unanswer. The COM component is third party's so I donot have control on what defined in IDL or whatever technology they used. I need to pass one argument in IDispatch's Invoke method as below . This is sample code from c# client. I want to pass structure which has byte array and string etc in c++ using IDispatch. How usually people pass structure as single argument in IDispatch's Invoke method() public class BLOB { /// <remarks/> public string contentType; public System.Byte[] binaryData; public string ID; public string URL; }

            S 1 Reply Last reply
            0
            • T Thomas_Mathews

              Thanks for the reply but my question remain unanswer. The COM component is third party's so I donot have control on what defined in IDL or whatever technology they used. I need to pass one argument in IDispatch's Invoke method as below . This is sample code from c# client. I want to pass structure which has byte array and string etc in c++ using IDispatch. How usually people pass structure as single argument in IDispatch's Invoke method() public class BLOB { /// <remarks/> public string contentType; public System.Byte[] binaryData; public string ID; public string URL; }

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              Thomas_Mathews wrote:

              The COM component is third party's so I donot have control on what defined in IDL or whatever technology they used

              OK, but you should have a definition of the interface somewhere - that's the point of COM - you share interface definitions.

              Thomas_Mathews wrote:

              This is sample code from c# client

              Do you have a sample of the IDispatch::Invoke call in C#?

              T 1 Reply Last reply
              0
              • S Stuart Dootson

                Thomas_Mathews wrote:

                The COM component is third party's so I donot have control on what defined in IDL or whatever technology they used

                OK, but you should have a definition of the interface somewhere - that's the point of COM - you share interface definitions.

                Thomas_Mathews wrote:

                This is sample code from c# client

                Do you have a sample of the IDispatch::Invoke call in C#?

                T Offline
                T Offline
                Thomas_Mathews
                wrote on last edited by
                #7

                A) There is a webservice and I am writing a client in c++ to invoke that webservice using IDispatch. I have taken the sample for c++ client from codeproject and below is the link [http://www.codeproject.com/KB/COM/xysoapclient.aspx? fid=13980&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=26&select=516139](http://www.codeproject.com/KB/COM/xysoapclient.aspx?<br mode=)[[^](http://www.codeproject.com/KB/COM/xysoapclient.aspx?<br mode= "New Window")] This is structure we pass in c# for calling method [System.Xml.Serialization.XmlTypeAttribute] public class BLOB { /// <remarks/> public string contentType; [System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] public System.Byte[] binaryData; public string ID; public string URL; } B) Regarding writing a client in c# for webservice is pretty straight forward. In C# it is pass complex data in single argument. OR If above is complex is anyone know how to pass structure like below in IDispatch's Invoke() method. The COM Server is third party. struct tag{ char str[100]; void *p; char str1[300]; }

                modified on Tuesday, January 20, 2009 2:25 AM

                S 1 Reply Last reply
                0
                • T Thomas_Mathews

                  A) There is a webservice and I am writing a client in c++ to invoke that webservice using IDispatch. I have taken the sample for c++ client from codeproject and below is the link [http://www.codeproject.com/KB/COM/xysoapclient.aspx? fid=13980&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=26&select=516139](http://www.codeproject.com/KB/COM/xysoapclient.aspx?<br mode=)[[^](http://www.codeproject.com/KB/COM/xysoapclient.aspx?<br mode= "New Window")] This is structure we pass in c# for calling method [System.Xml.Serialization.XmlTypeAttribute] public class BLOB { /// <remarks/> public string contentType; [System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] public System.Byte[] binaryData; public string ID; public string URL; } B) Regarding writing a client in c# for webservice is pretty straight forward. In C# it is pass complex data in single argument. OR If above is complex is anyone know how to pass structure like below in IDispatch's Invoke() method. The COM Server is third party. struct tag{ char str[100]; void *p; char str1[300]; }

                  modified on Tuesday, January 20, 2009 2:25 AM

                  S Offline
                  S Offline
                  Stuart Dootson
                  wrote on last edited by
                  #8

                  Firstly - you implied you had a C# client for your COM server, not for some web-service. This would appear to be incorrect...

                  Thomas_Mathews wrote:

                  I am writing a client in c++ to invoke that webservice using IDispatch

                  Yeah...don't think that's going to work - the CP article you reference doesn't use IDispatch to call web-services, and really, IDispatch isn't for calling web services.

                  Thomas_Mathews wrote:

                  This is structure we pass in c# for calling method [System.Xml.Serialization.XmlTypeAttribute] public class BLOB { /// public string contentType; [System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] public System.Byte[] binaryData; public string ID; public string URL; }

                  The "[System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")]" gives it away - this structure is sent to the web-service by serializing the structure contents as a chunk of XML. That implies to me that the web-service is probably using SOAP - maybe you could use something like gSOAP[^] to write your C++ client? Do you have a WSDL file that defines the web-service interface?

                  Thomas_Mathews wrote:

                  If above is complex is anyone know how to pass structure like below in IDispatch's Invoke() method. The COM Server is third party. struct tag{ char str[100]; void *p; char str1[300]; }

                  Strikes me that this is a completely separate problem from the one above - the only connection is "I have a method call that I wish to serialize between a client and a remote (to some extent) server". Now. This third-party COM server. It must define its interface somewhere. There must be something that tells you what methods it will understand on its IDispatch interface. If you don't have an IDL file, you ought to have a type library (it's usually embedded in the server somehow). Maybe you could try generating an interface to the COM server using #import[^], specifying the COM server DLL or EXE as the thing you're importing? Also - you cannot<

                  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