11-30-2009 04:21 AM
I want to instantiate NI Measurement Studio controls (such as CNiButton) inside my application inside a class which shall be comoon for all controls (MFC and NI), thus being derived from CWnd.
Inside this class I am in fact able to instantiate such a control by calling
CreateControl("{D940E4BE-6079-11CE-88CB-0020AF6845F6}", "*",
WS_VISIBLE | WS_CHILD | WS_BORDER,
CRect(10, 10, 50, 30),
m_pParent,
7654);
where m_pParent is a dialog window. This will display a CNiButton inside the dialog.
The problem is now that I cannot access any methods of CNiButton.
Attempts like CNiButton *button = dynamic_cast<CNiButton *>(this) fail.
Further attempts with SubclassDlgItem fail, too.
Probably GetControlUnknown() could solve the problem but I do not know how to handle this and don't know which parameters to pass to QueryInterface().
What can I do? Any hint is welcome.
Thank you in advance.
Michael
12-01-2009 01:23 AM
12-01-2009 01:24 AM
Again, so that everyone can read it:
Some more information about my problem (btw, I build my application using MSDEV 6.0 SP6)
I tried this (inside a class which is derived from CWnd):
(...)
_DCWButton_CI *p = NULL;
CreateControl("{D940E4BE-6079-11CE-88CB-0020AF6845F6}", // CLSID for CWButton
"*",
WS_VISIBLE | WS_CHILD | WS_BORDER,
CRect(10, 10, 50, 30),
m_pParent,
7654);
LPUNKNOWN lu = this->GetControlUnknown(); // this works and gets a reasonable pointer
HRESULT result= lu->QueryInterface(IID__DCWButton_CI, (void **)&p); // THIS FAILS! p is always NULL
Any idea? What is wrong.
Thank you, best regards,
Michael
12-08-2009 09:42 AM
Hi Michael,
here are a few links that you may find helpful. It seems that they are trying to do about the same thing there.
Can I create instances of CWxxx objects?
http://forums.ni.com/ni/board/message?board.id=230&message.id=1886&requireLogin=False
http://digital.ni.com/public.nsf/websearch/BFF489FE87875A3986256403006F5ECD?OpenDocument
http://sine.ni.com/devzone/cda/epd/p/id/3788
I hope that this helps.
Best regards,