Convert VC++ source to C#
hy
I find a COM XMLRPC implementation in http://www.*-*-*.com/
I don't have experience with COM & VC++
I already find this sample in VC++.
I need to convert this in C#.
I have included the beginning of my C# source.
I don't know how to make this in C# :
DISPID dispid ;
proxy.GetIDOfName(OLESTR("getLignesCommandes"), &dispid ) ;
// call the Add method, assume it takes two parameters of type int
CComVariant p1(10), p2(20), retVal ;
hr = proxy.Invoke0(dispid,&retVal ) ;
the VC++ source
------------------------
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
USES_CONVERSION ;
std::cout << "pocketXMLRPC demo" << std::endl ;
CoInitialize(0) ;
{
// create the Envelope object
CComPtr<IXmlRpcFactory> objFactory ;
HRESULT hr = objFactory.CoCreateInstance(__uuidof(CoFactory)) ;
if ( FAILED(hr))
{
std::cout << "Failed to create Factory object, hr=" << std::hex << hr <<
std::endl ;
return -1;
}
CComPtr<IXmlRpcStruct> objXmlRpcStruct;
hr = objXmlRpcStruct.CoCreateInstance(__uuidof(CoXmlRpcStruct)) ;
if ( FAILED(hr))
{
std::cout << "Failed to create XmlRpcStruct object, hr=" << std::hex <<
hr << std::endl ;
return -1;
}
// parameters to the Proxy call are
// /* [in] */ BSTR endpointURL,
// /* [defaultvalue][in] */ BSTR methodPrefix,
// /* [defaultvalue][in] */ BSTR serverUsername,
// /* [defaultvalue][in] */ BSTR serverPassword,
// /* [defaultvalue][in] */ BSTR httpProxyServer,
// /* [defaultvalue][in] */ long httpProxyPort,
// /* [defaultvalue][in] */ BSTR proxyUsername,
// /* [defaultvalue][in] */ BSTR proxyPassword,
// /* [defaultvalue][in] */ long timeout,
// /* [retval][out] */ IDispatch **Proxy
CComDispatchDriver proxy ;
objFactory->Proxy(CComBSTR(" http://www.*-*-*.com/
lrpc.php"), CComBSTR(L"khoros."), NULL, NULL, NULL, 0, NULL, NULL, 15000,
&proxy );
// get the DISPID of the method we want to call
DISPID dispid ;
proxy.GetIDOfName(OLESTR("getLignesCommandes"), &dispid ) ;
// call the Add method, assume it takes two parameters of type int
CComVariant p1(10), p2(20), retVal ;
hr = proxy.Invoke0(dispid,&retVal ) ;
if (FAILED(hr))
{
std::cout << "Failed to invoke method, hr=" << std::hex << hr <<
std::endl ;
return -1 ;
}
// co-erce result to string, so we can print it
retVal.ChangeType(VT_BSTR) ;
USES_CONVERSION ;
std::cout << "Result was " << OLE2A(retVal.bstrVal) << std::endl ;
}
CoUninitialize();
return 0;
Quote:
}
the partial C# source
--------------
class MainClass
{
public static void Main(string[] args)
{
try
{
CoFactoryClass objFactoryClass = new CoFactoryClass();
object objProxy;
objProxy =
objFactoryClass.Proxy(" http://www.*-*-*.com/
php","khoros.","","","",80,"","",15000); // result a System.__ComObject
// erreur, the compiler can't find the getLignesCommandes method of the
Object Class
//objProxy.getLignesCommandes();
System.Console.WriteLine(objProxy.ToString());// }
catch(COMException e)
{
System.Console.WriteLine("Oops an error occured !. Error Code is :
{0}.Error message is : {1}",e.ErrorCode,e.Message);
}
}
Quote:
}
Thanks
--Shaym