Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. calling managed code from unmanaged code (vc6)

calling managed code from unmanaged code (vc6)

Scheduled Pinned Locked Moved Managed C++/CLI
csharpquestionc++comhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dragan Matic
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • D 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

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      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 Box

      led mike

      D 1 Reply Last reply
      0
      • L led 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 Box

        led mike

        D Offline
        D Offline
        Dragan Matic
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • D Dragan Matic

          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.

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          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 Box

          led mike

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups