i got a struct like:
---------------------
public ref struct OutPacket{
int m_replyIndex;
List<MainInfo^>^ m_mainInfos;
};
---------------------
when i pass it to another process, i have to transfer it to intptr :
---------------------
IntPtr pnt = Marshal::AllocCoTaskMem(Marshal::SizeOf(outPacket));
Marshal::StructureToPtr(outPacket,pnt,true);
return pnt;
---------------------
then i got a message:
*********
err = {"Type 'CProcess.OutPacket' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed."}
*********
i think the trouble is that i have to process a "List<>"Type,maybe i should use "StructLayout",but i can't handle this well,
please help me thank u

error about"cannot be marshaled as an unmanaged structure"
xyktiger
Tahereh farrokhi
but i want to pass the struct like this:
public ref struct OutPacket{
int m_replyIndex;
List<MainInfo^>^ m_mainInfos;
};
if i don't marshal this ,how i can transfer it to intptr
Grattier
Yes: C# will understand the definition of the type: that is what the CLR is all about. Just use your type as the return type: you don't need to do any marshalling if you are going between C++/CLI and C#.
BURK
Ed Moya
hackbabu
You can't marshall something as complex as this to a native Win32 - in general you can only automatically marshall simple types (the most complex I have tried is some of the simpler Win32 structs).
What are you trying to acheive here: how do you expect this type to be represented on the native side
GunterPete
ok. if i want to use the OutPacket passed from vc.net,i have this:
-------------
OutPacket outPacket = .....
List<MainInfo> mainInfos = outPacket.m_mainInfos;
---------------
then i got the error:
cannot convert from 'System.Collections.Generic.List<NameSpace1.MainInfo>' to 'System.Collections.Generic.List<NameSpace2.MainInfo>'
ShadowOfTheBeast
C# will understand the definition
my vc.net code is:
"SomeType" OnReply(WPARAM wParam, LPARAM lParam)
{
}
my c# code will call the OnReply, then i should use the "SomeType" in my c# code
please tell me the way i can solve the "SomeType",if it's not a "Intptr"
tistalker
in c# and vc.net i declare the same struct OutPacket
public ref struct OutPacket{
int m_replyIndex;
List<MainInfo^>^ m_mainInfos;
};
public struct OutPacket
{
int m_replyIndex;
List<MainInfo^>^ m_mainInfos;
}
but i have this trouble when compiling:
Error 2 Cannot implicitly convert type 'Namespace1.OutPacket' to 'Namespace2.OutPacket'
Michael Kariv
Antara