About CSHARP Calling C ++ DLL

Source: Internet
Author: User

 

Because the Execution Code of C # And CLI can be obtained through disassembly (I just heard that there is no practical practice ).



For those that do not want to be disclosedCodeCan be written in C ++ and called by C # Or CLI.


Several methods have been found on the Internet


1: C #-> C ++

2: C #-> cli-> C ++

For details, see:Http://www.cppblog.com/mzty/archive/2008/03/12/44280.html

 

I personally think that method 1 is too cumbersome. In the C # project, I need to declare the output function again. More importantly, during debugging, I often warn stack mismatch to cause conflicts (annoying)

Although CLI engineering is added in method 2, the idea is clear and I recommend it to you.

 

Note, however, that the CLI and C ++ strings must be converted.

Convert string to char * as follows *

 

Using namespace system: runtime: interopservices;

String ^ strtitleinput = "dfdfsdfsdfassd ";

Char strtitle [256];


Intptr P = MARSHAL: stringtohglobalansi (strtitleinput );

Char * pinput = static_cast <char *> (P. topointer ());


Strcpy (strtitle, pinput );


MARSHAL: freehglobal (P );

 

 

 

J

 

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.