Accessing C# from C++ COM client

Hi,

Below's the COM client written in native C++. It does two things:
1) Get's updated value of a variable from COM Server, which indeed works fine
2) Calls C# code(that accesses .csv file via OLE, easier in C#) and here's the problem. I have converted C# code into Program.dll library and then to Program.tlb and registered the type library. Copied Program.tlb, so that the below COM client can access it.

I am compiling below code by cl /EHsc comtest.cpp

and it gives error message as
1
2
comtest.cpp(21) : error C2143: syntax error : missing ';' before '.'
comtest.cpp(21) : error C2143: syntax error : missing ';' before '.'


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include "atlbase.h"
#import "vc90.tlb" no_namespace
#import "Program.tlb"

int main()
{
   CoInitializeEx(NULL, COINIT_MULTITHREADED);
   {
      CComPtr<IUnknown> spUnknown;
      spUnknown.CoCreateInstance(__uuidof(CObject1));

      CComPtr<IObject1> pI;
      spUnknown.QueryInterface(&pI);

      
      //Get updated value of "res" variable from COM server
      int res = 0;
      res = pI->GetANum();
      std::cout << res << std::endl;
      
      //Calling C# code
      cout << "Calling ConvertToXML" << endl;
      Program::CXLStoXML.ConvertToXML();
      cout <<"Called ConvertToXML" << endl;
	  
   }
   CoUninitialize();
}


Does anybody know how to fix the compilation error?
Last edited on
Program::CXLStoXML.ConvertToXML(); ConvertToXML is probably static so write Program::CXLStoXML::ConvertToXML(); // note that ::
Topic archived. No new replies allowed.