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. dll from win32 console.

dll from win32 console.

Scheduled Pinned Locked Moved C / C++ / MFC
c++debugginghelp
40 Posts 5 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.
  • A appollosputnik

    How can I get the handle from the client console and pass it to the lpfnGetProcessID .... to runAppli....With the code below I am getting run-time error. that hwnd being used without being intialized.. Please tell me how can I initialize hwnd. Thanks Sujan int main(int argc, char **argv) { HWND hwnd; /* get handle to dll */ HMODULE hDll = LoadLibrary(TEXT("C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll")); typedef BOOL (* ICFUNC)(HWND, LPCSTR); ICFUNC lpfnGetProcessID = (ICFUNC)GetProcAddress(hDll, "runAppli"); ///* The actual call to the function contained in the dll */ BOOL intMyReturnVal = lpfnGetProcessID(hwnd, "runAppli"); /* Release the Dll */ FreeLibrary(hDll); return 0; }

    S Offline
    S Offline
    Stephen Hewitt
    wrote on last edited by
    #17

    You're not explaining yourself very clearly but it sounds like you might be after the GetConsoleWindow function.

    Steve

    A 2 Replies Last reply
    0
    • S Stephen Hewitt

      You're not explaining yourself very clearly but it sounds like you might be after the GetConsoleWindow function.

      Steve

      A Offline
      A Offline
      appollosputnik
      wrote on last edited by
      #18

      extern "C" BOOL __declspec(dllexport) runAppli(HWND hwnd, LPCSTR lpAppName) { // Only needed if resources are accessed //AFX_MANAGE_STATE(AfxGetStaticModuleState()); ::ShowWindow(hwnd, SW_SHOW); UNREFERENCED_PARAMETER(lpAppName); return true; } So I need to pass hwnd to this function right..? Is it necessary to launch my dll application. I just want to launch the application.

      S 1 Reply Last reply
      0
      • A appollosputnik

        extern "C" BOOL __declspec(dllexport) runAppli(HWND hwnd, LPCSTR lpAppName) { // Only needed if resources are accessed //AFX_MANAGE_STATE(AfxGetStaticModuleState()); ::ShowWindow(hwnd, SW_SHOW); UNREFERENCED_PARAMETER(lpAppName); return true; } So I need to pass hwnd to this function right..? Is it necessary to launch my dll application. I just want to launch the application.

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #19

        Why don't you explain exactly what you are trying to do?

        Steve

        A 2 Replies Last reply
        0
        • S Stephen Hewitt

          You're not explaining yourself very clearly but it sounds like you might be after the GetConsoleWindow function.

          Steve

          A Offline
          A Offline
          appollosputnik
          wrote on last edited by
          #20

          I have made some changes in the code let me know whats wrong in this my application is not launching. int main(int argc, char **argv) { HWND hWnd=NULL; /* get handle to dll */ HMODULE hDll = LoadLibrary(TEXT("C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll")); typedef BOOL (* ICFUNC)(LPCSTR); ICFUNC lpfnGetProcessID = (ICFUNC)GetProcAddress(hDll, "runAppli"); ///* The actual call to the function contained in the dll */ BOOL intMyReturnVal = lpfnGetProcessID("runAppli"); /* Release the Dll */ FreeLibrary(hDll); return 0; } //////////////////////////////////////////////////////////////////////////////////////////////////// extern "C" BOOL __declspec(dllexport) runAppli(LPCSTR lpAppName) { // Only needed if resources are accessed //AFX_MANAGE_STATE(AfxGetStaticModuleState()); ::ShowWindow( AfxGetMainWnd()->GetSafeHwnd(), SW_SHOW); UNREFERENCED_PARAMETER(lpAppName); return true; }

          L 1 Reply Last reply
          0
          • S Stephen Hewitt

            Why don't you explain exactly what you are trying to do?

            Steve

            A Offline
            A Offline
            appollosputnik
            wrote on last edited by
            #21

            I want to launch my dll application from win32 client exe.......Can u help me whats need be done Thanks for your help.

            1 Reply Last reply
            0
            • S Stephen Hewitt

              Why don't you explain exactly what you are trying to do?

              Steve

              A Offline
              A Offline
              appollosputnik
              wrote on last edited by
              #22

              I want to show the mainwindow of the dll application from win32 client. I am able to load the dll but I am confused what need to be done after that to show the mainwindow. Please help Stephen. Thanks Sujan

              S 1 Reply Last reply
              0
              • A appollosputnik

                I have made some changes in the code let me know whats wrong in this my application is not launching. int main(int argc, char **argv) { HWND hWnd=NULL; /* get handle to dll */ HMODULE hDll = LoadLibrary(TEXT("C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll")); typedef BOOL (* ICFUNC)(LPCSTR); ICFUNC lpfnGetProcessID = (ICFUNC)GetProcAddress(hDll, "runAppli"); ///* The actual call to the function contained in the dll */ BOOL intMyReturnVal = lpfnGetProcessID("runAppli"); /* Release the Dll */ FreeLibrary(hDll); return 0; } //////////////////////////////////////////////////////////////////////////////////////////////////// extern "C" BOOL __declspec(dllexport) runAppli(LPCSTR lpAppName) { // Only needed if resources are accessed //AFX_MANAGE_STATE(AfxGetStaticModuleState()); ::ShowWindow( AfxGetMainWnd()->GetSafeHwnd(), SW_SHOW); UNREFERENCED_PARAMETER(lpAppName); return true; }

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #23

                Please put <pre> tags around your code as requested, so it is clearly readable As to your code, this shows that you really do not understand how to create a Windows application. You are getting the address of the runAppli() function and then calling it with "runAppli" as its input parameter, which is declared as UNREFERENCED_PARAMETER and hence has no purpose. The runAppli function itself is trying to show a window which does not exist, and using an MFC call even though the MFC environment has not been initialised. The net result is that the function will fail but will not give you any indication of why because you do not check for errors. This program will never work however much you play with it. I would suggest you use the wizard in your Visual Studio IDE to create a proper Windows/MFC program, and examine the source and read the documentation to understand how the various pieces fit together.

                Unrequited desire is character building. OriginalGriff

                1 Reply Last reply
                0
                • A appollosputnik

                  I want to show the mainwindow of the dll application from win32 client. I am able to load the dll but I am confused what need to be done after that to show the mainwindow. Please help Stephen. Thanks Sujan

                  S Offline
                  S Offline
                  Stephen Hewitt
                  wrote on last edited by
                  #24

                  Firstly note that a dll and the code that loads it are in the same application; I'm starting to get the impression that you may not be aware of this. Also, maybe you should use static linking.

                  Steve

                  1 Reply Last reply
                  0
                  • S Stephen Hewitt

                    Why are you passing a HMODULE when a HWND is expected?

                    sujandasmahapatra wrote:

                    BOOL intMyReturnVal = lpfnGetProcessID(hDll, "runAppli");

                    sujandasmahapatra wrote:

                    extern "C" BOOL __declspec(dllexport) runAppli(HWND hwnd, LPCSTR lpAppName)

                    Steve

                    A Offline
                    A Offline
                    appollosputnik
                    wrote on last edited by
                    #25

                    Look Friends Now I am not calling the dll from not winn32 but from another mfc exe application. Where I have a button when I press it I should load the dll and launch the mainwindow. See my two apis void CClientRevProjDlg::OnBnClickedButton1() { typedef VOID (*MYPROC)(HWND); HINSTANCE hinstLib; MYPROC ProcAdd; BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; HWND h = AfxGetMainWnd()->GetSafeHwnd(); // Get a handle to the DLL module. hinstLib = LoadLibrary(L"C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll"); // If the handle is valid, try to get the function address. if (hinstLib != NULL) { ProcAdd = (MYPROC) GetProcAddress(hinstLib, "runAppli"); // Do add operation // If the function address is valid, call the function. if (fRunTimeLinkSuccess = (ProcAdd != NULL)) (ProcAdd) (h); // Free the DLL module. fFreeResult = FreeLibrary(hinstLib); } // If unable to call the DLL function, use an alternative. if (! fRunTimeLinkSuccess) printf("message via alternative method\n"); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //And in the dll App.cpp I have an extern "C" like this.... extern "C" BOOL __declspec(dllexport) runAppli(HWND h) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // HWND h = AfxGetMainWnd()->GetSafeHwnd(); ShowWindow(h,SW_SHOW); return true; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// With this when I press the run button from client exe, my dll mainwindow is shown but crashing and hanging for sometime. Please help me get rid of this problem someone Thanks a lot. :)

                    L 1 Reply Last reply
                    0
                    • A appollosputnik

                      Look Friends Now I am not calling the dll from not winn32 but from another mfc exe application. Where I have a button when I press it I should load the dll and launch the mainwindow. See my two apis void CClientRevProjDlg::OnBnClickedButton1() { typedef VOID (*MYPROC)(HWND); HINSTANCE hinstLib; MYPROC ProcAdd; BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; HWND h = AfxGetMainWnd()->GetSafeHwnd(); // Get a handle to the DLL module. hinstLib = LoadLibrary(L"C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll"); // If the handle is valid, try to get the function address. if (hinstLib != NULL) { ProcAdd = (MYPROC) GetProcAddress(hinstLib, "runAppli"); // Do add operation // If the function address is valid, call the function. if (fRunTimeLinkSuccess = (ProcAdd != NULL)) (ProcAdd) (h); // Free the DLL module. fFreeResult = FreeLibrary(hinstLib); } // If unable to call the DLL function, use an alternative. if (! fRunTimeLinkSuccess) printf("message via alternative method\n"); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //And in the dll App.cpp I have an extern "C" like this.... extern "C" BOOL __declspec(dllexport) runAppli(HWND h) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // HWND h = AfxGetMainWnd()->GetSafeHwnd(); ShowWindow(h,SW_SHOW); return true; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// With this when I press the run button from client exe, my dll mainwindow is shown but crashing and hanging for sometime. Please help me get rid of this problem someone Thanks a lot. :)

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #26

                      Once again, please put <pre> tags around your code so we can read it clearly, it is not easy to understand what your code is trying to do without it. As to your code, I still do not understand (and you have not explained) what you are trying to do with this dll; which, incidentally seems to change with every reply you post. Forget everything you have done in the past and try to explain clearly exactly what you are trying to achieve.

                      Unrequited desire is character building. OriginalGriff

                      A 3 Replies Last reply
                      0
                      • L Lost User

                        Once again, please put <pre> tags around your code so we can read it clearly, it is not easy to understand what your code is trying to do without it. As to your code, I still do not understand (and you have not explained) what you are trying to do with this dll; which, incidentally seems to change with every reply you post. Forget everything you have done in the past and try to explain clearly exactly what you are trying to achieve.

                        Unrequited desire is character building. OriginalGriff

                        A Offline
                        A Offline
                        appollosputnik
                        wrote on last edited by
                        #27

                        See Rechard....I have a mfc application which I already converted to a shared dll. This dll has a mainwindow. Now from a client program I want to launch that mainwindow of the dll and work on the application. This is very simple approach and I am sure its feasible in mfc only thing I dont know how. So I am trying get your help. Please help me if you can. Check my last post. I have a shared mfc dll where I have one extern "C" function exported as runAppli there I am only triying to display the mainwindnow. And another mfc client exe from where I am loading the dll and trying to call the runAppli to launch the mainwindow. I dont understand why it seems to be impossible. This is a very simple problem. Please help me if you can. Thanks a lot for your reply. Sujan

                        L 1 Reply Last reply
                        0
                        • L Lost User

                          Once again, please put <pre> tags around your code so we can read it clearly, it is not easy to understand what your code is trying to do without it. As to your code, I still do not understand (and you have not explained) what you are trying to do with this dll; which, incidentally seems to change with every reply you post. Forget everything you have done in the past and try to explain clearly exactly what you are trying to achieve.

                          Unrequited desire is character building. OriginalGriff

                          A Offline
                          A Offline
                          appollosputnik
                          wrote on last edited by
                          #28

                          Dear Richar tag option is not coming . So excuse me this time, next post onwards I'll put tags properly

                          1 Reply Last reply
                          0
                          • A appollosputnik

                            See Rechard....I have a mfc application which I already converted to a shared dll. This dll has a mainwindow. Now from a client program I want to launch that mainwindow of the dll and work on the application. This is very simple approach and I am sure its feasible in mfc only thing I dont know how. So I am trying get your help. Please help me if you can. Check my last post. I have a shared mfc dll where I have one extern "C" function exported as runAppli there I am only triying to display the mainwindnow. And another mfc client exe from where I am loading the dll and trying to call the runAppli to launch the mainwindow. I dont understand why it seems to be impossible. This is a very simple problem. Please help me if you can. Thanks a lot for your reply. Sujan

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #29

                            sujandasmahapatra wrote:

                            I have a mfc application which I already converted to a shared dll.

                            WHY? This is really not a sensible option as you have discovered to your cost. Go back to the original and run the application as an application; trying to make it into a DLL is a pointless exercise and is unlikely ever to work.

                            Unrequited desire is character building. OriginalGriff

                            1 Reply Last reply
                            0
                            • L Lost User

                              Once again, please put <pre> tags around your code so we can read it clearly, it is not easy to understand what your code is trying to do without it. As to your code, I still do not understand (and you have not explained) what you are trying to do with this dll; which, incidentally seems to change with every reply you post. Forget everything you have done in the past and try to explain clearly exactly what you are trying to achieve.

                              Unrequited desire is character building. OriginalGriff

                              A Offline
                              A Offline
                              appollosputnik
                              wrote on last edited by
                              #30

                              Now my code looks like this. My application launching but crashing. [pre] void CClientRevProjDlg::OnBnClickedButton1() { typedef VOID (*MYPROC)(HWND); HINSTANCE hinstLib; MYPROC ProcAdd; BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; HWND h = AfxGetMainWnd()->GetSafeHwnd(); // Get a handle to the DLL module. hinstLib = LoadLibrary(L"C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll"); // If the handle is valid, try to get the function address. if (hinstLib != NULL) { ProcAdd = (MYPROC) GetProcAddress(hinstLib, "runAppli"); // Do add operation // If the function address is valid, call the function. if (fRunTimeLinkSuccess = (ProcAdd != NULL)) (ProcAdd) (h); // Free the DLL module. fFreeResult = FreeLibrary(hinstLib); } // If unable to call the DLL function, use an alternative. if (! fRunTimeLinkSuccess) printf("message via alternative method\n"); } [/pre] ///////////////////////////////////////////////////////////////////////////////////// And runAppli like this... [code]

                              extern "C" BOOL __declspec(dllexport) runAppli(HWND h)
                              {
                              AFX_MANAGE_STATE(AfxGetStaticModuleState());
                              // HWND h = AfxGetMainWnd()->GetSafeHwnd();
                              ShowWindow(h,SW_SHOW);
                              return true;
                              }

                              [/code]

                              L 1 Reply Last reply
                              0
                              • A appollosputnik

                                Now my code looks like this. My application launching but crashing. [pre] void CClientRevProjDlg::OnBnClickedButton1() { typedef VOID (*MYPROC)(HWND); HINSTANCE hinstLib; MYPROC ProcAdd; BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; HWND h = AfxGetMainWnd()->GetSafeHwnd(); // Get a handle to the DLL module. hinstLib = LoadLibrary(L"C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll"); // If the handle is valid, try to get the function address. if (hinstLib != NULL) { ProcAdd = (MYPROC) GetProcAddress(hinstLib, "runAppli"); // Do add operation // If the function address is valid, call the function. if (fRunTimeLinkSuccess = (ProcAdd != NULL)) (ProcAdd) (h); // Free the DLL module. fFreeResult = FreeLibrary(hinstLib); } // If unable to call the DLL function, use an alternative. if (! fRunTimeLinkSuccess) printf("message via alternative method\n"); } [/pre] ///////////////////////////////////////////////////////////////////////////////////// And runAppli like this... [code]

                                extern "C" BOOL __declspec(dllexport) runAppli(HWND h)
                                {
                                AFX_MANAGE_STATE(AfxGetStaticModuleState());
                                // HWND h = AfxGetMainWnd()->GetSafeHwnd();
                                ShowWindow(h,SW_SHOW);
                                return true;
                                }

                                [/code]

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #31

                                1. You still have not properly used <pre> tags around your code as requested. 2. You are really wasting your time with this; as I said before forget using this DLL as it serves no purpose. Create an application as an application and do things the right way.

                                Unrequited desire is character building. OriginalGriff

                                A 2 Replies Last reply
                                0
                                • L Lost User

                                  1. You still have not properly used <pre> tags around your code as requested. 2. You are really wasting your time with this; as I said before forget using this DLL as it serves no purpose. Create an application as an application and do things the right way.

                                  Unrequited desire is character building. OriginalGriff

                                  A Offline
                                  A Offline
                                  appollosputnik
                                  wrote on last edited by
                                  #32

                                  :) I need this dll to work Richard. Its very important......My application should be served as a dll. And my mainwindow should appear.

                                  L 1 Reply Last reply
                                  0
                                  • A appollosputnik

                                    :) I need this dll to work Richard. Its very important......My application should be served as a dll. And my mainwindow should appear.

                                    L Offline
                                    L Offline
                                    Lost User
                                    wrote on last edited by
                                    #33

                                    Why do you persist with this? This is totally contrary to the design of Windows applications. Putting all this code into a DLL is just going to cause you problems and, as I have said repeatedly, serves absolutely no purpose. Perhpas if you actually explained what problem you are trying to resolve someone can advise you of a potential solution, but just insisting that you need this as a DLL makes no sense.

                                    Unrequited desire is character building. OriginalGriff

                                    A 1 Reply Last reply
                                    0
                                    • L Lost User

                                      1. You still have not properly used <pre> tags around your code as requested. 2. You are really wasting your time with this; as I said before forget using this DLL as it serves no purpose. Create an application as an application and do things the right way.

                                      Unrequited desire is character building. OriginalGriff

                                      A Offline
                                      A Offline
                                      appollosputnik
                                      wrote on last edited by
                                      #34

                                      window handle is creaeing all the problem check this I am trying to get the handle like this [code] HWND h = this->m_hWnd; [/code] from the dialog class.....This is giving problem.....PLease tell me how can I get the window handle from dialog class. HWND handle. If I get the correct handle then it'll launch the application. Thanks Sujan

                                      L G 2 Replies Last reply
                                      0
                                      • L Lost User

                                        Why do you persist with this? This is totally contrary to the design of Windows applications. Putting all this code into a DLL is just going to cause you problems and, as I have said repeatedly, serves absolutely no purpose. Perhpas if you actually explained what problem you are trying to resolve someone can advise you of a potential solution, but just insisting that you need this as a DLL makes no sense.

                                        Unrequited desire is character building. OriginalGriff

                                        A Offline
                                        A Offline
                                        appollosputnik
                                        wrote on last edited by
                                        #35

                                        Problem I have explained earlier also. I have built one application in mfc...Now I want to launch that application from another aplication. so I want to make the first application as dll and try to laucnh that application from my 2nd application. Howelse would that be achieved except dll. ??? you tell me. Thanks Sujan

                                        L 1 Reply Last reply
                                        0
                                        • A appollosputnik

                                          window handle is creaeing all the problem check this I am trying to get the handle like this [code] HWND h = this->m_hWnd; [/code] from the dialog class.....This is giving problem.....PLease tell me how can I get the window handle from dialog class. HWND handle. If I get the correct handle then it'll launch the application. Thanks Sujan

                                          L Offline
                                          L Offline
                                          Lost User
                                          wrote on last edited by
                                          #36

                                          Sorry, but I don't understand what you are saying. The last few messages you were trying to launch an MFC application held inside a DLL, and now you seem to be doing something else that does not make sense. Where does this dialog fit in to what you have been talking about? And you still have not figured out how to add <pre> tags around your code!

                                          Unrequited desire is character building. OriginalGriff

                                          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