2009-06-11 63 views
0
typedef void (*EntryPointfuncPtr)(int argc, const char * argv); 
HINSTANCE LoadME; 
LoadMe = LoadLibrary("LoadMe.dll"); 
if (LoadMe != 0) 
EntryPointfuncPtr LibMainEntryPoint; //GIve error in .c file but working fine in Cpp file. 

//Error:illegal use of this type as an expression 

LibMainEntryPoint = (EntryPointfuncPtr)GetProcAddress(LoadMe,"entryPoint"); 

有没有人可以告诉我如何去除这个编译错误。在.c文件中加载DLL时出现问题

回答

0

更改的typedef这可能工作:

typedef void (*EntryPointfuncPtr)(int, const char*); 
2

您的代码有两个问题:

  1. 的HINSTANCE变量声明为LoadME,但拼写LoadMe当它的初始化和使用。选择一个拼写或另一个拼写。

  2. if语句后面的两行代码位于不同的范围内。这是您看到的编译器错误的原因。括在大括号的线,所以他们是在同一范围内

这个工作对我来说:

typedef void (*EntryPointfuncPtr)(int argc, const char * argv); 
HINSTANCE LoadMe; 
LoadMe = LoadLibrary("LoadMe.dll"); 
if (LoadMe != 0) 
{ 
    EntryPointfuncPtr LibMainEntryPoint; 
    LibMainEntryPoint = (EntryPointfuncPtr)GetProcAddress(LoadMe,"entryPoint"); 
} 

安迪

相关问题