我想将结构传递给 C 函数,并编写以下代码。
当我运行它时,第一个函数 -Foo1正在工作,然后函数Foo出现异常。你能帮我理解是什么问题吗?...
C代码:
typedef struct
{
int Size;
//char *Array;
}TTest;
__declspec(dllexport) void Foo(void *Test);
__declspec(dllexport) int Foo1();
void Foo(void *Test)
{
TTest *X = (TTest *)Test;
int i = X->Size;
/*for(int i=0;i<Test->Size;Test++)
{
Test->Array[i] = 127;
}*/
}
int Foo1()
{
return 10;
}
Run Code Online (Sandbox Code Playgroud)
C# 代码:
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
[StructLayout(LayoutKind.Sequential)]
public class TTest
{
public int Size;
}
class Program
{
[DllImport(@"C:\.net …Run Code Online (Sandbox Code Playgroud)