How to pass structure or complex data in IDispatch using invoke() method .
-
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);
-
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);
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. -
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);
Please try with VT_DISPATCH by
struct tagSample: public IDispatch { int nIntArray[ 10 ]; char szString[ 40 ]; }smaple;
Is it possible? -
Please try with VT_DISPATCH by
struct tagSample: public IDispatch { int nIntArray[ 10 ]; char szString[ 40 ]; }smaple;
Is it possible?You can define a
struct
like that, but there's no type-safe way of accessing the data members if you pass anIDispatch
pointer. -
You can define a
struct
like that, but there's no type-safe way of accessing the data members if you pass anIDispatch
pointer.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; }
-
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; }
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#?
-
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#?
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
-
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
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<