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. How can a DLL execute a function of the main app?

How can a DLL execute a function of the main app?

Scheduled Pinned Locked Moved C / C++ / MFC
question
12 Posts 5 Posters 1 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.
  • P peterchen

    write 0xAD to port 0x64 oh wait... pass a pointer to the function to the DLL. I know of no "reverse export" mechanism.


    we are here to help each other get through this thing, whatever it is Vonnegut jr.
    boost your code || Fold With Us! || sighist | doxygen

    D Offline
    D Offline
    Dominik Reichl
    wrote on last edited by
    #3

    So it's impossible? Isn't there some possibility of generating a .lib file of main app or something like that? How can I write a plugin architecture then? The DLL must be somehow be able to execute class functions of the main app...


    _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

    J 1 Reply Last reply
    0
    • D Dominik Reichl

      So it's impossible? Isn't there some possibility of generating a .lib file of main app or something like that? How can I write a plugin architecture then? The DLL must be somehow be able to execute class functions of the main app...


      _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

      J Offline
      J Offline
      John R Shaw
      wrote on last edited by
      #4

      Wooo! It is more than possible! The person who has the information at the tip of his tong is just not online. If we have not done anything like that in a while, then we have to try to remember enough to figure it out (if we have the time to go through the trouble). There are articles at CP on plugins, DLLs and COMM (also in the MSDN Library). When I first read your post (ealier today) the first thing I thought about was callback functions, but that was not what you where asking about. If you can pass a callback function you can pass a class pointer. Heck we pass class pointers and references to DLLs all the time, otherwise we could not use MFC. Your question is resonable and someone may yet answer it. I am no expert on DLLs, so I did not try to figure out what the problem was. INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen

      D 1 Reply Last reply
      0
      • J John R Shaw

        Wooo! It is more than possible! The person who has the information at the tip of his tong is just not online. If we have not done anything like that in a while, then we have to try to remember enough to figure it out (if we have the time to go through the trouble). There are articles at CP on plugins, DLLs and COMM (also in the MSDN Library). When I first read your post (ealier today) the first thing I thought about was callback functions, but that was not what you where asking about. If you can pass a callback function you can pass a class pointer. Heck we pass class pointers and references to DLLs all the time, otherwise we could not use MFC. Your question is resonable and someone may yet answer it. I am no expert on DLLs, so I did not try to figure out what the problem was. INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen

        D Offline
        D Offline
        Dominik Reichl
        wrote on last edited by
        #5

        The person who has the information at the tip of his tong is just not online. Let's hope he'll get online soon :) There are articles at CP on plugins, DLLs and COMM (also in the MSDN Library). I've read most of them, but actually many of them are for C# only and the others for C++ never have the problem that the DLL wants to call something that is in the EXE. They'll just describe how to load and call a DLL, the DLL then does many things, like creating new windows, sending windows messages, etc. but never calls something of the EXE... Thanks and best regards, Dominik


        _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

        N 1 Reply Last reply
        0
        • D Dominik Reichl

          The person who has the information at the tip of his tong is just not online. Let's hope he'll get online soon :) There are articles at CP on plugins, DLLs and COMM (also in the MSDN Library). I've read most of them, but actually many of them are for C# only and the others for C++ never have the problem that the DLL wants to call something that is in the EXE. They'll just describe how to load and call a DLL, the DLL then does many things, like creating new windows, sending windows messages, etc. but never calls something of the EXE... Thanks and best regards, Dominik


          _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

          N Offline
          N Offline
          Neville Franks
          wrote on last edited by
          #6

          I have looked into this quite some time back and I'm afraid I can't remember what the outcome was, but I vaguely recall it was possible. You need to create a lib for the .exe and use that in the DLL. Also declare the functions as exported. One issue that comes to mind though is DLL's are (can be) shared by .EXE's so which EXE would the exported function be in. I guess this info lives in the export information. Another way to do this is for the .EXE to expose an array of functions DLL's can call. You could do this with delegates and probably signals and slots. Have a look at the truly excellent FastDelegate here on CP. In my programmers editor (see sig) I enabled interpreted C functions to call C/C++ functions in my .EXE. This is done by my C compiler resolving function addresses via. the .EXE's MAP file. This works very well and allows extensions to the editor to do most anything that the .exe can. Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"

          D 1 Reply Last reply
          0
          • N Neville Franks

            I have looked into this quite some time back and I'm afraid I can't remember what the outcome was, but I vaguely recall it was possible. You need to create a lib for the .exe and use that in the DLL. Also declare the functions as exported. One issue that comes to mind though is DLL's are (can be) shared by .EXE's so which EXE would the exported function be in. I guess this info lives in the export information. Another way to do this is for the .EXE to expose an array of functions DLL's can call. You could do this with delegates and probably signals and slots. Have a look at the truly excellent FastDelegate here on CP. In my programmers editor (see sig) I enabled interpreted C functions to call C/C++ functions in my .EXE. This is done by my C compiler resolving function addresses via. the .EXE's MAP file. This works very well and allows extensions to the editor to do most anything that the .exe can. Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"

            D Offline
            D Offline
            Dominik Reichl
            wrote on last edited by
            #7

            Also declare the functions as exported. Doh :) I've searched the whole IDE, all subdialogs, etc. at least 2 hours for a setting to generate a .lib of the .exe file... Didn't find anything. I have almost given it up and then just prefixed some of the functions with __declspec(dllexport). Compiled it, and think what? It generated the .lib, .exp and exported the functions very nicely as one could see in the Dependency Viewer. Yay!!! Added the .lib to the test plugin project (the DLL), compiled it, and everything works!! Many many thanks!!! Dominik


            _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

            J N 2 Replies Last reply
            0
            • D Dominik Reichl

              Also declare the functions as exported. Doh :) I've searched the whole IDE, all subdialogs, etc. at least 2 hours for a setting to generate a .lib of the .exe file... Didn't find anything. I have almost given it up and then just prefixed some of the functions with __declspec(dllexport). Compiled it, and think what? It generated the .lib, .exp and exported the functions very nicely as one could see in the Dependency Viewer. Yay!!! Added the .lib to the test plugin project (the DLL), compiled it, and everything works!! Many many thanks!!! Dominik


              _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

              J Offline
              J Offline
              John R Shaw
              wrote on last edited by
              #8

              :-DNot bad at all! An expert did not show up but someone who could get you looking in the right direction did. :doh:It never occured to me that you were not using export. :(Now if I can just understand how to do basicaly the same thing via COM thru the IUnknow interface. Thats what I've been working on. INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen

              N 1 Reply Last reply
              0
              • J John R Shaw

                :-DNot bad at all! An expert did not show up but someone who could get you looking in the right direction did. :doh:It never occured to me that you were not using export. :(Now if I can just understand how to do basicaly the same thing via COM thru the IUnknow interface. Thats what I've been working on. INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen

                N Offline
                N Offline
                Neville Franks
                wrote on last edited by
                #9

                John R. Shaw wrote: Not bad at all! An expert did not show up but someone who could get you looking in the right direction did. Hey who said I'm not an expert.:-D Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"

                J 1 Reply Last reply
                0
                • D Dominik Reichl

                  Also declare the functions as exported. Doh :) I've searched the whole IDE, all subdialogs, etc. at least 2 hours for a setting to generate a .lib of the .exe file... Didn't find anything. I have almost given it up and then just prefixed some of the functions with __declspec(dllexport). Compiled it, and think what? It generated the .lib, .exp and exported the functions very nicely as one could see in the Dependency Viewer. Yay!!! Added the .lib to the test plugin project (the DLL), compiled it, and everything works!! Many many thanks!!! Dominik


                  _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

                  N Offline
                  N Offline
                  Neville Franks
                  wrote on last edited by
                  #10

                  Dominik Reichl wrote: Added the .lib to the test plugin project (the DLL), compiled it, and everything works!! Many many thanks!!! Glad to be of help. Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"

                  1 Reply Last reply
                  0
                  • N Neville Franks

                    John R. Shaw wrote: Not bad at all! An expert did not show up but someone who could get you looking in the right direction did. Hey who said I'm not an expert.:-D Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"

                    J Offline
                    J Offline
                    John R Shaw
                    wrote on last edited by
                    #11

                    Neville Franks wrote: Hey who said I'm not an expert.:-D :laugh:You know what I mean! Some one who writes DLLs all the time and can answer questions about them in his sleep. By that deffinition most of us are not experts on DLLs.:-D INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen

                    1 Reply Last reply
                    0
                    • D Dominik Reichl

                      Hello! I'm currently writing some application, that contains a class A. It loads a DLL and passes a pointer to A to the DLL. The DLL includes the header file of A. Anyway, when I try to compile this, I get LNK2001: unresolved external symbol errors for all A class function calls... When I include all *.obj files as library files in the DLL settings, it compiles. But it doesn't really execute the actual functions of the main application then, it just compiles the whole code again into the DLL. It shouldn't do this, it should just call the real functions of the main application. What must I do that the DLL can execute the functions of A? Thanks and best regards, Dominik


                      _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

                      N Offline
                      N Offline
                      Nick Nougat
                      wrote on last edited by
                      #12

                      Well, the most simple way is to move all 'exported' functionality (i.e. that part of the application the plugins should be able to access) into a separate dll itself. Plugins then just need to link to that dll in order to use them, as does the main application. (This would most likely be done via implicit linkage) That way you also have enforced a modular concept for your application, which I'd recommend anyway as soon as your appication gets complex. Many of my bigger projects evolved to a main exe that only served as 'launcher' for the dlls that contain the 'real application'. Hope that helps, Nick

                      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