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. C / C++ / MFC
  4. Calling classes from DLLs

Calling classes from DLLs

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 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.
  • B Offline
    B Offline
    Bisyork
    wrote on last edited by
    #1

    I have been having problems trying to set up a plugin for my program. The program loads a DLL dynamically, and then calls a member function:

    __declspec(dllexport) int Start(CDervDlg *dlg)
    {
    dlg->m_SomeVar = TRUE; //Works fine
    dlg->SomeFunc("Blah", "Blah"); //Link error: unresolved external symbol.
    }

    I've tried using both regular DLLs and Extension DLLs, but neither work. This is probably just something obvious that I just can't see, but can anyone help?

    J 1 Reply Last reply
    0
    • B Bisyork

      I have been having problems trying to set up a plugin for my program. The program loads a DLL dynamically, and then calls a member function:

      __declspec(dllexport) int Start(CDervDlg *dlg)
      {
      dlg->m_SomeVar = TRUE; //Works fine
      dlg->SomeFunc("Blah", "Blah"); //Link error: unresolved external symbol.
      }

      I've tried using both regular DLLs and Extension DLLs, but neither work. This is probably just something obvious that I just can't see, but can anyone help?

      J Offline
      J Offline
      Jaime Stuardo
      wrote on last edited by
      #2

      if SomeFunc is on the DLL, you have to dllexport it when generating the DLL and dllimport when generating the EXE. If it is an MFC extension DLL, you can use the AFX_EXT_CLASS macro, for example: class AFX_EXT_CLASS CMyDlg : public CDialog { }; Jaime

      B 1 Reply Last reply
      0
      • J Jaime Stuardo

        if SomeFunc is on the DLL, you have to dllexport it when generating the DLL and dllimport when generating the EXE. If it is an MFC extension DLL, you can use the AFX_EXT_CLASS macro, for example: class AFX_EXT_CLASS CMyDlg : public CDialog { }; Jaime

        B Offline
        B Offline
        Bisyork
        wrote on last edited by
        #3

        Somefunc is in the EXE.

        ///EXE code
        class CDervDlg : public CDialog
        {
        void TestLoad();
        void SomeFunc(CString, CString);

        BOOL m\_SomeVar;
        

        };

        typedef int (*SCGptr)(CDervDlg *);
        void TestLoad()
        {
        HINSTANCE inst = AfxLoadLibrary("testlib.dll");
        SCGptr Startfunc = (SCGptr)GetProcAddress(inst, "?Start@@YAHPAVCDervDlg@@@Z");
        if (Startfunc != NULL)
        Startfunc(this);
        }

        ///DLL code
        #include "DervDlg.h"

        __declspec(dllexport) int Start(CDervDlg *dlg)
        {
        dlg->m_SomeVar = TRUE; //Works fine
        dlg->SomeFunc("Blah", "Blah"); //Link error: unresolved external symbol.
        }

        Thank you for helping.

        J 1 Reply Last reply
        0
        • B Bisyork

          Somefunc is in the EXE.

          ///EXE code
          class CDervDlg : public CDialog
          {
          void TestLoad();
          void SomeFunc(CString, CString);

          BOOL m\_SomeVar;
          

          };

          typedef int (*SCGptr)(CDervDlg *);
          void TestLoad()
          {
          HINSTANCE inst = AfxLoadLibrary("testlib.dll");
          SCGptr Startfunc = (SCGptr)GetProcAddress(inst, "?Start@@YAHPAVCDervDlg@@@Z");
          if (Startfunc != NULL)
          Startfunc(this);
          }

          ///DLL code
          #include "DervDlg.h"

          __declspec(dllexport) int Start(CDervDlg *dlg)
          {
          dlg->m_SomeVar = TRUE; //Works fine
          dlg->SomeFunc("Blah", "Blah"); //Link error: unresolved external symbol.
          }

          Thank you for helping.

          J Offline
          J Offline
          Jaime Stuardo
          wrote on last edited by
          #4

          In DLL you have to declare: class __declspect(dllimport) CDervDlg : public CDialog { void TestLoad(); void SomeFunc(CString, CString); BOOL m_SomeVar; }; and in EXE: class __declspect(dllexport) CDervDlg : public CDialog { void TestLoad(); void SomeFunc(CString, CString); BOOL m_SomeVar; }; In your DLL you are using a function declared in the EXE, that's why you need to export from the EXE, and import it into the DLL. Jaime

          B 1 Reply Last reply
          0
          • J Jaime Stuardo

            In DLL you have to declare: class __declspect(dllimport) CDervDlg : public CDialog { void TestLoad(); void SomeFunc(CString, CString); BOOL m_SomeVar; }; and in EXE: class __declspect(dllexport) CDervDlg : public CDialog { void TestLoad(); void SomeFunc(CString, CString); BOOL m_SomeVar; }; In your DLL you are using a function declared in the EXE, that's why you need to export from the EXE, and import it into the DLL. Jaime

            B Offline
            B Offline
            Bisyork
            wrote on last edited by
            #5

            Thank you very much. It works now.

            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