Cause: extern "C" must be added before the DLL function declaration in C ++ function declaration.
[Dllimport ("A. dll")]
Public extern static int F ();
After the call, the system prompts that the entry point cannot be found.
Run dumpbin/exports on the command line to view the function name:, or use exclusive to view the exported interface.
Dumpbin/exports a. dll
The function name is not "F "? But "? F @ yahxz"
C # function declaration:
[Dllimport ("A. dll", entrypoint = "? F @ yahxz ")]
Public extern static int F ();
This call is successful!
1Basic explanation: Extern can be placed inVariable or functionBefore,To indicate the definition of variables or functions in other files,Prompt the compiler to find its definition in other modules when it encounters this variable and Function. In addition, extern can be used to specify links.
That is to say, extern has two functions. First, when it is connected with "C", for example, extern "C" Void fun (int A, int B ); the compiler will tell the compiler to translate the corresponding function name instead of the C ++ name according to the C rule when compiling the function name fun, when translating this function name, the C ++ rule will make the name "fun" completely invisible. It may be fun @ abc_int_int # % $ or something else, this depends on the "temper" of the compiler (the methods used by different compilers are different). Why does this happen because C ++ supports function overloading, I will not discuss this issue too much here. If you are interested, you can search for it online. I believe you can get a satisfactory explanation!