将c++函数导入c#中[重复]。

问题描述 投票:-1回答:1

我创建了一个c++函数,它将char[]和它的大小作为参数,并在函数中修改参数。我想在c#中使用这个函数,把它导入到dll中。我已经将该函数导出为dll,但我如何在c#中使用它。

C++代码:C++代码。

static void getDriveList(char* name, int* size)
{
    char arr[4] = { 'a','b','c','d' };
    for (int i = 0; i < 4; i++)
        name[i] = arr[i];
    *size = 4;
}

c#代码:C#代码。

const string dllLocation = "D:\\Project1.dll";
 [DllImport(dllLocation, CallingConvention = CallingConvention.Cdecl)]
 private static extern void getDriveList(out char[]name,out  int Len);

int length;
char[] name;
getDriveList(out name, out length);

c#代码不正确。我如何在c#中使用c++代码。

c# c++ dllexport
1个回答
-1
投票

在dll文件中制作c++函数,并尝试从c#代码中制作这个。

© www.soinside.com 2019 - 2024. All rights reserved.