I have a main project and a DLL project. The main executable links to the DLL. In the main project I have a function:
int func(char *str)
{
.....
}
In the DLL project, I want to use this function. Can I forward declare this function and use it? Like:
int func(char *str);
int dllFunc()
{
...
status = func(str);
...
}
You cannot use forward declaration forward declaration is something different. If you want call some method in dll, you have to use GetProcAdress or Implicit linking .
Anyway, It look that you want to call method placed inside you executable from some DLL, it can be done as far as I know. And it doesn't make much sense, because DLL is designed to be shared between application not main executable.
One (fairly common) way of doing it is to provide a callback from the application, ie
In DLL:
typedef void (*callback)();
callback my_callback;
void dll_register_callback(callback app_callback) { my_callback = app_callback; }
void do_things() { my_callback(); }
In application:
void cb() {}
dll_register_callback(cb);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.