. Net calls the C ++ class library Method

Source: Internet
Author: User

In addition to performance,. Net also has to pay attention to security issues. We can give. netProgramSet shelling and obfuscation (. NET reactor tool ). In addition to shelling and obfuscation for. net, there is also a way to put important logic and computing in the C ++ class library. 
C # The attribute dllimport is used to call the C ++ class library and the Windows API.


1) prepare C ++ DLL first


 
Extern "C" _ declspec (dllexport) char * getstring () {return "Hello World ";}

Note: select "use MFC in static library" for the project attribute during compilation"


2) Prepare a demo to call the DLL

 
[Dllimport ("mfcdll. DLL ", entrypoint =" getstring ")] public static extern string getstring (); Private void btncall_click (Object sender, eventargs e) {MessageBox. show (getstring ());}

Note: The compiler must select 32-bit for compiling. If it is called in 64-Bit mode, an exception is thrown.

Display result:



Demo download: http://download.csdn.net/detail/sp951/3760084



Related Article

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.