嗨,我试图从 c# 调用一些 c++ 代码。所以我遵循了几个教程,amde 我自己的 dll,现在我从我的 c# 包装器中调用它。问题是,我有一个接收指针的函数,但我似乎无法让它工作,Visual Studio 只是向我显示我不太了解的红色错误。有人可以告诉我我做错了什么吗?我还有一个问题,如果 c++ 中的函数调用其他函数,所有数据都将保持不变,对吗?因为我传递的这个数组将在 dll 内部进行操作,然后,我会从 dll 调用其他函数来获取结果 - 我担心函数调用之间数据会丢失!
谢谢!
dll .h #包括
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstring>
#include "opencv\ml.h"
struct points{
double x;
double y;
double z;
};
#define db at<double>
extern "C" __declspec(dllexport) points * mapear_kinect_porto(points pontos[]);
CvERTrees * Rtree ;
extern "C" __declspec(dllexport) void calibrate_to_file(points pontos[]);
extern "C" __declspec(dllexport) int calibration_neutral();
extern "C" __declspec(dllexport) int EmotionsRecognition();
时间:2019-04-10 标签:c#wrapper
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct points
{
/// double
public double x;
/// double
public double y;
/// double
public double z;
}
class CPlusPlusWrapper
{
/// Return Type: void
///pontos: points*
[System.Runtime.InteropServices.DllImportAttribute("DLLTUT.dll", EntryPoint = "calibrate_to_file")]
public static extern void calibrate_to_file(ref points pontos);
public unsafe void calibrate_file()
{
points[] shit = new points[8];
points*[] pBLA; //error here!!!!
pBLA = &shit;
// calibrate_to_file(pbla);
}
}
顺便说一句,我使用了 p/invoke 助手,我得到了这个
public partial class NativeConstants {
/// db -> at<double>
/// Error generating expression: Expression is not parsable. Treating value as a raw string
public const string db = "at<double>";
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct points {
/// double
public double x;
/// double
public double y;
/// double
public double z;
}
public partial class NativeMethods {
/// Return Type: points*
///pontos: points*
[System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint="mapear_kinect_porto")]
public static extern System.IntPtr mapear_kinect_porto(ref points pontos) ;
/// Return Type: void
///pontos: points*
[System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint="calibrate_to_file")]
public static extern void calibrate_to_file(ref points pontos) ;
/// Return Type: int
[System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint="calibration_neutral")]
public static extern int calibration_neutral() ;
/// Return Type: int
[System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint="EmotionsRecognition")]
public static extern int EmotionsRecognition() ;
}