Home > Back-end >  C code calls the DLL error
C code calls the DLL error

Time:06-08

#include
#include
Typedef int (* Fun1) (int a, int b);
Fun2 typedef int (*) (void);
Int main (int arg c, char * argv [])
{
HMODULE hDll=LoadLibrary (L "MyDLL. DLL");
If (hDll!=NULL)
{
Fun1 fun=(Fun1) GetProcAddress call (hDll, "add");
If (fun!=NULL)
{
Printf (" the add ()=% d \ n ", fun (5, 3));
}
Fun=(Fun1) GetProcAddress call (hDll, "sub");
If (fun!=NULL)
{
Printf (" sub ()=% d \ n ", fun (5, 3));
}
Fun2 output=(Fun2) GetProcAddress call (hDll, "output");
If (the output!=NULL)
{
The output ();
}
FreeLibrary (hDll);
}
return 0;
}

Above the C code calls the DLL, but in VS2012 at compile time, always to quote the following error:
Mistake 3 error C2065: "output" : no statement of identifiers d: \ test \ newcpp \ newcpp \ the main c 20 1 newcpp
Error 2 error C2146: syntax errors: lack of ";" () in front of the identifier "output" d: \ test \ newcpp \ newcpp \ the main c 20 1 newcpp
Error 1 error C2275: "Fun2" : this type is used as the expression illegal d: \ test \ newcpp \ newcpp \ the main c 20 1 newcpp
Please advice, thanks a lot!

CodePudding user response:

Some of the C compiler can only in the front of the block to define variables, try to define the output with fun in the same area

CodePudding user response:

To put the extension from. C. CPP

CodePudding user response:

Change the extension no more creative, VS can be compiled C file as C + +

CodePudding user response:


I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related