Convert VC++ source to C# 
Author Message
 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



Sun, 09 Jan 2005 22:02:51 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Utility to convert VB source code to VC++

2. How to convert nonmanged vc++ to managed vc++?

3. Converting Borland C source to Ansi C source to run under Linux

4. Converting Borland C source to Ansi C source to run under Linux

5. how to convert source code pascal to source code c

6. Converting Turbo Pascal source to C source

7. Converting a VB.Net source to a C#.Net source

8. New C# Source Code Sample - Running JScript.NET Code from C# Apps

9. Graphics Rendering project source code c/vc/vc++

10. Problem to convert from VC 6.0 to VC 7.1 because of using filebuf::setmode()

11. Problem converting VC++ 6.0 project to VC++.net

12. Converting project from VC++ 2002 to VC++ 2003 and adding a new configuration

 

 
Powered by phpBB® Forum Software