Using C# dll as COM in an MFC application

J

Janiv Ratson

Hello,
I have written a C# dll in VS2005.
One interface and class are exported using Interop Services.
I want to use this c# dll in my MFC application, using VS2003.
It compiles after I imported the dll to my MFC app.
On runtime I get class not registered HR error in my MFC project.

I use the code as follow:
_NewActivationPtr myActivation = NULL;

HRESULT hr = myActivation.CreateInstance(__uuidof(NewSupernaActivation));

I don't what to do.

Do I have to use GACUtil to register?

If I want to use GACUtil do I have to sign my project?

Trying do it had failed, because my third party library I'm using in my C#
dll is not signed (so if I choose to sign my project, there is a compilation
error, caused because the 3rd party library is not signed, I guess).

Please help,

Thanks,

Janiv Ratson.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


In addition to DePalo post take a look at the latest number of MSDN
magazine, it has one article about that precise subject.
 
G

Guest

Janiv,

Did you check the registry to make sure that the COM interfaces were
actually registered?

Run Regedit.exe and then search on NewSupernaActivation or the name of your
DLL. If you don't find it then it's not registered and that is your problem.
You'll need to run regasm.exe to register the DLL.

Kim
 
D

Dr. Jochen Manns

Did you RegAsm the Assembly? Importing may register only the type library.
 
D

Dr. Jochen Manns

Did you try RegAsm /Codebase.

Eventuall POST the registry Settings under the CLSID here for inspection.
You can check yourself if there are multiple keys below InprocServer32 of
your component. If so remove the CLSID entry of your component, make sure
that the assembly version in AssemblyInfo.cs does not use auto-increment
(1.0.0.1 instead of the VS.NET 2003 default 1.0.*) and RegAsm /Codebase the
assembly again.

Jochen
 
J

Janiv Ratson

Hello all and thanks for your help.
I have registered my dll using regasm.exe.
I can find the NewSupernaActivation in the registry under CLSID.
Still I get Class not registered in my code.
Please help.
Thanks,
Janiv Ratson.
 
D

Dr. Jochen Manns

Are you sure? I thought that this message is only a warning.

RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase
can ca...
use your assembly to interfere with other applications that may be installed
on
the same computer. The /codebase switch is intended to be used only with
signed
assemblies. Please give your assembly a strong name and re-register it.
 
J

Janiv Ratson

Hello Dr. Manns and all,
In order to regasm my dll using /code base, I need my assembly to be signed.
Hoever, my assembly uses 3rd party assembly, which is not signed, and
therefor I my assembly cannot be signed.
Is there any other solution?
Thanks a lot,
Janiv Ratson.
 
D

Dr. Jochen Manns

Well - your choice, finally. In this special case: using a strongly names
assembly makes sure that no one tamperes with it. And registering something
as COM open wide access to the component on the system - no way for further
security verifications the assembly will have full trust. Personally (not
more) I can think there are scenarios where you can live with it. Yes,
indeed you losse .NET / CLR security but if someone is able to replace a DLL
on a system in most (s)he can choose to patch the registration to a modified
DLL anyway.

No more help to expect from this side, sorry :) But actually: does it work
after the RegAsm /Codebase?

Bye

Jochen
 
J

Janiv Ratson

Yes it works.
Thanks,
J.
Dr. Jochen Manns said:
Well - your choice, finally. In this special case: using a strongly names
assembly makes sure that no one tamperes with it. And registering
something as COM open wide access to the component on the system - no way
for further security verifications the assembly will have full trust.
Personally (not more) I can think there are scenarios where you can live
with it. Yes, indeed you losse .NET / CLR security but if someone is able
to replace a DLL on a system in most (s)he can choose to patch the
registration to a modified DLL anyway.

No more help to expect from this side, sorry :) But actually: does it
work after the RegAsm /Codebase?

Bye

Jochen
 
D

Dr. Jochen Manns

Hmm, hope that this is not a .NET 2.0 security feature which correlates with
the RegAsm warning.

Check InProgServer32 Codebase and make sure, that all required files are in
this directory. Eventually (?) the assembly requires more legacy (win32)
DLLs in this directory or the system search path.
 
J

Janiv Ratson

Hi,
It is now created but could not run due to "Could not load file or assembly
'3rd party assembly' exception.
I guess I haven't completed the action as required.
Any ideas?
Thanks.
J.
 
D

Dr. Jochen Manns

Sorry, I ment InprocServer32 in the Registry and there the CodeBase value.

When exactly is the load error reported? If you attach a debugger do you get
any more detailled error (output/trace window or inner exception)? Can you
activate the fusion log to find out which locations have been scanned for
the assembly (debugger should automatically report this - I think).

Jochen
 
G

Guest

Janiv,

It sounds like your DLL is registered. The next thing I would look at are
dependencies. You can use Depends.exe usually found as a tool in the
C:\program files\Microsoft Visual Studio 8\Common7\Tools\bin if you are using
VS2005.

Start Depends and then open your DLL, make sure that everything that your
DLL needs to execute is available AND properly registered. If Depends can't
find a dependency it should show up in Red.

Kim
 
D

Dr. Jochen Manns

But I think this will not show up late binding .NET Interop Dependencies
(DllImportAttribute).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top