Thread: Dialogbox from within a DLL

  1. #31
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    You have two problems. First, remove WS_CHILD from the dialog. WS_DISABLED probably isn't all that useful either.
    Second, you're not declaring the DLL function correctly in the client. Two ways to fix this:
    Code:
    #include <windows.h>
    
    extern "C" __declspec(dllimport) 
    LRESULT DisplayMyMessage(HWND hwndOwner);
    
    #pragma comment(lib, "Con2DLL.lib")
    
    int main()
    { 
        DisplayMyMessage(0);
        return 0;
    }//main
    Or...
    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    
    typedef LRESULT (*DisplayMyMessage_pfn)(HWND);
    
    int main()
    { 
        HMODULE hmod = LoadLibraryA("Con2DLL.dll");
        if (!hmod)
        {
            cerr << "LoadLibrary failed, le = " << GetLastError() << endl;
            return 1;
        }//if
    
        DisplayMyMessage_pfn dm = 
            (DisplayMyMessage_pfn)GetProcAddress(hmod, "DisplayMyMessage");
        if (!dm)
        {
            FreeLibrary(hmod);
            cerr << "GerProcAddress failed, le = " << GetLastError() << endl;
            return 1;
        }//if
    
        dm(0);
    
        FreeLibrary(hmod);
        return 0;
    }//main
    gg

  2. #32
    Registered User JustMax's Avatar
    Join Date
    Jan 2009
    Posts
    59

    Thumbs up

    I don't know who you are but you're my hero!!!

    Thank you soooo much.

    I think the main problem was that I was calling it from a Win32 Project instead of a console project in VS.

    Thank you for all the time you put into this.

  3. #33
    Registered User JustMax's Avatar
    Join Date
    Jan 2009
    Posts
    59
    One more question:
    How can I change the edit control to a richtext control?

    I tried just deleting the edit control and adding the richtext control, but it went back to not displaying my dialog.

  4. #34
    Registered User JustMax's Avatar
    Join Date
    Jan 2009
    Posts
    59
    I got it, I forgot to load the richedd.dll.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  2. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  3. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 12:34 PM
  4. .lib vs .h vs .dll
    By Shadow12345 in forum C++ Programming
    Replies: 13
    Last Post: 01-01-2003, 05:29 AM
  5. Putting a DialogBox into a DLL?
    By xds4lx in forum Windows Programming
    Replies: 1
    Last Post: 11-17-2002, 12:59 AM