Can I call a method which is placed in main application from dll code?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
seems there is only one way to do it – create a callback object.
in your application you have to declare interface, wich describes your method, for example:
next you have to create class, wich implements this interface (and your method):
when you load DLL, you have to create
TMyMethodObjectinstance and pass itsIMyMethodInterfaceto dll; of course dll has to have corresponding method and export it (wich takes interface as parameter)SetMethodCallbackwich stores interface reference:vars:
code:
now, you can use IMyMethodInterface reference in your dll to call method.
of course you can statically link dll and use it directly:
here is an DLL sample code:
take into account that your
mmoobject (TMyMethodInterface) will not be destroyed until you setAppMethodin dll tonil(or FreeLibrary dll ), so be careful