Problem creating MFC application via dll

Discussion in 'Win32' started by Hayden, Jun 15, 2007.

  1. Hayden

    Hayden New Member

    Joined:
    Jun 15, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Support and Development
    Location:
    Australia
    Hi,

    I am fairly new to C++ and DLLs, not sure even if this will work, if someone can give me some pointers or maybe somewhere I could find some similar examples I would greatly appreciate it.

    I would like to build a MFC Win32 based DLL that only has one external function.

    extern "C" __declspec(dllexport) void CreateLkApp(){.........}

    that piece is fine. The next piece is where I'm having trouble. I'd like this function to call/create an application class which in turn creates a dialog box. All within the same dll.

    Is this possible? I have attached my zipped up project which only works up until a point, but may make it a bit clearer what I want to achieve. Basically a dialog application built inside the dll.
     

    Attached Files:

  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Search the forum and its there with the title creating a simple Dll.
     
  3. Hayden

    Hayden New Member

    Joined:
    Jun 15, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Support and Development
    Location:
    Australia
    Hi Shabbir,

    that was a good simple starter dll, however I'm fine with creating and calling a dll. The thing I'm after is getting a little more complex. That I've got an application that Calls this following simple function. This function I'm wanting to create a dialog box.

    Basically an application that calls a DLL function that creates an application of its own. If you have a look at the project I've supplied it might make more sense.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    If you try to explain more than just attaching your complete solution it becomes easier. At least I would expect not to download and know what you are upto.
     
  5. Hayden

    Hayden New Member

    Joined:
    Jun 15, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Support and Development
    Location:
    Australia
    Alright, I've got an application (lets call it 'BizApp') with a language that cannot build multi column lists with checkboxes etc. The language is MapBasic(propriatary) and is based on VB.

    I'm trying to create a dialog based program that will update various databases, (Lets call it 'TableUpdate') that requires a multi column list with checkboxes. A C++ application will allow me more flexibility as far as an interface goes.

    I thought about creating 'TableUpdate' with a plain old EXE but this would allow people to continue to use the 'BizApp' application while 'TableUpdate' is still running. I.e. it won't be in Modal. Unless there's a way to force it??? This will be important as I don't want locking issues if I can help it.
    If I create a DLL that's able to produce this dialog based interface then 'BizApp' would basically be stuck waiting for the process with my dialog to finish.

    So I'm trying to create a DLL that will create an interface. Is this possible? If not have you any other solutions.
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    This is very much possible. Have a Dll that will have the resource which will have your complete dialog resource. Now Have a function in the Dll that will launch that dialog using the DialogBox Function and that will make the things modal.

    If you are unsure about creating a Dialog resource in the Dll see [thread=937] Seperate resource into a seperate DLL[/thread].
     
  7. Hayden

    Hayden New Member

    Joined:
    Jun 15, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Support and Development
    Location:
    Australia
    Hi Shabbir, with the example I've tried changing the main DLL CPP file to the following, however have never used the DialogBox function and have just used the past hour trying to figure out how to use it, some help on this one would be greatly appreciated!!!

    // SepResSampleDll.cpp : Defines the entry point for the DLL application.
    //

    #include "stdafx.h"

    BOOL APIENTRY DllMain( HANDLE hModule,
    DWORD ul_reason_for_call,
    LPVOID lpReserved
    )
    {
    return TRUE;
    }

    extern "C" __declspec(dllexport) void CreateLkApp()
    {
    static HINSTANCE hInstance;
    static HWND hwnd;

    DialogBox(hInstance,text("DLG"),hwnd,DlgProc);
    }
     
  8. Hayden

    Hayden New Member

    Joined:
    Jun 15, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Support and Development
    Location:
    Australia
    Further to my post above.

    hInstance is the handle to the module, is this SepResSampleAppDlg?
    hInstance = SepResSampleAppDlg;

    the second parameter, this is just a string to identify the dialog later?

    hwnd is the parent application window id, really not sure how to go about getting this??

    The DlgProc parameter is just as confusing!!!
     
  9. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    DialogBox in a very novice language is a Win32 version of DoModal and you can even use DoModal if you wish to.
     
  10. Hayden

    Hayden New Member

    Joined:
    Jun 15, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Support and Development
    Location:
    Australia
    Hi Shabbir,

    do you mean do the following code

    Code:
    [COLOR=Navy]extern "C" __declspec(dllexport) void CreateLkApp()
    {
    	CSepResSampleAppDlg Dlg;
    	m_pMainWnd = &Dlg;
    	Dlg.DoModal();
    
    }[/COLOR]
    Then I'm guessing you just need to #include the Application and Dialog header files in SepResSampleDll.cpp.

    Actually that didn't work, what else could I have missed?
     
    Last edited by a moderator: Jun 19, 2007
  11. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Yup you are missing one important point in the first sample I have told you to see. I will clarify some more points here.

    Download the sample from [thread=907]Creating a simple DLL[/thread].
    Now have the Dll project to have the necessary resource to show the dialog.
    Then have the necessary classes for the Dialog.
    The create the object of the class and class and call its DoModal.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice