Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Win32 (http://www.go4expert.com/forums/win32/)
-   -   Problem creating MFC application via dll (http://www.go4expert.com/forums/creating-mfc-application-via-dll-t4705/)

Hayden 15Jun2007 13:37

Problem creating MFC application via dll
 
1 Attachment(s)
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.

shabbir 15Jun2007 15:17

Re: Problem creating MFC application via dll
 
Search the forum and its there with the title creating a simple Dll.

Hayden 18Jun2007 07:51

Re: Problem creating MFC application via dll
 
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.

shabbir 18Jun2007 08:24

Re: Problem creating MFC application via dll
 
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.

Hayden 18Jun2007 09:19

Re: Problem creating MFC application via dll
 
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.

shabbir 18Jun2007 09:29

Re: Problem creating MFC application via dll
 
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 Seperate resource into a seperate DLL.

Hayden 18Jun2007 11:52

Re: Problem creating MFC application via dll
 
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);
}

Hayden 18Jun2007 12:47

Re: Problem creating MFC application via dll
 
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!!!

shabbir 18Jun2007 15:11

Re: Problem creating MFC application via dll
 
DialogBox in a very novice language is a Win32 version of DoModal and you can even use DoModal if you wish to.

Hayden 19Jun2007 04:58

Re: Problem creating MFC application via dll
 
Hi Shabbir,

do you mean do the following code

Code:

extern "C" __declspec(dllexport) void CreateLkApp()
{
        CSepResSampleAppDlg Dlg;
        m_pMainWnd = &Dlg;
        Dlg.DoModal();

}

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?


All times are GMT +5.5. The time now is 08:48.