|
i have the correct id, i need a small code to show the dialog from reource dll in win32 way
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
If you are using MFC you can create an instance of the dialog class from the DLL. Be sure to use MFC with dynamic linking in both the exe and dll.
The way I did this in my project was:
In the DLL have
class MyDialog : public CDialog {
}
Then an exported function to create and destroy the instance.
Because in C++ the return type and parameters make up the function name, we should use C for exporting functions, however we cannot create classes in C.
Any memory allocated from within a DLL should be deleted from within the DLL too, so we need a create and destroy function
The following will create an instance of the class and return it through a C function and delete it when you are finished with it.
void *InternalGetDialog() {
return new MyDialog();
}
void InternalDeleteDialog(void *pDlg) {
CDialog *pDialog = (CDialog *)pDialog;
delete pDialog;
}
extern "C" {
__declspec(dllexport) void *GetDialog() {
return InternalGetDialog();
}
__declspec(dllexport) void DeleteDialog(void *pDialog) {
InternalDeleteDialog(pDialog);
}
}
Then in the exe that displays the dialog
typedef CDialog *(*GetDialogFunc)();
typedef CDialog *(*DeleteDialogFunc)();
void DisplayDynamicDialog() {
HMODULE hModule = LoadLibrary("Resources.dll");
if (hModule != NULL) {
GetDialogFunc pGetDialogFunc = (GetDialogFunc)GetProcAddress(hModule, "GetDialog");
DeleteDialogFunc pDeleteDialogFunc = (DeleteDialogFunc)GetProcAddress(hModule, "DeleteDialog");
CDialog *pDialog = pGetDialogFunc();
INT_PTR nRes = pDialog->DoModal();
pDeleteDialogFunc(pDialog);
FreeLibrary(hModule);
}
}
|
|
|
|
|
thanx 4 ur reply with sample but i need the sample in win32 way, my program don't use MFC.
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
Firstly you need a message handler, essentialy the same as your main message handler, usually WndProc
BOOL CALLBACK DlgProc(HWND hDlg, UINT nMessage, WPARAM wParam, LPARAM lParam) {
switch (nMessage) {
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
return TRUE;
case IDCANCEL:
DestroyWindow(hDlg);
return TRUE;
}
break;
}
}
return FALSE;
}
Then you just need to use that as the "procedure function"
void DisplayDynamicDialog(HWND hParent) {
HMODULE hModule = LoadLibrary("Resources.dll");
if(hModule != NULL) {
hDialog = CreateDialog(hModule, MAKEINTRESOURCE(ID_DIALOG), hParent, (DLGPROC)DlgProc);
ShowWindow(hDialog, SW_SHOW);
FreeLibrary(hModule);
}
}
Finally, just to reiterate what Thaddeus Jones said, the ID you supply needs to be the ID defined in the DLL, not the ID defined in the exe, hence the resource.h that you include needs to be from the dll. To avoid confusion, I recommend using quoted string names instead.
|
|
|
|
|
thanks a lot, worked like a charm, once again thanx.
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
|
Firstly your call to CreateDialog() is incomplete, so this code will not even compile. Secondly are you sure you are making the right call (i.e. is this a Modal or Modeless dialog)?
Take a look here[^] for some more information.
I must get a clever new signature for 2011.
|
|
|
|
|
i know it is incomplete, therefore i m in need of a sample in win32 way.
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
OK so what part of this[^] are you having trouble with?
I must get a clever new signature for 2011.
|
|
|
|
|
sir i had received the answer, thanx for giving ur valuable time sir.
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
Hi all,
Can any body help me how to use the VC++ activex control
in linux Gui (QT) applications?
|
|
|
|
|
You cannot do that.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
activeX and linux?
|
|
|
|
|
HI,
Does anyone know of any free tools or Visual Studio add-in that will check the source files in a project for unused variables and/or functions?
Tony
|
|
|
|
|
Set the compiler warning level to 4.
Watched code never compiles.
|
|
|
|
|
AFAIK that works well for local variables, but not for class level variables or methods.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I still don't understand why people write unused code!!
Watched code never compiles.
|
|
|
|
|
Don't blame the programmers. Blame the users, they tend to avoid those pieces of an app that contain most of the bugs.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
can't you compile with warning Level 4 in Project->Properties->C/C++->General->Warning Level -> Level 4 (/W4) ?
|
|
|
|
|
Thanks for the reply.
Yea, I have used warning level 4 to identify any unused local variables but I was thinking of something on a bigger scale i.e. something that would identify class members and methods which are not referenced in the project.
Of couse I could right click every method in the class view and show where it is called but that could drive a man insane!
Thanks again for the reply.
|
|
|
|
|
Check Doxygen. It has been very long since I used it, but it may help dig out something. I know there is something with unused function, but not sure for unused variables.
I could be way off the mark, it has been very long since I used it.
|
|
|
|
|
One biggest problem of the most article from here , is that is not tested on static and dynamic mode : here [^] I use this control , of type CCheckComboBox , on CFormView form .... but when I try to use it into an dialog bar , I broke down ... how can I do that ? How can I put into dialog bar the member variable type of CCheckComboBox ?
|
|
|
|
|
I'm pretty sure the article's author would consider precious your comments, just post them in the article's own thread.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
People are not only thankless but also so unforgiving of the mistakes committed even by a baby.
|
|
|
|