c++ - DLL design : the DLL needs to access some of the application functions/data -
i have dll bunch of functions. far, good, that's dll for. but, functions in dll need call functions (or access data) application loaded dll.
app.exe :
std::vector<someclass> objectslist; bool foo(void) { ... } loadlibrary( "something.dll" );
something.dll :
__declspec(dllexport) void somefunction(void) { if ( foo() ) { objectslist[2].someattr = 1; } }
for know, dll code in not correct because dll cannot know foo
or objectslist
@ linking. so, way see :
something.dll :
typedef bool footype(void); footype* pfoofunc; __declspec(dllexport) void setfoo(footype* fooptr) { pfoofunc = fooptr; } __declspec(dllexport) void somefunction(void) { if ( (*pfoofunc)() ) { ... _same thing objectslist_ } }
app.exe :
loadlibrary( "something.dll" ); setfoo = getprocaddress(...); setfoo(&foo);
am right or there more elegant way kind of stuff ?
solutions here : a dll need access symbols of application still interested in discussion kind of design.
thanks
there 2 common solutions: first dll use sort of callback; second put functions , data shared between root , dll(s) separate dll of own.
Comments
Post a Comment