Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 调用c++;C语言中的泛型方法# 我创建了一个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#_C++ Cli - Fatal编程技术网

C# 调用c++;C语言中的泛型方法# 我创建了一个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# 调用c++;C语言中的泛型方法# 我创建了一个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#,c++-cli,C#,C++ Cli,当我说un.时,我没有看到C++/CLI库中的任何方法?它构建并运行良好,但我根本无法访问C++。< P> C++的所有方法(CLUB+CLI类)都是静态的。尝试使用C#中的非托管.Method语法(您不必创建对象)。为什么要通过p/Invoke调用memset?您可以#包含并直接调用它。提示:代码完成非常好,但编译器需要遵守规则。无论哪种情况,请键入所需的代码。如果Intellisense为您提供了一条您可以使用的信息,那么很好。否则,请查看编译器的说明。您可能会收到类似“Member”类的消

当我说
un.
时,我没有看到C++/CLI库中的任何方法?它构建并运行良好,但我根本无法访问C++。

< P> C++的所有方法(CLUB+CLI类)都是静态的。尝试使用C#中的非托管.Method语法(您不必创建对象)。

为什么要通过p/Invoke调用
memset
?您可以
#包含
并直接调用它。提示:代码完成非常好,但编译器需要遵守规则。无论哪种情况,请键入所需的代码。如果Intellisense为您提供了一条您可以使用的信息,那么很好。否则,请查看编译器的说明。您可能会收到类似“Member”类的消息。无法使用实例引用访问方法();请改为使用类型名对其进行限定”。
using UnManagedCLI;

unsafe class TestWriter
{
    static void Main()
    {
        Unmanaged un;

        //I can't access any of the C++ methods in here?
    }
}