Why id pin_ptr is causing cannot instantiate abstract class error?

  • Thread starter Thread starter Bruce
  • Start date Start date
B

Bruce

public ref class GpsDevice abstract
{

/* Please note GarXface4::GpsDevice* is in a different namespace
from this one and GarXface4::GpsDevice is an unmanaged class */
virtual GarXface4::GpsDevice* GetDevice() = 0;


};

I have a couple of classes inherited from that class.

public ref class GpsUsbDevice : public GpsDevice
{


/* Please note GarXface4::GpsDevice* is in a different namespace
from this one and GarXface4::GpsDevice is an unmanaged class */
GarXface4::GpsDevice* GetDevice()
{
return m_pDevice;
}

private:

GarXface4::GpsComPortDevice* m_pDevice; // GarXface4::GpsDevice is
the base class of this class



}

public ref class GpsComPortDevice : public GpsDevice
{

/* Please note GarXface4::GpsDevice* is in a different namespace from
this one and is an unmanaged class */
GarXface4::GpsDevice* GetDevice()
{
return m_pDevice;
}

private:

GarXface4::UsbDevice* m_pDevice; // GarXface4::GpsDevice is the base
class of this class


}


MyClass::CtreatDevice(GpsDevice^ p)
{
/* Please note GarXface4::GpsDevice* is in a different namespace
from this one and GarXface4::GpsDevice an unmanaged class */
GarXface4::GpsDevice pin_ptr *p = gpsDevice->GetDevice();


}


The compile error occurs on this line:

GarXface4::GpsDevice pin_ptr *p = gpsDevice->GetDevice();

and it seems to be caused by the pin_ptr. If I remove it, it works fine.
GarXface4::GpsDevice is an unmanaged class. Do I still need the
pin_ptr in 2005? Do pointers to unmanaged classes now automatically get
pinned?
 
The compile error occurs on this line:
GarXface4::GpsDevice pin_ptr *p = gpsDevice->GetDevice();
and it seems to be caused by the pin_ptr. If I remove it, it works fine.
GarXface4::GpsDevice is an unmanaged class. Do I still need the pin_ptr
in 2005? Do pointers to unmanaged classes now automatically get pinned?

Hi,

If GetDevice returns an unmanaged pointer (i.e. its target is located on a
native heap) there is no need to pin it. It will never move unless you make
it. I think you cannot pin something that is not located on the managed
heap.

But your pin_ptr syntax is wrong anyway. see here
http://msdn2.microsoft.com/en-us/library/1dz8byfh.aspx
for info on how to use pin_ptr.

Blessed winter solstice to you too.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
Back
Top