Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with MessageBox

Problem with MessageBox

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JGStanier
    wrote on last edited by
    #1

    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?:)

    P 1 Reply Last reply
    0
    • J JGStanier

      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?:)

      P Offline
      P Offline
      Prakash Nadar
      wrote on last edited by
      #2

      What kinda dll is it ?


      "When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)

      J 1 Reply Last reply
      0
      • P Prakash Nadar

        What kinda dll is it ?


        "When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)

        J Offline
        J Offline
        JGStanier
        wrote on last edited by
        #3

        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); }
        :)

        J P 2 Replies Last reply
        0
        • J JGStanier

          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); }
          :)

          J Offline
          J Offline
          JGStanier
          wrote on last edited by
          #4

          Oops, '/*Module: MyLib.h*/' should read '/*Module: MyLibFile.h*/':)

          S 1 Reply Last reply
          0
          • J JGStanier

            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); }
            :)

            P Offline
            P Offline
            Prakash Nadar
            wrote on last edited by
            #5

            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)

            J 1 Reply Last reply
            0
            • P Prakash Nadar

              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)

              J Offline
              J Offline
              JGStanier
              wrote on last edited by
              #6

              Yes, sorry, I was trying something and forgot to replace it with NULL.:-O Still get an error message saying it can't find the window class though. I guess it isn't linking the windows.h file.

              1 Reply Last reply
              0
              • J JGStanier

                Oops, '/*Module: MyLib.h*/' should read '/*Module: MyLibFile.h*/':)

                S Offline
                S Offline
                Selvam R
                wrote on last edited by
                #7

                Hi, Did you get ? With Regards, R.Selvam

                J 1 Reply Last reply
                0
                • S Selvam R

                  Hi, Did you get ? With Regards, R.Selvam

                  J Offline
                  J Offline
                  JGStanier
                  wrote on last edited by
                  #8

                  No, when I run it I get nothing, just a 1407 error message, and then the program terminates.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups