marshalling abstract pointers

    Date: 03/09/06 (C Sharp)    Keywords: no keywords

    In C++, you can return pointers to base types to be casted into derived types safely, even if said base type is abstract.

    However, there is a slight problem when you need to convert that abstract pointer into something usable in C#. Here's the rundown of what I think is happening.

    Firstly, we have an unmanaged function returning a pointer to an abstract base class. That pointer, and its contents, exist on the unmanaged heap. Next, I use Marshal::PtrToStructure, attempting to cast the pointer into the base type of the corresponding managed hierarchy. The PtrToStructure method tries to create a new object on the managed stack, and throws an exception indicating that instantiating an abstract class is right out.

    How can I get this pointer converted to a reference that I can use?

    DC

    Source: http://community.livejournal.com/csharp/51501.html

« datagridviewcomboboxcolumn... || UserControl with ComboBox »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home