Thread: Calling a class member through a pointer to a class in a DLL

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Calling a class member through a pointer to a class in a DLL

    Nasty stuff.

    I've got this DLL:

    Code:
    class GFXBase
    {
    public:
        GFXBase() {}
        ~GFXBase() {}
    
        void Nothing();
    
    };
    
    void GFXBase::Nothing()
    {
        MessageBox(NULL, "Nothing doing!", "HMM", MB_OK | MB_ICONEXCLAMATION);
    }
    
    extern "C" __declspec(dllexport) GFXBase *pGFXBase = NULL;
    
    
    BOOL APIENTRY DllMain( HANDLE hModule, 
                           DWORD  ul_reason_for_call, 
                           LPVOID lpReserved
    					 )
    {
        pGFXBase = new GFXBase();
    
        return TRUE;
    }
    With this trying to use it:

    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        HMODULE hGFXBaseDLL = NULL;
        void *pGFXBase = NULL;
    
        hGFXBaseDLL = LoadLibrary("GFXBase.dll");
        if (! hGFXBaseDLL)
        {
            MessageBox(NULL, "Error loading library", "Error", MB_OK | MB_ICONERROR | MB_TASKMODAL);
            return 1;
        }
    
        pGFXBase = (void *) GetProcAddress(hGFXBaseDLL, "pGFXBase");
        if (! pGFXBase)
        {
            MessageBox(NULL, "Error calling GetProcAddress()", "Error", MB_OK | MB_ICONERROR | MB_TASKMODAL);
            return 1;
        }
        else
            MessageBox(NULL, "Retreived pointer", "Yay", MB_OK | MB_ICONINFORMATION);
    
        
    
        FreeLibrary(hGFXBaseDLL);
        return 0;
    }
    Now I want to use the class without "knowing" the class. Hence the void pointer. T'all works fine (the pointer is retreived) but obviously I can't use it. There must be a way to call GFXBase::Nothing(), I just don't know how. Even if it involves insane doings I'd be interested to know.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Nevermind twas a stupid question and I'm sticking to a better approach.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  2. Simple thread object model (my first post)
    By Codeplug in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2004, 11:34 PM
  3. Member function pointer within the class
    By skorman00 in forum C++ Programming
    Replies: 1
    Last Post: 07-05-2004, 06:03 AM
  4. Using class with DLL
    By greg2 in forum C++ Programming
    Replies: 2
    Last Post: 09-12-2003, 05:24 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM