Problem creating MFC application via dll

Hayden's Avatar, Join Date: Jun 2007
Light Poster
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
File Type: zip BizAppLk.zip (42.1 KB, 15 views)
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Search the forum and its there with the title creating a simple Dll.
Hayden's Avatar, Join Date: Jun 2007
Light Poster
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's Avatar, Join Date: Jul 2004
Go4Expert Founder
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's Avatar, Join Date: Jun 2007
Light Poster
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's Avatar, Join Date: Jul 2004
Go4Expert Founder
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's Avatar, Join Date: Jun 2007
Light Poster
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's Avatar, Join Date: Jun 2007
Light Poster
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's Avatar, Join Date: Jul 2004
Go4Expert Founder
DialogBox in a very novice language is a Win32 version of DoModal and you can even use DoModal if you wish to.
Hayden's Avatar, Join Date: Jun 2007
Light Poster
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?

Last edited by shabbir; 19Jun2007 at 08:54.. Reason: Code block - http://www.go4expert.com/forums/misc.php?do=bbcode#code