.NET object in C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amasidlover
    New Member
    • Apr 2009
    • 2

    .NET object in C++

    I'm trying to wrap a SOAP webservice in an OCX and one option is to write the webservice wrapper in C# and export it as a .NET/COM interoperabilit y object, as in http://support.microsoft.com/kb/908574

    However, when I attempt this initially I got a could not import tlb error when compiling the C++, I fixed this by correcting the path on the import line and that error went away - so I'm pretty confident the tlb is now being properly imported. I now get lots of undefined errors for all of the symbols that should be created e.g. my equivalent of IHelloWorldPtr, ptrHW etc... I've tried inspecting the TLB using the COM/OLE Viewer, but this doesn't seem to contain any of the names I'd recognise.

    There seems to be a gap in all of the tutorials I've found that doesn't explain how the class names and interface names I use get translated in to the Ptr style names that appear in the C++ examples - I'm sure its something so obvious that no-one sees the need to mention it.

    There's another example at http://support.microsoft.com/kb/828736/ but again it seems to skip over how you find out what the ICalculatorPtr and pICalc should be called if you only have the C# source to refer to.

    Apologies if this isn't quite the right forum - because it spans .NET, OLE, COM, C++ and C# I wasn't sure of the best place for it.

    Help would be much appreciated!

    Alex
  • NewToOracle
    New Member
    • Feb 2009
    • 15

    #2
    Need Info

    Originally posted by amasidlover
    I now get lots of undefined errors for all of the symbols that should be created e.g. my equivalent of IHelloWorldPtr, ptrHW etc... I've tried inspecting the TLB using the COM/OLE Viewer, but this doesn't seem to contain any of the names I'd recognise.
    Could you please post the errors you are getting?

    Comment

    • amasidlover
      New Member
      • Apr 2009
      • 2

      #3
      Hi,

      I'll add the relevant code too as the errors are meaningless without...

      The C++/COM import:
      Code:
      #include "stdafx.h"
      #import "CSharpProxyRetail.tlb" raw_interfaces_only
      #include <iostream>
      #include <atlbase.h>
      
      using namespace CSharpProxyRetail;
      using namespace std;
      
      int _tmain(int argc, _TCHAR* argv[])
      {
      	HRESULT hr = CoInitialize(NULL);
      	BSTR Val;
      	
      	IRetailPtr ptrHW (__uuidof(WrapRetail)); 
      	ptrHW>getStockInformation();
      	ptrHW>QuantityOnPO(&Val);
      
      	CW2A szResponse(Val);
      	cout << szResponse << endl;
      	::SysFreeString(Val);
      	CoUninitialize();
      	return 0;
      }
      The c# (.NET) export of the interface:

      Code:
      public interface IRetail
      {
          void getStockInformation();
          string QuantityOnPO();
         
      }
      
      
      [ComVisible(true)]    // By default, this value is true. However, this line of code is 
      // included for documentation purposes.
      public class WrapRetail : IRetail
      {
          private Retail ws;
          private StockInfo si;
      
          public WrapRetail()
          {
              ws = new Retail();
          }
          public void getStockInformation()
          {
              si = ws.getStockInformation("37530119", 44);
          }
      
          public string QuantityOnPO()
          {
              return si.QuantityOnPO.ToString();
          }
      }
      The errors are:
      Code:
      \TestToo.cpp(14) : error C2065: 'IRetailPtr' : undeclared identifier
      \TestToo.cpp(14) : error C2146: syntax error : missing ';' before identifier 'ptrHW'
      \TestToo.cpp(14) : error C2065: 'ptrHW' : undeclared identifier
      \TestToo.cpp(15) : error C2065: 'getStockInformation' : undeclared identifier
      \TestToo.cpp(15) : warning C4552: '>' : operator has no effect; expected operator with side-effect
      \TestToo.cpp(16) : error C2065: 'QuantityOnPO' : undeclared identifier
      \TestToo.cpp(16) : warning C4552: '>' : operator has no effect; expected operator with side-effect
      \TestToo.cpp(18) : error C2065: 'CW2A' : undeclared identifier
      \TestToo.cpp(18) : error C2146: syntax error : missing ';' before identifier 'szResponse'
      \TestToo.cpp(18) : error C2065: 'szResponse' : undeclared identifier
      We've actually used gSOAP and done the whole thing in C++ as we were under some time pressure, but I'd be interested in the solution to this issue and it may help someone else...

      Alex

      Comment

      Working...