托管c++中,可以定义结构体数组吗?如果可以,怎么定义?

linbegin 2009-02-18 04:12:06
我在c++中调用C#写的dll,作为参数的结构体数组不知道该怎么传递。
以下时c++中调用c#中的batchannealing类的代码:
Class1 ^a=gcnew Class1();
double kk=a->batchannealing(jihua,jihua1,jihua2,maxjobdonetime);
jihua是结构体数组,如果想上面那样写的话会报错:
错误 1 error C2664: “batchannealing::Class1::batchannealing”: 不能将参数 1 从“jih *”转换为“cli::array<Type,dimension> ^”
我感觉是不是应该将jihua从jih指针型转换成托管c++的cli::array<Type,dimension> ^这种形式,单卧不知道可不可以。希望各位高手指点,谢谢
...全文
797 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
真相重于对错 2009-02-18
  • 打赏
  • 举报
回复
array<type>^
mienfong 2009-02-18
  • 打赏
  • 举报
回复
另,能否麻煩你簡單的用上面的資料寫一下程式(像宣告,代入等),但不要像你問問題的那麼簡單,那會捉不到重點。
mienfong 2009-02-18
  • 打赏
  • 举报
回复
抱歉說錯,應該是為甚不用CLI的方式寫C++的結構體?因為CLI都是相容了,就不用考慮太多東西。
mienfong 2009-02-18
  • 打赏
  • 举报
回复
稍微看了一下,請問樓主為甚不用CLI的方式寫VC的結構體?這樣就不用做CString <--> String 轉換。
linbegin 2009-02-18
  • 打赏
  • 举报
回复
jihua结构体:
struct jih
{
CString lutai;
CString jihh;
CString currentoperate;
CString time;
CString hangch;
CString rezhao;
CString lengzhao;
CString waittime; //记录等待时间
CString waitb; //记录等待开始时间
CString freetime; //记录抛空时间
CString time1; //保存初始剩余时间
CString lengquetime;
CString jiaretime;
};

以下是c#中的代码:
namespace batchannealing
{
public class Class1
{

myLink ml = new myLink();
anneal_event ae = new anneal_event();
//structData st = new structData();

rezh[] re = new rezh[23];

lengzh[] lz = new lengzh[23];
hangche[] hc = new hangche[2];
timecalculate[] tc = new timecalculate[1000];

DateTime current = new DateTime();
DateTime begin = new DateTime();
int x = 0;
string makespan = "";
double totalwaittime = 0;
double totalfreetime = 0;
double jiartime = 0; //加热时间
double lengqtime = 0; //冷却时间
public double batchannealing(jih[] jihua, dengpaichan[] jihua1, ableresorce[] jihua2,ChargeMode mode)
{

//扫描条件事件表
int count = 0;
string[] newjihua = new string[count];


count = jihua.Length;
int countall=count;
bool isxiere = false;
//int end = 0;

........
}
batchannealing方法太长,省略了。
linbegin 2009-02-18
  • 打赏
  • 举报
回复
struct jih
{
CString lutai;
CString jihh;
CString currentoperate;
CString time;
CString hangch;
CString rezhao;
CString lengzhao;
CString waittime; //记录等待时间
CString waitb; //记录等待开始时间
CString freetime; //记录抛空时间
CString time1; //保存初始剩余时间
CString lengquetime;
CString jiaretime;
};



public double batchannealing(jih[] jihua, dengpaichan[] jihua1, ableresorce[] jihua2,ChargeMode mode)
{

//扫描条件事件表
int count = 0;
string[] newjihua = new string[count];


count = jihua.Length;
int countall=count;
bool isxiere = false;
//int end = 0;
........
}
mienfong 2009-02-18
  • 打赏
  • 举报
回复
麻煩寫詳細點,把batchannealing及Class1的類定義及jihua結構體寫清楚,越細越能瞭解你的問題。

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧