开发者

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

开发者 https://www.devze.com 2023-01-15 15:16 出处:网络
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

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

精彩评论

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