c# - Marshalling .NET generic types -
Here is a C # program that tries to Marshal.SizeOf
on some different types:
using thesystem; Using System.Runtime.InteropServices; Structure Layouts (LayoutCind.Security)] Class Acklace ({} Structure Layout (LayoutCind Security)] Structure Astroc {} [Layout Layout (LayoutCind.Security)] Class B {ACLs Values;} [Structure Layouts (LayoutCind.Security) ] Class C
on Edit: Because the comments were asked, here it is called "real world" There is a problem that inspires most of the academic questions: I am calling in a CPI which is basically a C function which operates a variety of simple simple structures (many different types) after all one field There is a generic header, but the area's headline R is different in different structures. One flag indicates the type of field in the header (strange, yes, but this is to work with me)."type 'c11 [AClass]' is an unmanaged structure Can not be martial in the form, no meaningful shape or offset can be made. '
Why? Specifically, SizeOf is referred to as
C & lt; AClass & gt;
, but onB
orC & Edit
If I type a single normal type
C < T & gt;
and can define a single C # external declarationM (C>
), and then callM (C & LT; At & g;)
andM (c & lt; double>)
, I have a small and sweet interop solution but answered the answer, It appears that I Each structure has to be typed in a separate C # (although the generic headers can be provided in the heritage).
Generic forms are not supported in any interop scenario as a rule. If you try to martial a normal type or value, then both P / Attack and COM Interop will fail. So I hope that this scenario should be applied or unsupported because it is a martial-specific function.
Comments
Post a Comment