IntPtr to structure conversion

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
 
T

Tomas Restrepo \(MVP\)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top