我有一个用C++编写的非托管静态库(.dll):
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "program.h"
struct MyData
{
int32_t index;
char* name;
//uint8_t* data;
};
extern "C" {
__declspec(dllexport) MyData* GetMyData()
{
MyData* ms = new MyData();
ms->index = 5;
ms->name = "Happy string";
//ms->data = new uint8_t[5] { 4, 8, 16, 32, 64 };
return ms;
}
}
Run Code Online (Sandbox Code Playgroud)
'GetMyData'方法返回指向'MyData'对象的指针.
我使用'PInvoke'将此库导入C#projeсt并调用'GetMyData'方法.
// This is a personal academic project. Dear …Run Code Online (Sandbox Code Playgroud)