在.c文件中加载DLL时出现问题

在.c文件中加载DLL时出现问题,dll,Dll,谁能告诉我如何删除这个编译错误吗 将typedef更改为此可能有效: 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 fin

谁能告诉我如何删除这个编译错误吗

将typedef更改为此可能有效:

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");

您的代码有两个问题:

  • HINSTANCE变量声明为LoadME,但在初始化和使用时拼写为LoadME。选择一种拼写或另一种拼写

  • if语句后面的两行在不同的范围内。这就是您看到的编译器错误的原因。用大括号括住这些行,使它们位于同一范围内

  • 这对我很有用:

    typedef void (*EntryPointfuncPtr)(int, const char*);
    
    安迪

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