tags:

views:

84

answers:

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

Can anybody tell me how to remove this compile error.

A: 

Changing the typedef to this might work:

typedef void (*EntryPointfuncPtr)(int, const char*);
Steef
+2  A: 

Your code has two problems:

  1. The HINSTANCE variable is declared as LoadME, but spelled LoadMe when its initialised and used. Choose one spelling or the other.

  2. The two lines after the if statement are in different scopes. This is the cause of the compiler error that you are seeing. Enclose the lines in braces so that they are in the same scope

This works for me:

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

Andy

Andy Johnson