다음과 같이 C ++ 64 비트 라이브러리를 만들었습니다.
// UnManagedCLI.h
#pragma once
using namespace System;
using namespace System::Runtime::InteropServices;
namespace UnManagedCLI {
[DllImport("msvcrt.dll", EntryPoint = "memset", CallingConvention = CallingConvention::Cdecl, SetLastError = false)]
extern IntPtr MemSet(IntPtr dest, int c, int count);
//[System::Runtime::CompilerServices::ExtensionAttribute]
public ref class Unmanaged sealed
{
public:
static void Free(void* unmanagedPointer)
{
Marshal::FreeHGlobal(IntPtr(unmanagedPointer));
}
generic <typename T> where T : value class
static IntPtr New(int elementCount)
{
return Marshal::AllocHGlobal(sizeof(T) * elementCount);
}
generic <typename T> where T : value class
static IntPtr NewAndInit(int elementCount)
{
int sizeInBytes = sizeof(T) * elementCount;
IntPtr newArrayPtr = Marshal::AllocHGlobal(sizeInBytes);
MemSet(newArrayPtr, 0 , sizeInBytes);
return newArrayPtr;
}
generic <typename T> where T : value class
static void* Resize(void* oldPointer, int newElementCount)
{
return Marshal::ReAllocHGlobal(IntPtr(oldPointer),
IntPtr((int) sizeof(T) * newElementCount)).ToPointer();
}
};
}
C #에서 참조로 포함하고 빌드에서 안전하지 않은 코드를 확인한 다음 기본에서 다음을 수행합니다.
using UnManagedCLI;
unsafe class TestWriter
{
static void Main()
{
Unmanaged un;
//I can't access any of the C++ methods in here?
}
}
un.
C ++ / CLI 라이브러리에서 메소드가 보이지 않는다고 말할 때 ? 잘 빌드되고 실행되지만 C ++에 전혀 액세스 할 수 없습니다.
C +++ / CLI 클래스 (관리되지 않음)의 모든 메서드는 정적입니다. C #에서 Unmanaged.Method 구문을 사용해보십시오 (개체를 만들 필요가 없음).
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다