calling managed code from unmanaged code (vc6)
-
we have an older application that we would like to extend with managed code (written in c#). The extension was planned to be through a dll written in C++ that would call managed part - as proposed in the following article: http://www.codeproject.com/dotnet/bridge.asp problem is that when I write a simple non-managed app in VC2005, I can call managed part without any problem, but when I try to call it from the same application compiled with VC6, it simply breaks. here is the C# assembly code: namespace ClassLibrary1 { public class Class1 { public static int ShowDialog(string sText, string sCaption) { System.Windows.Forms.MessageBox.Show(sText, sCaption); return 0; } } } here is the wrapper C++ dll using namespace System; using namespace ClassLibrary1; using namespace System::Windows::Forms; extern "C" __declspec(dllexport) int __cdecl callDotNet(char *text, char *caption) { String ^sText = gcnew String(text); String ^sCaption = gcnew String(caption); // MessageBox::Show("about to enter Class1"); Class1::ShowDialog(sText, sCaption); return 0; } and here is the simple console app that calls a DLL that calls C# code: extern "C" __declspec(dllexport) int __cdecl callDotNet(char *text, char *caption); int main(int argc, char* argv[]) { callDotNet("sample text", "sample caption"); return 0; } This works if it is compiled in VS2005 but breaks when compiled in VC6 (unhandled exception in console2.exe (KERNEL32.DLL): 0xE0434F4D:(no name).) Unfortunately it is not possible to recompile the old application with VC2005 since it is pretty old application with a lots of code written in cobol. This may be a newbie question or has been discussed before, but I searched the message boards and could't find anything similar. I am not sure at all that it is possible to connect unmanaged code with managed code this way. Am I on the right track? Tnx in advance Dragan Matic
-
we have an older application that we would like to extend with managed code (written in c#). The extension was planned to be through a dll written in C++ that would call managed part - as proposed in the following article: http://www.codeproject.com/dotnet/bridge.asp problem is that when I write a simple non-managed app in VC2005, I can call managed part without any problem, but when I try to call it from the same application compiled with VC6, it simply breaks. here is the C# assembly code: namespace ClassLibrary1 { public class Class1 { public static int ShowDialog(string sText, string sCaption) { System.Windows.Forms.MessageBox.Show(sText, sCaption); return 0; } } } here is the wrapper C++ dll using namespace System; using namespace ClassLibrary1; using namespace System::Windows::Forms; extern "C" __declspec(dllexport) int __cdecl callDotNet(char *text, char *caption) { String ^sText = gcnew String(text); String ^sCaption = gcnew String(caption); // MessageBox::Show("about to enter Class1"); Class1::ShowDialog(sText, sCaption); return 0; } and here is the simple console app that calls a DLL that calls C# code: extern "C" __declspec(dllexport) int __cdecl callDotNet(char *text, char *caption); int main(int argc, char* argv[]) { callDotNet("sample text", "sample caption"); return 0; } This works if it is compiled in VS2005 but breaks when compiled in VC6 (unhandled exception in console2.exe (KERNEL32.DLL): 0xE0434F4D:(no name).) Unfortunately it is not possible to recompile the old application with VC2005 since it is pretty old application with a lots of code written in cobol. This may be a newbie question or has been discussed before, but I searched the message boards and could't find anything similar. I am not sure at all that it is possible to connect unmanaged code with managed code this way. Am I on the right track? Tnx in advance Dragan Matic
Dragan Matic wrote:
non-managed app in VC2005
VC6 has no support for the .NET platform (managed code), you must use later compiler.
Dragan Matic wrote:
it is pretty old application with a lots of code written in cobol.
And you compile Cobal with VC6? :confused:
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real"
Score: 1.0 in the Soap Boxled mike
-
Dragan Matic wrote:
non-managed app in VC2005
VC6 has no support for the .NET platform (managed code), you must use later compiler.
Dragan Matic wrote:
it is pretty old application with a lots of code written in cobol.
And you compile Cobal with VC6? :confused:
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real"
Score: 1.0 in the Soap Boxled mike
led mike wrote:
VC6 has no support for the .NET platform (managed code), you must use later compiler.
I know that, but it was my understanding that functions prefixed with extern "C" will be visible (and callable) as simple C functions. I expected to be able to call them as any other dll that exports some functions and structures.
led mike wrote:
And you compile Cobal with VC6?
No, actually the application we have is an old cobol application now largely extended and partly replaced with code written in VC6. Cobol can call VC6 dlls, so I thought it could also call dlls written in VS2005 - as long as the functions are exported with extern "C" prefixes. When I didn't succeed in that, I tried to call a dll from program written with VC6 only to find that is not possible, too.
-
led mike wrote:
VC6 has no support for the .NET platform (managed code), you must use later compiler.
I know that, but it was my understanding that functions prefixed with extern "C" will be visible (and callable) as simple C functions. I expected to be able to call them as any other dll that exports some functions and structures.
led mike wrote:
And you compile Cobal with VC6?
No, actually the application we have is an old cobol application now largely extended and partly replaced with code written in VC6. Cobol can call VC6 dlls, so I thought it could also call dlls written in VS2005 - as long as the functions are exported with extern "C" prefixes. When I didn't succeed in that, I tried to call a dll from program written with VC6 only to find that is not possible, too.
Dragan Matic wrote:
No, actually the application we have is an old cobol application now largely extended and partly replaced with code written in VC6.
So you mean with VC6 DLL's? You might have a library problem. A C/C++ DLL requires support of the CRT libraries at a miniumum and VS2003 and 2005 had new CRT versions.
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real"
Score: 1.0 in the Soap Boxled mike