Sign in to follow this  

DLL Calling An App

This topic is 4865 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
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
Quote:
Original post by jonbell
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?


it doesn't thats the whole point of the scheme, the code
i provided was in the DLL, not the app.

the dllFunction pluginInit(...) took and argument for a
function pointer, this function pointer is passed
from the application to the DLL init, and called to
add an menu item on the app side, its just to show you
how to do it w/o exporting functions from the app.

Share this post


Link to post
Share on other sites

This topic is 4865 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this