C # Call the unmanaged code. "No Entry Point found" SOLUTION

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.