2009-06-11 64 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"); 
} 

安迪

相關問題