开发者

cli/C++ how to define cli::array with unmanaged type element?

I have a native C/C++ struct

typedef struct
{
...
} AStruct;

and in C++/CLI code i define one delegate and one cli array as following

public delegate void UpdateDataDelegate(AStruct% aSt,AStruct% bSt);

cli::Array<AStruct>^ args=gcnew cli::Array<AStruct>(2); // complile failed!!!!。

this->Invoke(updateData,args);

AStruct has many fields and was used by many module开发者_如何转开发s so if i don't like to write a mananged wrap for AStruct, how to make above code works?

many thanks


The element type of a managed array must be a managed type. One workaround is store pointers:

array<AStruct*>^ args=gcnew array<AStruct*>(2);
args[0] = new AStruct;
// etc...

UpdateDataDelegate^ dlg = gcnew UpdateDataDelegate(Mumble);
dlg->Invoke(*args[0], *args[1]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜