c#调用c++出现异常

pixian0237 pixian0237 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
c#代码

using System;
using System.Colle<img src="https://img-bbs.csdn.net/upload/201704/11/1491899383_919628.png" alt="">.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
using System.IO;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
[DllImport("smallT_BJ.dll", EntryPoint = "?smallTarget@@YA?AV?$Point_@H@cv@@PBD@Z",
ExactSpelling = true,CallingConvention = CallingConvention.Cdecl)]
// EntryPoint 这个比较复杂的部分是通过dependency查询到的函数名,与之前定义的函数名smallTarget多了很多字符
public static extern Point smallTarget(string path);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string path = " C:\\1.bmp";
Point point = new Point();
point = smallTarget(path);
}
}
}

c++dll下面是.h文件的内容
#include <windows.h>
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <opencv2\opencv.hpp>
#include <fstream>
#include <memory>
#include <stdlib.h>
#include <math.h>
#include <time.h>
using namespace std;
using namespace cv;
#ifdef SMALLT_BJ_EXPORTS
#define SMALLT_BJ_API __declspec(dllexport)
#else
#define SMALLT_BJ_API __declspec(dllimport)
#endif
SMALLT_BJ_API Mat filters(Mat source, int thresholdin);
SMALLT_BJ_API Mat filterspatial2(Mat source, int th);
SMALLT_BJ_API void cmedian(Mat src, Mat dst, int innerbox_size, int outerbox_size);
SMALLT_BJ_API Mat prefilter(Mat source);
SMALLT_BJ_API vector<Mat> getSuspects(Mat& frame, Mat src, int box_size, vector<Point>& LeftUpPoints, vector<vector<Point>>& cont);
SMALLT_BJ_API Point smallTarget(const char* file);

其他的都是乱码就不贴出来了,我在c#执行文件的目录下面(存放位置肯定没又问题,bin\Debug目录下)放了4个可能需要用到的文件,分别是.dll文件.h文件,.lib文件,.exp文件。在调用这个dll文件之前我用dependency测试了一下dll,发现缺少几个opencv方面的动态库,然后就加了相应的dll文件加在c#程序的目录下,后来又检测发现又缺少了更多的dll,然后又添加了相应的dll,最后检测不缺少dll,但是出现的问题是:“警告: 由于在延时加载依赖模块中丢失导入函数,至少有一个模块具有不能解析的导入。”。其中dll文件在别人给我的时候在我的电脑上进行了测试,并没问题,可以运行通过。
然后我在c#上进行调用dll出现的问题是

然后上网找了很多资料,实在是没用一个合适的解决方案、只能来请求下帮助,怎么解决?然后是dll制作出了问题还是c#d调用dll本来就存在一些问题呢?
...全文
评论 15
收藏 已收藏
分享
返回顶部
pixian0237
C# 111,129 成员 642,540 内容