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. using a MFC DLL in C++ .Net

using a MFC DLL in C++ .Net

Scheduled Pinned Locked Moved Managed C++/CLI
c++csharpcomhelpquestion
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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Hi, I have to use a MFC C++ DLL (unmanaged of course) in a C++ .Net project. I have problems to do that. I've created a C++ .Net project and includes the MFC DLL. My problems comes as soon as I call a method (ctor, dtor or method) from the MFC DLL. I've got this kind of error : error LNK2001: unresolved external symbol "public: __thiscall toto::toto(void)" (??0toto@@$$FQAE@XZ) fatal error LNK1120: 2 unresolved externals toto is the unmanaged class from the MFC DLL. I call it in the C++ .Net class like this : toto *p; p = new toto(); (the first line compile but not the second) Thanks, Denis (denissohet AT hotmail DOT com

    U 1 Reply Last reply
    0
    • A Anonymous

      Hi, I have to use a MFC C++ DLL (unmanaged of course) in a C++ .Net project. I have problems to do that. I've created a C++ .Net project and includes the MFC DLL. My problems comes as soon as I call a method (ctor, dtor or method) from the MFC DLL. I've got this kind of error : error LNK2001: unresolved external symbol "public: __thiscall toto::toto(void)" (??0toto@@$$FQAE@XZ) fatal error LNK1120: 2 unresolved externals toto is the unmanaged class from the MFC DLL. I call it in the C++ .Net class like this : toto *p; p = new toto(); (the first line compile but not the second) Thanks, Denis (denissohet AT hotmail DOT com

      U Offline
      U Offline
      ursus zeta
      wrote on last edited by
      #2

      That unresolved external symbol is pretty common; and generally, it means that you somehow failed to reference whatever it was (DLL), or failed to link to the LIB file. In this case, since you are importing an unmanaged function into a managed .NET project, you must use the System::Runtime::InteropServices namespace and the DLLImport attribute preceeding the function declaration. This explains and shows the correct syntax: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeinteropservicesdllimportattributeclasstopic.asp[^]

      A 1 Reply Last reply
      0
      • U ursus zeta

        That unresolved external symbol is pretty common; and generally, it means that you somehow failed to reference whatever it was (DLL), or failed to link to the LIB file. In this case, since you are importing an unmanaged function into a managed .NET project, you must use the System::Runtime::InteropServices namespace and the DLLImport attribute preceeding the function declaration. This explains and shows the correct syntax: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeinteropservicesdllimportattributeclasstopic.asp[^]

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        DllImport must be use to import an unmanaged function but I have to import into my C++ .Net code, classes from unmanaged code... And I don't know how to do. I want to do a wrapper but I can't call my unmanaged classes un .Net code. That's my problem in fact. I've try the DllImport, but I can't call a constructor :s Is it possible to do this ? Thks

        U 1 Reply Last reply
        0
        • A Anonymous

          DllImport must be use to import an unmanaged function but I have to import into my C++ .Net code, classes from unmanaged code... And I don't know how to do. I want to do a wrapper but I can't call my unmanaged classes un .Net code. That's my problem in fact. I've try the DllImport, but I can't call a constructor :s Is it possible to do this ? Thks

          U Offline
          U Offline
          ursus zeta
          wrote on last edited by
          #4

          Sorry for not replying. I'm not a big fan of MFC, but, I've read that using MFC classes in a .NET CLR project can be problematic. As I recall there is a conflict with a compiler switch that enables runtime type checks in MFC, and this conflicts with the operation of the Common Language Runtime. Sorry for my previous post, it could just be making things more difficult for you. There is an article on MSDN Magazine about this problem. I suggest that you search there.

          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