Problem with MessageBox
-
I have written a simple program that imports a DLL at compile time, and then displays a message box (MessageBox()) containing data from the imported DLL. The problem is that the data gets imported, but the message box doesn't get displayed, returning code 1407 'Cannot find window class'. But when I don't import the DLL, the message box displays fine. Anyone have any ideas?:)
-
I have written a simple program that imports a DLL at compile time, and then displays a message box (MessageBox()) containing data from the imported DLL. The problem is that the data gets imported, but the message box doesn't get displayed, returning code 1407 'Cannot find window class'. But when I don't import the DLL, the message box displays fine. Anyone have any ideas?:)
What kinda dll is it ?
"When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)
-
What kinda dll is it ?
"When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)
Its an implicitly loaded DLL. The DLL code is as follows (NB its not my code, I got it out of a book):
/*Module: MyLibFile1.cpp*/ #include <windows.h> #define MYLIBAPI extern "C" __declspec(dllexport) #include "MyLibFile.h" int g_nResult; int Add(int nLeft, int nRight) { g_nResult = nLeft + nRight; return(g_nResult); }
The header file is:/*Module: MyLib.h*/ #ifndef MYLIBAPI #define MYLIBAPI extern "C" __declspec(dllimport) #endif MYLIBAPI int g_nResult; MYLIBAPI int Add(int nLeft, int nRight);
And the main code that includes the MessageBox() is as follows:/*Module: MyExeFile1.cpp*/ #include <windows.h> #include "..\MyLibFile\MyLibFile.h" int WINAPI WinMain(HINSTANCE hinstExe, HINSTANCE, LPTSTR pszCmdLine, int) { int nLeft = 10, nRight = 25; TCHAR sz[100]; wsprintf(sz, TEXT("%d + %d = %d"), nLeft, nRight, Add(nLeft, nRight)); MessageBox(GetActiveWindow(), sz, TEXT("Calculation"), MB_OK); DWORD Error = GetLastError(); wsprintf(sz, TEXT("The result from the last Add is: %d"), g_nResult); MessageBox(NULL, sz, TEXT("Last Result"), MB_OK); return(0); }
:) -
Its an implicitly loaded DLL. The DLL code is as follows (NB its not my code, I got it out of a book):
/*Module: MyLibFile1.cpp*/ #include <windows.h> #define MYLIBAPI extern "C" __declspec(dllexport) #include "MyLibFile.h" int g_nResult; int Add(int nLeft, int nRight) { g_nResult = nLeft + nRight; return(g_nResult); }
The header file is:/*Module: MyLib.h*/ #ifndef MYLIBAPI #define MYLIBAPI extern "C" __declspec(dllimport) #endif MYLIBAPI int g_nResult; MYLIBAPI int Add(int nLeft, int nRight);
And the main code that includes the MessageBox() is as follows:/*Module: MyExeFile1.cpp*/ #include <windows.h> #include "..\MyLibFile\MyLibFile.h" int WINAPI WinMain(HINSTANCE hinstExe, HINSTANCE, LPTSTR pszCmdLine, int) { int nLeft = 10, nRight = 25; TCHAR sz[100]; wsprintf(sz, TEXT("%d + %d = %d"), nLeft, nRight, Add(nLeft, nRight)); MessageBox(GetActiveWindow(), sz, TEXT("Calculation"), MB_OK); DWORD Error = GetLastError(); wsprintf(sz, TEXT("The result from the last Add is: %d"), g_nResult); MessageBox(NULL, sz, TEXT("Last Result"), MB_OK); return(0); }
:) -
Its an implicitly loaded DLL. The DLL code is as follows (NB its not my code, I got it out of a book):
/*Module: MyLibFile1.cpp*/ #include <windows.h> #define MYLIBAPI extern "C" __declspec(dllexport) #include "MyLibFile.h" int g_nResult; int Add(int nLeft, int nRight) { g_nResult = nLeft + nRight; return(g_nResult); }
The header file is:/*Module: MyLib.h*/ #ifndef MYLIBAPI #define MYLIBAPI extern "C" __declspec(dllimport) #endif MYLIBAPI int g_nResult; MYLIBAPI int Add(int nLeft, int nRight);
And the main code that includes the MessageBox() is as follows:/*Module: MyExeFile1.cpp*/ #include <windows.h> #include "..\MyLibFile\MyLibFile.h" int WINAPI WinMain(HINSTANCE hinstExe, HINSTANCE, LPTSTR pszCmdLine, int) { int nLeft = 10, nRight = 25; TCHAR sz[100]; wsprintf(sz, TEXT("%d + %d = %d"), nLeft, nRight, Add(nLeft, nRight)); MessageBox(GetActiveWindow(), sz, TEXT("Calculation"), MB_OK); DWORD Error = GetLastError(); wsprintf(sz, TEXT("The result from the last Add is: %d"), g_nResult); MessageBox(NULL, sz, TEXT("Last Result"), MB_OK); return(0); }
:)JGStanier wrote: MessageBox(GetActiveWindow(), sz, TEXT("Calculation"), MB_OK); Which window??? should it not be NULL like the second messagebox?
"When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)
-
JGStanier wrote: MessageBox(GetActiveWindow(), sz, TEXT("Calculation"), MB_OK); Which window??? should it not be NULL like the second messagebox?
"When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)