C # calls C + + dynamic-link library DLLs

Source: Internet
Author: User

Two methods were found in the process to solve the problem: a DLL library created by unmanaged C + + that needs to be called with a static method. This method can not be directly referenced in C # Reference, but to use static call method, the other blog has been described in detail, the only thing to add is that C # files need to First:

Using System.Runtime.InteropServices;

Before you can call the [DllImport] method.


Another approach is to use the CLR directly to generate a managed C++dll library.


Create a process


The routines are as follows

C + + DLLs:

Cpplibdemo.h#pragma onceusing namespace System;namespace cpplibdemo {public ref class class1{//Todo:add your methods For this class here.public:String ^getgreating () {return ' Hello World ';}};}

C # language:

Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks;            Using Cpplibdemo;namespace consoleapplication5{class Program {static void Main (string[] args) {            Class1 Clrdemo = new Class1 ();            Console.Write (Clrdemo.getgreating ());        Console.ReadLine (); }    }}


C # calls C + + dynamic-link library DLLs

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.