GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Jan-2007, 06:40
Futterama Futterama is offline
New Member
 
Join Date: Jan 2007
Posts: 1
Futterama is on a distinguished road

How to get a handle to a derived class?


Hello forum,

I have an MFC dialog application with a USB class of my own.

I would like to be able to receive device notifications in the USB class, but the RegisterDeviceNotification needs a handle for the recipient of the notifications. The only handle I can come up with is the handle for the main dialog class.

So how do I get the handle for my USB class, so that it's the USB class' MESSAGE_MAP that receives the notification?

The call to RegisterDeviceNotification looks like this at the moment:

CPP / C++ / C Code:
DeviceNotificationHandle = RegisterDeviceNotification(
this,
&DevBroadcastDeviceInterface,
DEVICE_NOTIFY_WINDOW_HANDLE);

The call is made from within the USB class, but the member function containing the call to RegisterDeviceNotification is called from the main dialog class' OnInitDialog().

I would somehow like to replace "this" with the handle for the USB class.

The USB class object is created like this:

CPP / C++ / C Code:
USBclass USBclassObj;

I'm not sure I have provided enough background information on how to get the handle, so please ask for more if nessasary.

I hope you can help me. Thanks.


Regards,
Futterama
Last edited by LuciWiz : 26-Jan-2007 at 12:40. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 29-Jan-2007, 10:47
Umesh Bansal Umesh Bansal is offline
New Member
 
Join Date: Jan 2007
Posts: 5
Umesh Bansal is on a distinguished road

Re: How to get a handle to a derived class?


HI,
Is your class is derived from CDialog.
// class USBclass : public CDialog

If yes then u can easily see that CDialog is internally derived from CWnd, which is having a member variable m_hwnd that contains handle to dialog.
For modeless dialog u have to initializes the value m_hwnd by calling Create function of Cwnd class.

your class Cntr will look like something this

USBclass() : CDialog(...)
{
Create(.....) // Just see parameters which has to be passed.
}

After calling create function , your class members will get initilaized and you can get the vlaue of m_hwnd.

USBclass USBclassObj;

You can use value like this
USBclassObj.m_hwnd;

For mOdal dialog instead of calling Create function you have to call another fn. See MSDN for help.

Regards,
Umesh Bansal.
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard drive/CPU Diagnoses Issues binarybug Computer Hardware Forum 1 22-Jan-2007 20:23
Box Class, need help again :( TransformedBG C++ Forum 7 13-Nov-2006 16:11
a tester class and then some. postage Java Forum 1 06-May-2006 16:48
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 21:30
Error C2146: syntax error : missing ',' before identifier 'C4' mattchew008 C++ Forum 2 19-Dec-2004 07:06

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:15.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.