I have written a managed dll written in c++ .NET, I now need to use this dll from vc++ which is unmanaged, what is the procedure for this and draw backs if any?
.NET module could be used in unmanaged code only via proxy library which gives to module ability to mimic COM-module behavior. Such proxy dll could be built with the regasm.exe utility (or tlbexp.exe with some extra body motions).
I'm not an expert in the question but I'm hear the talkings next to me already a couple of days... And I've got a couple of books on .NET and took a look at them at bedtime.
Thanks for the reply, still looking for an answer, the only way I can see it to be done is to write a bridge dll, which is the last thing I want to do, I just want an easy way of using my managed C++ dll with unmanaged C++.
The problem I have is that I have a lot of legacy code that cannot be-written very easily, the code relies heavely on MFC, and I have written an managed C++ dll that is using the great .NET model, my new projects are being written in .NET.
Worked out a work around, I have exported a bridge function from the managed dll, now my managed dll should be able to be used by any language.
The following code exports a single function 'bridge_function', this function then creates a reference to an object then sends an email by SMTP, it works like a dream.
The work now starts in converting data types from unmanaged to managed and visa versa, so if anyone can assist in the procedure I would be grateful,
I would first like to convert a CString to a String and also pass arrays of strings, ints etc...
Worked out a work around, I have exported a bridge function from the managed dll, now my managed dll should be able to be used by any language.
...
The work now starts in converting data types from unmanaged to managed and visa versa, so if anyone can assist in the procedure I would be grateful,
I would first like to convert a CString to a String and also pass arrays of strings, ints etc...
I respect your stubbornness deeply. And it's the last time I repeat my advice to generate proxy COM-dll. The side effect of this action is very useful - there type library will be generated, and you will be able at unmanaged side to use COMpatible types which will be converted by proxy to .NET types transparently.
Otherwise you definitely need to do all type transformations "hand-craftily".
PS. Another nice effect is the ability to use all available assembly classes as COM-objects (with some restrictions). You never need to "bridge" and "bond" - you just come and take.
PPS. Of course things not so easy - there always some threshold exists you have to step over. And the question is - does the effort cost a result.
I am not stubborn, just new to .NET and having to deal with the problem I have, I have taken your suggestion on board and will be looking at it very shortly, the creating of the proxy COM-dll might be the answer but I needed to get some code working and exporting a bridge function solved the problem, remember there is more than one road to a destination.
Created a type library from my .NET DLL, using regasm, when I came to import the type library into a test unmanaged project, I have got a few problems, the TLH file was created with no problem, but trying to create an instance seemed to cause a problem the error was saying No Interface.
Well, I have done a little sample - though I was very short of time I was extremely interested, because I heard a lot about that "inability to create instance" and "no interface registered" or something like that...
I don't know why my sample was so obedient - it was started at once. Is it too simple?
By the way, Filbert, thank you for the topic - I had intension to touch .NET, and that intension was lasted very long time, but I had really touched it only this afternoon.
PS. I found I was wrong - there are no additional dlls produced during regasm'ing .NET module - it's just proper registration record generated. Sorry, I'm only .NET-beginner.
Last edited by Igor Vartanov; January 6th, 2005 at 02:55 AM.
Igor, There seems to be a problem when using C++ .NET, I created a test project using C# and it worked first time? Have you tried to write a managed DLL using C++, I am now banging my head on the desk in dismay!!! I thought .NET was a framework that can be used by C++, C#, VB etc...
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.