Skip to main content
GameDev.net gamedev.net
🔒 Locked

CoCreateInstance returns strange value

Started by peter86 Sep 26, 2002 at 3:41 PM 4 replies 550+ views
Original Post
peter86
peter86
The returnvalue I get from CoCreateInstance dosen´t match with any of it´s return values. Is anything wrong with my switch-statement or how could or how can happend?
  
hr = CoCreateInstance(CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC, IID_IDirectMusicPerformance8, (void**) &g_pMusicPerformance);
	
if(FAILED(hr))
{
	switch (hr)
	{
	case REGDB_E_CLASSNOTREG:
		DISPLAYMSG("REGDB_E_CLASSNOTREG");
		return 0;
			
	case CLASS_E_NOAGGREGATION:
		DISPLAYMSG("CLASS_E_NOAGGREGATION");
		return 0;
		
	default:
		DISPLAYMSG("Unknown error!");
		return 0;
	}
}
  
coder_x
coder_x
Have you called CoInitialize before your call to CoCreateInstance ?
peter86
peter86
Yes, I´ve called CoInitialize before.
S1CA
S1CA
So what is the return value then ? (it''d be kinda helpful if you told us! ).

Preferably in hexadecimal.

...So we can take off the severity bits, isolate the facility code and look the error code itself up in winerror.h to tell you what you''re doing wrong.

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
peter86
peter86
I couldn´t think of that I hadn´t called CoInitialize, but I had not made that call. Sorry for the wrong answear before.
Shannon Barber
Shannon Barber
Why don''t you add the error for ''not coinitialized'' to your switch?

I use a couple of macros, and built a library for my error cooking function:

  
#define HR2StringCase(Case_)\
case Case_:\
strcpy(szHR, #Case_);\
break;

void __cdecl HR2String(HRESULT hr, char* szHR)
{
switch(hr)
{
HR2StringCase(S_OK)
HR2StringCase(S_FALSE)

HR2StringCase(REGDB_E_CLASSNOTREG);

HR2StringCase(E_FAIL)
HR2StringCase(E_NOTIMPL)
HR2StringCase(E_INVALIDARG)
HR2StringCase(E_POINTER)
HR2StringCase(E_NOINTERFACE)
//on & on...

}
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.