IntPtr to structure conversion

  • Thread starter Thread starter MichaelC
  • Start date Start date
M

MichaelC

Hi, all

Please help me to solve compilation error :

frmDeviceEnentsHandl.cpp(32) : error C2440: 'type cast' : cannot
convert from 'System::IntPtr' to 'DEV_BROADCAST_HDR *'

in next code :

void DManArrivedDeviceHandler::frmDeviceEnentsHandl::WndProc(Message*
m)
{
if( m->Msg == WM_DEVICECHANGE )
{
if( m->WParam == DBT_DEVICEARRIVAL )
{
DEV_BROADCAST_HDR *pNewDevice = (DEV_BROADCAST_HDR*)m->LParam;
if( pNewDevice && pNewDevice->dbch_devicetype ==
DBT_DEVTYP_DEVICEINTERFACE )
{
GetNewDeviceParams((DEV_BROADCAST_DEVICEINTERFACE*)pNewDevice);


Best reguards,
Michael
 
MichaelC,
Please help me to solve compilation error :

frmDeviceEnentsHandl.cpp(32) : error C2440: 'type cast' : cannot
convert from 'System::IntPtr' to 'DEV_BROADCAST_HDR *'

in next code :

void DManArrivedDeviceHandler::frmDeviceEnentsHandl::WndProc(Message*
m)
{
if( m->Msg == WM_DEVICECHANGE )
{
if( m->WParam == DBT_DEVICEARRIVAL )
{
DEV_BROADCAST_HDR *pNewDevice = (DEV_BROADCAST_HDR*)m->LParam;

Try here:
DEV_BROADCAST_HDR *pNewDevice = (DEV_BROADCAST_HDR*)m->LParam.ToPointer();

The LParam here is an IntPtr structure, so the ToPointer() method on it will
return a void* you can convert.
 
Back
Top