How do I import a .net dll to a vc++ project?

R

Ricardo Vázquez

I need to use a .NET DLL I've written in C#, within a VC++ 6.0/MFC project.
Googling I find plenty of topics related with using a VC++ DLL in a .NET
project...
But I need exactly the other way round: a .NET DLL in a VC++ project.
Is this possible?
How do I import the .net dll to the vc++ project? (both the .net dll and the
vc++ project are my code)

Thank you very much.

Ricardo Vazquez.
 
S

Scott M.

You need the .NET .dll to have been compiled in the "Register for InterOp"
mode. Then you can use the .NET "regasm.exe" tool to finish the process.

If all you have is the .NET .dll (and not access to the project source
code), then you're out of luck.

-Scott
 
K

Kerem Gümrükcü

Hi Ricardo!
I need to use a .NET DLL I've written in C#, within a VC++ 6.0/MFC
project.
Googling I find plenty of topics related with using a VC++ DLL in a .NET
project...
Ok,...

But I need exactly the other way round: a .NET DLL in a VC++ project.
Is this possible?

Yes it is and there is very good support on that! You have to expose the
managed .net library via COM to your operating system and other applications
that want to use your managed library. Here are several good examples and
explantations/backgrounders on that topic:


[NET Framework Developer's Guide
Exposing .NET Framework Components to COM]
http://msdn.microsoft.com/en-us/library/zsfww439(VS.71).aspx

[How to call a managed DLL from native Visual
C++ code in Visual Studio.NET or in Visual Studio
2005]
http://support.microsoft.com/kb/828736/en-us

[Understanding Classic COM Interoperability
With .NET Applications]
http://www.codeproject.com/KB/COM/cominterop.aspx

[Building COM Servers in .NET]
http://www.codeproject.com/KB/COM/BuildCOMServersInDotNet.aspx

[Calling Managed .NET C# COM Objects
from Unmanaged C++ Code]
http://www.codeproject.com/KB/cs/ManagedCOM.aspx


Hope this helps,..

Regards

Kerem

--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
 
K

Kerem Gümrükcü

Hi Scott,
If all you have is the .NET .dll (and not access to the project source
code), then you're out of luck.

thats partially true and partially false. You still could write
a wrapper (proxy/assembly dll) and make it COM visible, this
even has some advantages, e.g encapsulating difficult calls
and stuff, possibly extending the functionality of the old net dll
with new things and many more,...this is just a example,...

Regards

Kerem

--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
 
G

Gregory A. Beamer

I need to use a .NET DLL I've written in C#, within a VC++ 6.0/MFC
project. Googling I find plenty of topics related with using a VC++
DLL in a .NET project...
But I need exactly the other way round: a .NET DLL in a VC++ project.
Is this possible?
How do I import the .net dll to the vc++ project? (both the .net dll
and the vc++ project are my code)

The short answer is set up a COM callable wrapper. This can be as simple
as using tlbexp.exe (type library export) and creating the wrapper. I
believe you have to register the wrapper in the registry, but this is
fairly easy to do. You can google tblexp.exe for more info on the
command line tool.

Regasm.exe shortens the steps a bit, as it handles a couple of tasks,
but, if I remember correctly, you can regsrv32.exe the wrapper if you
need basic COM support. I would double check this.

As for "both in same project and need a project reference", it is not
going to happen with interop, so you have to separate the two out a bit.
Logical separation (in your head) may be enough, but putting in two
projects may be easier to ensure you keep the wrapper updated with the
assembly. It really depends on how you work.

Peace and Grace,
Greg


--
Vote for Miranda's Christmas Story
http://tinyurl.com/mirandabelieve

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
T

Tom Shelton

I need to use a .NET DLL I've written in C#, within a VC++ 6.0/MFC project.
Googling I find plenty of topics related with using a VC++ DLL in a .NET
project...
But I need exactly the other way round: a .NET DLL in a VC++ project.
Is this possible?
How do I import the .net dll to the vc++ project? (both the .net dll and the
vc++ project are my code)

Thank you very much.

Ricardo Vazquez.

A non-com alternative is to use C++/CLI:

http://tom-shelton.net/index.php/20...ged-code-from-a-dll-created-in-visual-c-2008/
 
R

Ricardo Vázquez

Scott! Kerem!

Thank you so much!

Kindest regards,

Ricardo.

Kerem Gümrükcü said:
Hi Ricardo!
I need to use a .NET DLL I've written in C#, within a VC++ 6.0/MFC
project.
Googling I find plenty of topics related with using a VC++ DLL in a .NET
project...
Ok,...

But I need exactly the other way round: a .NET DLL in a VC++ project.
Is this possible?

Yes it is and there is very good support on that! You have to expose the
managed .net library via COM to your operating system and other
applications
that want to use your managed library. Here are several good examples and
explantations/backgrounders on that topic:


[NET Framework Developer's Guide
Exposing .NET Framework Components to COM]
http://msdn.microsoft.com/en-us/library/zsfww439(VS.71).aspx

[How to call a managed DLL from native Visual
C++ code in Visual Studio.NET or in Visual Studio
2005]
http://support.microsoft.com/kb/828736/en-us

[Understanding Classic COM Interoperability
With .NET Applications]
http://www.codeproject.com/KB/COM/cominterop.aspx

[Building COM Servers in .NET]
http://www.codeproject.com/KB/COM/BuildCOMServersInDotNet.aspx

[Calling Managed .NET C# COM Objects
from Unmanaged C++ Code]
http://www.codeproject.com/KB/cs/ManagedCOM.aspx


Hope this helps,..

Regards

Kerem

--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
 
R

Ricardo Vázquez

Wonderful solution, Tom.
Clean, neat, no problems when installing my app, and so clearly documented.

Thank a lot.

Best regards,

Ricardo.
 

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