COM Codebase Location - How to pick which version to use?

1

I have needed to modify code in a C# DLL and use it within a C++ application. I am not savvy at all in C++, so if something isn't clear let me know.

I've registered the C# assembly using:

regasm file.dll /tlb:file.dll /codebase

However, when I try to use this in the c++ application:

CLSID clsid;
CLSIDFromProgID(L"MyApp.MyClass", &clsid);

HRESULT hr = CoCreateInstance(clsid,NULL, CLSCTX_INPROC_SERVER ,IID_MyClass, reinterpret_cast<void**>(&myclass));

hr returns with 0x8013151a: access to this member is denied

I've noticed that in registry, I see multiple versions of the C# dll (with Codebase pointing to different dll locations).

I think the problem is because it's not using the correct dll. (I could be completely wrong).

My question is this, how do you know which version of the dll it's trying to load?

Thanks in advance.

c++
dll
com
com-interop
regasm
asked on Stack Overflow Dec 24, 2014 by Puzzled • edited Dec 24, 2014 by Puzzled

1 Answer

4

Pretty unlikely that this is a DLL Hell problem. You can double-check by using the debugger's Debug + Windows + Modules window, it shows you the path of the DLL. Keep your registry clean by letting MSBuild register the component, Project + Properties, Build tab, "Register for COM interop" option. VS must run elevated.

This is a MethodAccessException, always a coding bug. Psychic debugging required without seeing your code but the simplest explanation is that your C# class' default constructor is not public.

answered on Stack Overflow Dec 24, 2014 by Hans Passant

User contributions licensed under CC BY-SA 3.0