有谁能告诉我如何在.dll中调用主机.exe文件中的函数?我的意思是,扭转他们的角色。现在DLL将从其主机EXE调用一个函数。
我这样做了:
DLL:
#define DLLIMPORT __declspec(dllimport)/(dllexport)
DLLIMPORT ret_check()
{
char resp;
system("cls");
printf("Exit to: ");
printf("\n\t[M] Midterms\n\t[H] Home\n\t\n\t[C] Cancel[X] Close Program\n\n");
ret:
resp = getch();
switch(resp)
{
case 'm': midterms(); //Defined in host .exe file
case 'h': main(); //Defined in host .exe file
case 'c': return;
case 'x': terminator(); //Defined in host .exe file
default: goto ret;
}
函数midterms()和terminator()以及main()可以在host exe文件中找到。
但是当我编译它时。我在命令提示符下遇到这样的错误:
>gcc -o midx.dll midx.o -s -shared -Wl,--subsystem,windows
midx.o:midx.c:(.text+0x402): undefined reference to `midterms'
midx.o:midx.c:(.text+0x40e): undefined reference to `terminator'
midx.o:midx.c:(.text+0x490): undefined reference to `_imp__withdraw'
midx.o:midx.c:(.text+0x4a2): undefined reference to `_imp__deposit'
midx.o:midx.c:(.text+0x4ae): undefined reference to `_imp__ret_check'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: midx.o: bad reloc
address 0x20 in section `.eh_frame'
collect2.exe: error: ld returned 1 exit status
有人可以帮帮我吗?
结构:
DLLIMPORT float withdraw() {}
DLLIMPORT float deposit() {}
DLLIMPORT ret_check() {}
DLLIMPORT float mid_problem3() {}