这种需求算有点难度吧,在这里贴出一个实现以供参考:

C++部分:头文件

// 下列 ifdef 块是创建使从 DLL 导出更简单的
// 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 CALCULATE_EXPORTS
// 符号编译的。在使用此 DLL 的
// 任何项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将
// CALCULATE_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
// 符号视为是被导出的。#ifndef _Calculate_
#define _Calculate_#include <stdlib.h>#ifdef CALCULATE_EXPORTS
#define CALCULATE_API extern "C" __declspec(dllexport)
#else
#define CALCULATE_API __declspec(dllimport)
#endiftypedef intptr_t  IntPtr;CALCULATE_API int MultiGray(double st_high,double st_low,IntPtr* P_inflect_handle,int** P_inflect,int* P_inflect_Len,double set_max,double set_min,double response_setTime,IntPtr* P_mid_handle,int** P_mid,int* P_mid_Len,IntPtr* flag_handle,int** flag,int* flag_Len,int jump_edge,int tcon_OD_up,int tcon_OD_down,IntPtr* P_left_handle,int** P_left,int* P_left_Len,IntPtr* P_right_handle,int** P_right,int* P_right_Len,int freq,double response
);
CALCULATE_API bool ReleaseObject(IntPtr handle);#endif

C++部分:函数实现

// Calculate.cpp : 定义 DLL 的导出函数。
//#include "pch.h"
#include "framework.h"
#include "Calculate.h"
#include <vector>
using namespace std;CALCULATE_API int MultiGray(double st_high,double st_low,IntPtr* P_inflect_handle,int** P_inflect,int* P_inflect_Len,double set_max,double set_min,double response_setTime,IntPtr* P_mid_handle,int** P_mid,int* P_mid_Len,IntPtr* flag_handle,int** flag,int* flag_Len,int jump_edge,int tcon_OD_up,int tcon_OD_down,IntPtr* P_left_handle,int** P_left,int* P_left_Len,IntPtr* P_right_handle,int** P_right,int* P_right_Len,int freq,double response
)
{int count = 100000;auto array1 = new std::vector<int>();for (int i = 0; i < count; i++){array1->push_back(i);}*P_inflect_handle = reinterpret_cast<IntPtr>(array1);*P_inflect = array1->data();*P_inflect_Len = count;auto array2 = new std::vector<int>();for (int i = 0; i < count; i++){array2->push_back(i);}*P_mid_handle = reinterpret_cast<IntPtr>(array2);*P_mid = array2->data();*P_mid_Len = count;auto array3 = new std::vector<int>();for (int i = 0; i < count; i++){array3->push_back(i);}*flag_handle = reinterpret_cast<IntPtr>(array3);*flag = array3->data();*flag_Len = count;auto array4 = new std::vector<int>();for (int i = 0; i < count; i++){array4->push_back(i);}*P_left_handle = reinterpret_cast<IntPtr>(array4);*P_left = array4->data();*P_left_Len = count;auto array5 = new std::vector<int>();for (int i = 0; i < count; i++){array5->push_back(i);}*P_right_handle = reinterpret_cast<IntPtr>(array5);*P_right = array5->data();*P_right_Len = count;return 0;
}CALCULATE_API bool ReleaseObject(IntPtr handle)
{std::vector<int>* object = reinterpret_cast<std::vector<int>*>(handle);delete object;return true;
}

C# 部分:

 public class SafeHandle : SafeHandleZeroOrMinusOneIsInvalid{public SafeHandle(): base(true){}protected override bool ReleaseHandle(){return ReleaseObject(handle);}[DllImport("Calculate.dll", CallingConvention = CallingConvention.Cdecl)]static unsafe extern bool ReleaseObject(IntPtr handle);}public class Performer{[DllImport("Calculate.dll", EntryPoint = "MultiGray", CallingConvention = CallingConvention.Cdecl)]unsafe extern static int MultiGray(double st_high,double st_low,out SafeHandle handle1,out int* P_inflect,out int P_inflect_Len,double set_max,double set_min,double response_setTime,out SafeHandle handle2,out int* P_mid,out int P_mid_Len,out SafeHandle handle3,out int* flag,out int flag_Len,int jump_edge,int tcon_OD_up,int tcon_OD_down,out SafeHandle handle4,out int* P_left,out int P_left_Len,out SafeHandle handle5,out int* P_right,out int P_right_Len,int freq,double response);public unsafe ReturnData Excute(double st_high,double st_low,out SafeHandle handle1,out int* P_inflect,out int P_inflect_Len,double set_max,double set_min,double response_setTime,out SafeHandle handle2,out int* P_mid,out int P_mid_Len,out SafeHandle handle3,out int* flag,out int flag_Len,int jump_edge,int tcon_OD_up,int tcon_OD_down,out SafeHandle handle4,out int* P_left,out int P_left_Len,out SafeHandle handle5,out int* P_right,out int P_right_Len,int freq,double response){int result = MultiGray(st_high,st_low,out handle1,out P_inflect,out P_inflect_Len,set_max,set_min,response_setTime,out handle2,out P_mid,out P_mid_Len,out handle3,out flag,out flag_Len,jump_edge,tcon_OD_up,tcon_OD_down,out handle4,out P_left,out P_left_Len,out handle5,out P_right,out P_right_Len,freq,response);ReturnData data = new ReturnData();data.flag_Len = flag_Len;data.flag = new int[flag_Len];for(int i=0;i<flag_Len;i++){data.flag[i] = flag[i];}data.freq = freq;data.jump_edge = jump_edge;data.P_inflect_Len = P_inflect_Len;data.P_inflect = new int[P_inflect_Len];for(int i=0;i<P_inflect_Len;i++){data.P_inflect[i] = P_inflect[i];}data.P_left_Len = P_left_Len;data.P_left = new int[P_left_Len];for(int i=0;i<P_left_Len;i++){data.P_left[i] = P_left[i];}data.P_mid_Len = P_mid_Len;data.P_mid = new int[P_mid_Len];for(int i=0;i<P_mid_Len;i++){data.P_mid[i] = P_mid[i];}data.P_right_Len = P_right_Len;data.P_right = new int[P_right_Len];for(int i=0;i<P_right_Len;i++){data.P_right[i] = P_right[i];}data.response = response;data.response_setTime = response_setTime;data.set_max = set_max;data.set_min = set_min;data.st_high = st_high;data.st_low = st_low;data.tcon_OD_down = tcon_OD_down;data.tcon_OD_up = tcon_OD_up;handle1.Dispose();handle2.Dispose();handle3.Dispose();handle4.Dispose();handle5.Dispose();return data;}}public class ReturnData{public double st_high;public double st_low;public int[] P_inflect;public int P_inflect_Len;public double set_max;public double set_min;public double response_setTime;public int[] P_mid;public int P_mid_Len;public int[] flag;public int flag_Len;public int jump_edge;public int tcon_OD_up;public int tcon_OD_down;public int[] P_left;public int P_left_Len;public int[] P_right;public int P_right_Len;public int freq;public double response;}

C# C++ 互操作:C++向C#输出不定长数组或指针的实现相关推荐

  1. 西门子1200/1500PLC不定长数组选择排序的运用编程实例

    前景介绍: 1.选择排序原理:选择排序算法首先从第1个位置开始对全部元素进行选择,选出全部元素中最小的给该位置,再对第2个位置进行选择,在剩余元素中选择最小的给该位置即可:以此类推,重复进行" ...

  2. java数组初始化和不定长数组处理方式

    初始化数组 1.动态初始化: 数组类型[] 数组名=new 数组类型[数组长度]; 2.静态初始化: 数组类型[] 数组名={数组0,数组1,数组2,数组3,......}; 3.静态省略初始化 数组 ...

  3. python输入定长数组和输入不定长数组

    输入定长数组 a,b,c = map(int,input().split( )) list = [a,b,c] print(list) 输入一维不定长数组 # arr = input('') #输入一 ...

  4. c语言不定长数组_学习C语言这三块“硬骨头”不搞定学了也是白学

    C语: C语言在嵌入式学习中是必备的知识,审核大部分操作都要围绕C语言进行,而其中有三块"难啃的硬骨头"几乎是公认级别的. 01指针 C语言 指针公认最难理解的概念,也是让很多初学 ...

  5. java创建不定长数组_java如何创建不定长的数组?

    java如何创建不定长的数组? JAVA没法定义不定长的数组,要么声明为NULL,要么指定其长度.如果需要不定长的集合,我们可以采用ArrayList来解决. 1.首先声明一个集合listArrayL ...

  6. java创建不定长数组_java创建不定长的数组应该怎么做

    java创建不定长的数组应该怎么做 发布时间:2020-05-06 13:45:51 来源:亿速云 阅读:239 作者:小新 java创建不定长的数组应该怎么做?相信有很多人都不太了解,今天小编为了让 ...

  7. c语言定义不定长数组初始化_大学C语言期末考试练习题(带详解答案)(1)

    链接:https://pan.baidu.com/s/1d2Bb1vNTyBNpFGneIAicVw 提取码:y7uw 单项选择题 C语言的基本单位是 函数 1.(A  )是构成C语言程序的基本单位. ...

  8. c语言定义不定长数组初始化_C语言如何定义一组长度不定的数组?

    1 引言 定长数组包 在平时的开发中,缓冲区数据收发时,如果采用缓冲区定长包,假定大小是 1k,MAX_LENGTH 为 1024.结构体如下: // 定长缓冲区 //公众号:c语言与cpp编程 st ...

  9. c语言定义不定长数组初始化_数组的定义,初始化和使用,C语言数组详解

    数组可以说是目前为止讲到的第一个真正意义上存储数据的结构.虽然前面学习的变量也能存储数据,但变量所能存储的数据很有限.不仅如此,数组和指针(后续会讲)是相辅相成的,学习数组可以为学习指针打下基础. 那 ...

最新文章

  1. 分布式系统选主怎么玩
  2. JMeter测试TCP/IP Socket应用的性能
  3. Linux下php安装Redis扩展
  4. JavaScript的基础学习篇
  5. faster rcnn可视化(修改demo.py保存网络中间结果)
  6. axure选中后横线切换_3、开关状态切换 —— Axure实用交互
  7. 论文阅读 - Beat Tracking by Dynamic Programming
  8. php闭包 回调函数,PHP|PHP实践-闭包
  9. 2021年朔州市副高考试成绩查询,2021朔州市第二中学校教师成绩查询入口:http://www.shuozhou.gov.cn/ztjs/rlzy/rsks/...
  10. Native Instruments Battery 4 for mac - 尖端鼓采样器
  11. LINQ系列:Linq to Object集合操作符
  12. 怎么查oa系统的服务器地址,oa系统服务器地址如何查
  13. 市场调研报告-全球与中国商业虚拟化平台市场现状及未来发展趋势
  14. 「springcloud 2021 系列」nacos配置管理 这样用就对了
  15. 世界上前11名最贵跑车
  16. grub引导安装win10
  17. 插值、拟合和逼近的对比
  18. Python金融应用编程(数据分析、定价与量化投资) !
  19. 回文是指正读反读均相同的字符序列,如“abba”和“abdba”均是回文但“good”不是回文,试写一个算法判断给定字符是否为回文。
  20. 安装mysql的初始密码在哪里

热门文章

  1. html仿今日头条数据列表
  2. java会员卡的绑定和解绑_java毕业设计_springboot框架的健身房会员卡管理
  3. 32位低功耗MCU的设计
  4. 改变文字颜色html,html怎么改变字体大小和颜色
  5. intel英特尔架构
  6. 小米首页二级菜单栏实现原理
  7. linux操作的进程调度没有采用,Linux进程调度分析
  8. adobe xd_如何在Adobe XD中创建Finance App UI设计
  9. ip地址转换htonl的用法
  10. Cocoa Application-基础