C C ++ 동적 링크 라이브러리 DLL을 호출 #

종류의 정적 메소드를 호출 할 필요가 만든 DLL을 관리되지 않는 C ++ 라이브러리 하나를 우리는 과정에서 문제를 해결하는 방법은 두 가지가 있음을 발견했다. 이 방법은 직접 C #을 참조에서 참조 할 수없는 것이 아니라, 유일한 필요가, 당신이 필요로 C #을 파일을 그을 추가, 다른 블로그가 훌륭한 세부 사항에 설명 된 정적 메소드 호출을 사용 :

using System.Runtime.InteropServices;

당신은 [같이 DllImport] 메서드를 호출하기 전에.

또 다른 방법은 직접 CLR을 사용하여 C ++ DLL 라이브러리를 생성하기 위해 관리하는 것입니다.

프로세스 생성

과 같은 일상적인
C ++ DLL을 :

1

4

5

6

(7)

8

9

(10)

(11)

(12)

(13)

(14)

(15)

(16)

(17)

// CPPlibdemo.h

#pragma once

 

using namespace System;

 

namespace CPPlibdemo {

 

    public ref class Class1

    {

        // TODO: Add your methods for this class here.

    public:

            String ^getgreating(){

 

            return "hello world";

        }

    };

}

C # 언어 :

1

4

5

6

(7)

8

9

(10)

(11)

(12)

(13)

(14)

(15)

(16)

(17)

(18)

(19)

(20)

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();

        }

    }

}

다음은 PHP 중국 네트워크 자세한 내용에 C ++ 동적 링크 라이브러리 DLL의 부탁에주의를 호출하는 C 번호의 내용이다 (www.php.cn)!

 

추천

출처www.cnblogs.com/ximi07/p/12371260.html