Premise Need help coding a native Driver. One bug has me baffled.

Motorola Premise

123

Senior Member
Hopefully some of the Premise gurus are still lurking ...

I've created a native driver for the USBUIRT that works fine provided you don't attempt to create a second instance of it! The moment you do, a "Debug Assertion Failed!" message appears and points to a line within "atlcomcli.h". If I enter debug mode, the offending line is ATLASSERT in this snippet:

Code:
__checkReturn HRESULT CoCreateInstance(__in REFCLSID rclsid, __in_opt LPUNKNOWN pUnkOuter = NULL, __in DWORD dwClsContext = CLSCTX_ALL) throw()
	{
		ATLASSERT(p == NULL);
		return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&p);
	}

My C++ knowledge is insufficient to understand what's going on there ... but I do recognize CoCreateInstance and I use it to create a Timer object within OnBrokerAttach. I copied the technique from the source code for the ALC and Panja drivers.

Code:
// Set up timer
if ( SUCCEEDED(hr = m_DelayTimer.CoCreateInstance(CLSID_PremiseTimer)) )
{
m_DelayTimer->SetCallback(DELAY_TIMER_ID, this);
m_DelayTimerRunning = FALSE;
}

If I comment out the code above, the resulting USBUIRT driver allows for multiple instances without complaint. If I include the line with "m_DelayTimer.CoCreateInstance", only one instance of a USBUIRT driver is tolerated. I'm stumped. What's preventing the creation of mulitple instances of a timer?
 
I suspect you are calling m_DelayTimer.CoCreateInstance more than once on the same instance of m_DelayTimer. The first call leaves m_DelayTimer's private member variable p not NULL, thus the second call fails the assertion.

For any given instance of a CComPtr, you should normally call CoCreateInstance only once unless you first call the CComPtr's Release to release its internal reference to the underlying COM object, or perhaps Detach to transfer the reference if you're doing something a bit more complex.

If this doesn't help you find the problem, then if you show a bit more of your code I might be able to help you find the problem.

Frank
 
I suspect you are calling m_DelayTimer.CoCreateInstance more than once on the same instance of m_DelayTimer. ...

Thanks for shedding light on this problem! I didn't understand why the "p=NULL" assertion failed until your explanation that it may already be set by a previous call to CoCreateInstance. I defined m_DelayTimer as a Global variable. The first instance of my CUUIRT driver class creates a PremiseTimer, using m_DelayTimer, and then the second instance of CUUIRT attempts to do it again. Oops! m_DelayTimer shouldn't be Global but a member of the CUUIRT class.

Therein lies the core problem ... my limited knowledge of C++. To put things into perspective, the last time I coded in C, Ronald Reagan was in the White House. I recall someone discussing Bjarne Stroustrup and C++ at about the time I left software engineering and entered the world of IT. I didn't know what an "assertion" was until I encountered it a few days ago. But, I'm learning ...

The USBUIRT's API specifies several functions for communicating with the device via "uuirtdrv.dll" (open/close, get firmware version, etc). There are two important callback functions, one that is called whenever the USBUIRT receives an IR signal and another when it is in Learning mode. My best guess is that I should define these callbacks as methods of the CUUIRT class. I've tried but failed. So I've defined them as functions that interact with CUUIRT via Global variables ... an expedient but limited strategy!

I'm going to try a few more things before I take advantage of your generous offer to review the source code. Thanks again!
 
I was curious- where do you get the SDK (libraries and docs) for the USBUIRT? Do you know if these are the same devices that ship with PCs designed for Windows Media Center?
 
For whatever reason, Jon Rhees doesn't post the SDK and directs people to request it via email (support at usbuirt.com). Alternately, PM me with your email address and I'll forward it to you. It includes examples, in C++ and VB6, for communicating with a USB-UIRT via uuirtdrv.dll.

Regarding PCs with Windows Media Center, unfortunately, I don't know what kind of IR devices are included.
 
Back
Top