DLL and EXEs, Verify design

Recommended Posts

In my project, an imported DLL must call some function in the EXE. My solution was to create a function in the DLL that the EXE calls and provides a function pointer through. Is this OK? Is it guaranteed to always work? Is there a better solution?

Share on other sites
That doesn't sound good, I for one wouldn't recommend doing it like that.
Having a DLL rely on an EXE kinda defeats the idea of a DLL.
But if you really wanna do it that way, I guess I could see it working.

Share on other sites
If you want to be more OOPy, you could use an abstract class (THat's what I do for plugins).

In the header shared between the EXE and DLL:
class IApp{public:   IApp() {}   virtual ~IApp() {}   virtual bool DoSomething() = 0;   // Other methods here};

In the EXE source:
class CApp : public IApp{public:   CApp();   virtual ~CApp();   virtual bool DoSomething() {/* Code here */}};

And then you create a CApp, and pass it to the DLL, which takes it as an IApp.

Share on other sites
The reason for using DLL is that am not going to develop those. Check out the idea at http://aritma.genteq.net

Share on other sites
Quote:
 Original post by arithmaIn my project, an imported DLL must call some function in the EXE.My solution was to create a function in the DLL that the EXE calls and provides a function pointer through. Is this OK? Is it guaranteed to always work? Is there a better solution?

This is pretty much exactly how callbacks happen in Windows, e.g. your window procedure usually lives in an .exe, that .exe calls into a .dll (user32.dll to be exact), passing a function pointer that points back into the .exe. Later on the .dll calls back into the .exe using that pointer.

Just make sure you explicitly specify your calling convention (cdecl, stdcall, that stuff) and you'll be fine.

Create an account

Register a new account

• Forum Statistics

• Total Topics
627770
• Total Posts
2979002

• 11
• 10
• 10
• 23
• 14