On Sun, 5 Mar 2006 14:01:06 +0100, "Bruno van Dooren"
<br**********************@hotmail.com> wrote:
error C4368: cannot define 'CustomType' as a member
of managed 'WrapperClass': mixed types are not supported
I found the answer here:
http://msdn2.microsoft.com/en-us/library/xhfb39es.aspx
in C++/CLI you cannot embed native types in managed types, but you can use
pointers to them.
a solution for your problem could be to use a pointer for which you
dynamically allocate the space in your constructor, instead of embedding
your type directly. obviously you have to delete the pointer in the
destructor of your ref class.
I was afraid you were going to say that, Bruno. <g> I had come to the
same conclusion but was hoping I was missing something. There are so
many of those custom types that it's probably not worthwhile to go
with the conventional C++/CLI approach at all.
The main point of the inner unmanaged wrapper class (in the old
Managed Extensions version) was to isolate the awkward data types.
Requiring allocs for all those tiny structs would make things worse
rather than better, and would leave the managed code interspersed with
allocs and frees.
I guess I'm back to something like the old Managed Extensions
approach. I still may be able to move forward a tiny bit. This time
I could use the /cli compile switch, with the inner wrapping class
flagged as #pragma unmanaged, isolating the handles and awkward data
types. I think that will remove some of the ugly Managed Extensions
__whatever, leaving the code close to native. The outer class could
be a straight 'ref class' in managed code, calling into the inner
native class.
This would still look like ME code though, and would require two
function calls to get through the managed/unmanaged wrappers to the
inner DLL. I've found that to be error-prone. Still better than a
zillion allocs and frees.
I was looking forward to C++/CLI coming into its own, but I guess I
can't make use of it.
Another related question: Is there any way to use different compile
flags (/cli vs /cli:old....) on different files in one project?