2

I've not found some example that really works. I need to create an interaction system for MetaTrader. It's better to use modern technologies like WCF or somehting else using C#, but MetaTrader doesn't support COM or just OOP at all. So I need some gateway component that must be functions library with non-object interface. Surely, it requires usage of C++. But I'm not succeeded to find over the Web some example how to call from a C++ functions library a C# COM+ DLL. All the examples I could find use component C++ assemblies that are not supported by MetaTrader. So, I can't use namespace, etc. in C++. I wrote a COM+ server application that is easy to call from C# by the following lines

object c2 = Activator.CreateInstance(Type.GetTypeFromProgID("Imutome.COMPlusCache.Cache"));
c2.GetType().InvokeMember("OnTransfer", BindingFlags.InvokeMethod, null, c2, null);

But when I'm trying to write in C++ something like this

CLSIDFromProgID(OLESTR("Imutome.COMPlusCache.Cache"), &rclsid);
HRESULT hres = CoCreateInstance(rclsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void **)&ppv);

I get just zeros in ppv and "0x80040154 Class not registered" in hres. I'm not sure what flags or what interface are required but I get the same error whatever I try. Although in C# everything works. Tell me please what do I need to change to make C++ succesfully create a COM+ object instance.

7
  • What happens if you pass CLSCTX_ALL? Also does CLSIDFromProgID() actually retrieve the right class id? Commented Mar 30, 2011 at 13:41
  • Have you initialized COM in the C++ thread? What about narrowing down the problem by trying to create some other more basic COM object using the same code (but a different ProgId, obviously). Commented Mar 30, 2011 at 13:45
  • (BTW depending on how you registered the C# assembly, it may need to be in the same directory as the running app) Commented Mar 30, 2011 at 13:46
  • @mackenir: He would have got another error code if he hadn't initialized COM. Commented Mar 30, 2011 at 13:48
  • CLSCTX_ALL doesn't help also. Of course, I've used CoInitialize before. The C# assembly is registered using ComponentService GUI. May be IID_IDispatch is really incorrect but I don't know what can I replace it with. ComponentService displays IManagedObject and other interfaces of ServicedComponent and one my inteface ICache. Commented Mar 30, 2011 at 14:52

1 Answer 1

1

I believe the problem is in the way you register your component. You shoud use:

regasm your_component_name.dll /tlb /codebase

OR

regasm your_component_name.dll /tlb

AND put your component library to GAC or your executable location. Hope this helps. ComponentService GUI is not the same.

Sign up to request clarification or add additional context in comments.

1 Comment

The problem is solved. The reason was really very simple. It was that the example from the Web I've used for the base had [assembly: AssemblyVersion("1.0.*")] So, the strong name didn't match the assembly version. I had just to replace the asteric.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.