Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2006

Tip: Looking for answers? Try searching our database.

Using C# dll as COM in an MFC application

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Janiv Ratson - 17 Aug 2006 17:22 GMT
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.
Ignacio Machin ( .NET/ C# MVP ) - 17 Aug 2006 20:07 GMT
Hi,

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

Signature

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

> Hello,
> I have written a C# dll in VS2005.
[quoted text clipped - 24 lines]
>
> Janiv Ratson.
Kim Greenlee - 17 Aug 2006 20:45 GMT
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

Signature

digipede - Many legs make light work.
Grid computing for the real world.
http://www.digipede.net
http://krgreenlee.blogspot.net

Janiv Ratson - 20 Aug 2006 08:10 GMT
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.

> Janiv,
>
[quoted text clipped - 8 lines]
>
> Kim
Dr. Jochen Manns - 20 Aug 2006 08:33 GMT
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

> Hello all and thanks for your help.
> I have registered my dll using regasm.exe.
[quoted text clipped - 16 lines]
>>
>> Kim
Janiv Ratson - 20 Aug 2006 09:12 GMT
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.

> Did you try RegAsm /Codebase.
>
[quoted text clipped - 27 lines]
>>>
>>> Kim
Dr. Jochen Manns - 20 Aug 2006 09:55 GMT
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.

> Hello Dr. Manns and all,
> In order to regasm my dll using /code base, I need my assembly to be
[quoted text clipped - 36 lines]
>>>>
>>>> Kim
Janiv Ratson - 20 Aug 2006 12:18 GMT
Is it a warning we can live with ?
Thanks,
Janiv Ratson.

> Are you sure? I thought that this message is only a warning.
>
[quoted text clipped - 46 lines]
>>>>>
>>>>> Kim
Dr. Jochen Manns - 20 Aug 2006 13:02 GMT
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

> Is it a warning we can live with ?
> Thanks,
[quoted text clipped - 50 lines]
>>>>>>
>>>>>> Kim
Janiv Ratson - 20 Aug 2006 13:32 GMT
Yes it works.
Thanks,
J.
> Well - your choice, finally. In this special case: using a strongly names
> assembly makes sure that no one tamperes with it. And registering
[quoted text clipped - 66 lines]
>>>>>>>
>>>>>>> Kim
Janiv Ratson - 20 Aug 2006 15:50 GMT
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.
> Yes it works.
> Thanks,
[quoted text clipped - 70 lines]
>>>>>>>>
>>>>>>>> Kim
Dr. Jochen Manns - 20 Aug 2006 16:20 GMT
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.

> Hi,
> It is now created but could not run due to "Could not load file or
[quoted text clipped - 78 lines]
>>>>>>>>>
>>>>>>>>> Kim
Janiv Ratson - 20 Aug 2006 16:47 GMT
How do I use InProgServer32 ?
All required files are in the same folder.
Thanks.

> Hmm, hope that this is not a .NET 2.0 security feature which correlates
> with the RegAsm warning.
[quoted text clipped - 85 lines]
>>>>>>>>>>
>>>>>>>>>> Kim
Dr. Jochen Manns - 20 Aug 2006 17:10 GMT
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

> How do I use InProgServer32 ?
> All required files are in the same folder.
[quoted text clipped - 90 lines]
>>>>>>>>>>>
>>>>>>>>>>> Kim
Kim Greenlee - 21 Aug 2006 04:17 GMT
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

Signature

digipede - Many legs make light work.
Grid computing for the real world.
http://www.digipede.net
http://krgreenlee.blogspot.net

Dr. Jochen Manns - 21 Aug 2006 06:36 GMT
But I think this will not show up late binding .NET Interop Dependencies
(DllImportAttribute).

> Janiv,
>
[quoted text clipped - 10 lines]
>
> Kim
Dr. Jochen Manns - 17 Aug 2006 23:28 GMT
Did you RegAsm the Assembly? Importing may register only the type library.

> Hello,
> I have written a C# dll in VS2005.
[quoted text clipped - 24 lines]
>
> Janiv Ratson.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.