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. How to import class from a dll?

How to import class from a dll?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionc++sysadminhelp
3 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.
  • E Offline
    E Offline
    eli15021979
    wrote on last edited by
    #1

    Hi, I want to import a class from a dll dynamiclly by using LoadLibrary(DLLFile) and not by using Project->Settings->Link.... Is it the same as loading regular function from a dll(By getting a pointer to that function)? for example,if in my dll the function looks like this: in my dll.h file:

    #define TCPDLL_API __declspec(dllexport)

    #ifdef __cplusplus
    extern "C" {
    #endif

    TCPDLL_API ERROR_CODES FLRInitializeConnections(IPStruct *Server,int num_of_radars);

    #ifdef __cplusplus
    }
    #endif

    and in my dll.cpp file:

    TCPDLL_API ERROR_CODES FLRInitializeConnections(IPStruct *Server , int num_of_radars)
    {
    //Do something
    }

    now,when i want to use the function : in my app.h:

    typedef ERROR_CODES (*FLRInitializeConnections_PROC )(IPStruct*,int);

    HINSTANCE hLib;

    // imported functions handles
    FLRInitializeConnections_PROC FLRInitializeConnections;

    and in my app.cpp:

    hLib = LoadLibrary(DLL name);

    FLRInitializeConnections = (FLRInitializeConnections_PROC)GetProcAddress(hLib,"FLRInitializeConnections");

    Now i can call the function from the dll. My question is - in order to use a class from a dll , what should i do? Do i need to get a pointer to that class or can i load the dll and make instance of that class in the regular way? With best regards, Eli

    S 1 Reply Last reply
    0
    • E eli15021979

      Hi, I want to import a class from a dll dynamiclly by using LoadLibrary(DLLFile) and not by using Project->Settings->Link.... Is it the same as loading regular function from a dll(By getting a pointer to that function)? for example,if in my dll the function looks like this: in my dll.h file:

      #define TCPDLL_API __declspec(dllexport)

      #ifdef __cplusplus
      extern "C" {
      #endif

      TCPDLL_API ERROR_CODES FLRInitializeConnections(IPStruct *Server,int num_of_radars);

      #ifdef __cplusplus
      }
      #endif

      and in my dll.cpp file:

      TCPDLL_API ERROR_CODES FLRInitializeConnections(IPStruct *Server , int num_of_radars)
      {
      //Do something
      }

      now,when i want to use the function : in my app.h:

      typedef ERROR_CODES (*FLRInitializeConnections_PROC )(IPStruct*,int);

      HINSTANCE hLib;

      // imported functions handles
      FLRInitializeConnections_PROC FLRInitializeConnections;

      and in my app.cpp:

      hLib = LoadLibrary(DLL name);

      FLRInitializeConnections = (FLRInitializeConnections_PROC)GetProcAddress(hLib,"FLRInitializeConnections");

      Now i can call the function from the dll. My question is - in order to use a class from a dll , what should i do? Do i need to get a pointer to that class or can i load the dll and make instance of that class in the regular way? With best regards, Eli

      S Offline
      S Offline
      stolid_rock
      wrote on last edited by
      #2

      View this link http://www.codeproject.com/dll/classesexportedusingLL.asp[^]

      E 1 Reply Last reply
      0
      • S stolid_rock

        View this link http://www.codeproject.com/dll/classesexportedusingLL.asp[^]

        E Offline
        E Offline
        eli15021979
        wrote on last edited by
        #3

        thanks:->

        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