Jump to content
  • Advertisement
Sign in to follow this  
jonbell

DLL Calling An App

This topic is 5228 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know how to export functions from a DLL so that my app can call it but is it possible to do the opposite and give the DLL access to a number of functions in my App that it can call? For example my app may call : dllDoIt(); then in the dll i want to call the app back : void dllDoit() { appAddIt(); } How can this be done? Cheers

Share this post


Link to post
Share on other sites
Advertisement
All sounds good, I am actually writing a plugin mechanism for my App so i want to allow dll's to create entries on my app's menu etc. How do other popular App plugins (Max etc) achieve this? Do they make a certain number of functions available to the plugin dll?

Share this post


Link to post
Share on other sites
From what I know, you would write code or script in the app that calls on the DLL. I've never written a max plug-in, but I remember seeing scripts you could write. In MS Office, for instance, you would write visual basic macros which call on your DLL. The visual basic would create the menus and interactions, while the DLL does the real dirty work (in C/C++ or whatever language).

Share this post


Link to post
Share on other sites
this is what i do in my editor

btw: IApplicationAccesor is just an abstract class that
accesses data on the App side, simple to do

just allocate on App side and pass to Dll when
calling pluginCallFunction.

Hope this helps,
Cheers
Dan


void (*APPMENUFUNC)( const char *title, int callId );

int pluginInit( APPMENUFUNC addMenu )
{
(*addMenu) ( "Do Something First", DLL_DOSOMETHING_FIRST );
(*addMenu) ( "Do Something Else", DLL_DOSOMETHING_ELSE );
(*addMenu) ( "Do Something Again", DLL_DOSOMETHING_AGAIN );

return 3; //number of menu items added
}

int pluginCallFunction( int callId, IApplicationAccesor *pApp )
{
switch( callId )
{
case DLL_DOSOMETHING_FIRST:
return doSomethingFirst();
case DLL_DOSOMETHING_ELSE:
doSomethingElse();
case DLL_DOSOMETHING_AGAIN:
doSomethingAgain();
}
return -1;
}

Share this post


Link to post
Share on other sites
So how does the plugin get hold of the functions to call in the app? GetProcAddress() cannot be used by a DLL because an App does not publish function names.

Is what I am trying to do a bad idea? Should a dll be calling an app?

Share this post


Link to post
Share on other sites
What I did was that when I load my dlls, I pass in an instance of my app to the dll (usign GetModuleHandle()) which I can then use to later access "EXPORTed" functions from my main app. I dunno if there's any other way, but it worked for me...

Share this post


Link to post
Share on other sites
Well, that's the caveat... The main app HAS to publish the functions to be accessed by the dll. I don't think you can really run away from that. Hence the rational behind passing the HINSTANCE to the dll upon load-time.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!