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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How do i dynamically acces method export in CLASS

How do i dynamically acces method export in CLASS

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
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.
  • K Offline
    K Offline
    Killer3
    wrote on last edited by
    #1

    #ifdef EXPCLASS_EXPORTS #define EXPCLASS_API __declspec(dllexport) #else #define EXPCLASS_API __declspec(dllimport) #endif // This class is exported from the EXPCLASS.dll class EXPCLASS_API CEXPCLASS { public: CEXPCLASS(void); char * CEXPMethod(char * plaintext , char * key); // TODO: add your methods here. }; How do i dynamically acces method export in CLASS? CODE USED TO ACCESS METHOD EXPORT IN CLASS hDLL = LoadLibrary("EXPCLASS.dll"); if (hDLL != NULL) { lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"CEXPMethod"); if (lpfnDllFunc1 ==NULL) { // handle the error FreeLibrary(hDLL); } else { strResult = lpfnDllFunc1("killer" ,"strikes HERE"); } } for thendral -- modified at 6:54 Thursday 20th April, 2006

    N 1 Reply Last reply
    0
    • K Killer3

      #ifdef EXPCLASS_EXPORTS #define EXPCLASS_API __declspec(dllexport) #else #define EXPCLASS_API __declspec(dllimport) #endif // This class is exported from the EXPCLASS.dll class EXPCLASS_API CEXPCLASS { public: CEXPCLASS(void); char * CEXPMethod(char * plaintext , char * key); // TODO: add your methods here. }; How do i dynamically acces method export in CLASS? CODE USED TO ACCESS METHOD EXPORT IN CLASS hDLL = LoadLibrary("EXPCLASS.dll"); if (hDLL != NULL) { lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"CEXPMethod"); if (lpfnDllFunc1 ==NULL) { // handle the error FreeLibrary(hDLL); } else { strResult = lpfnDllFunc1("killer" ,"strikes HERE"); } } for thendral -- modified at 6:54 Thursday 20th April, 2006

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      see this thread http://www.codeproject.com/script/comments/forums.asp?forumid=1647&Page=2&userid=1599046&mode=all&select=1404839&df=100&tid=1404839#xx1404839xx[^] nave

      K 1 Reply Last reply
      0
      • N Naveen

        see this thread http://www.codeproject.com/script/comments/forums.asp?forumid=1647&Page=2&userid=1599046&mode=all&select=1404839&df=100&tid=1404839#xx1404839xx[^] nave

        K Offline
        K Offline
        Killer3
        wrote on last edited by
        #3

        Hi naveen ! can u advise what exactly i need to do ? Use this API to get the address of a function that returns an instance of the class that you wish to access dynamically. For eg: The function will be something like this... void* FUNC_EXPORT CreateInstance() { return static_cast< void*> (new SomeClass); } Use GetProcAddress to get the address of this function for thendral

        N 1 Reply Last reply
        0
        • K Killer3

          Hi naveen ! can u advise what exactly i need to do ? Use this API to get the address of a function that returns an instance of the class that you wish to access dynamically. For eg: The function will be something like this... void* FUNC_EXPORT CreateInstance() { return static_cast< void*> (new SomeClass); } Use GetProcAddress to get the address of this function for thendral

          N Offline
          N Offline
          Naveen
          wrote on last edited by
          #4

          instead of returning the void* u can return the pointer to the class say SomeClass* FUNC_EXPORT CreateInstance() { return static_cast< void*> (new SomeClass); } them u can access the functions of that clas using the pointer obtained.. nave

          K 1 Reply Last reply
          0
          • N Naveen

            instead of returning the void* u can return the pointer to the class say SomeClass* FUNC_EXPORT CreateInstance() { return static_cast< void*> (new SomeClass); } them u can access the functions of that clas using the pointer obtained.. nave

            K Offline
            K Offline
            Killer3
            wrote on last edited by
            #5

            Iam not in control of the situation. Can i have a sample code that achieves it? class __declspec(dllexport) MyClass { public: static char* LSGDecrypt(const char* key,const char* hex); static char* LSGEncrypt(const char* key,const char* source); } The above class is export in a dll . So should i add new function to the dll ? Iam about access a static function So is that required to instantiate the class object. HINSTANCE hDLL; // Handle to DLL LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer char* key = new char [50]; key ="KEYVAULE"; char* strPlain = new char [50]; strPlain="password"; char* strResult = new char [50]; DWORD dwrd =NULL; hDLL = LoadLibrary("Mydll.dll"); if (hDLL != NULL) { lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"LSGEncrypt"); if (lpfnDllFunc1 ==NULL) // Fails here? so DLL is freed up? { FreeLibrary(hDLL); } else strResult = lpfnDllFunc1("killer" ,"strikes HERE"); } Thanks for thendral

            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