Failing to initialize COM

This is a discussion on Failing to initialize COM within the Windows Programming forums, part of the Platform Specific Boards category; Alright so I am attempting to initialize direct music via the COM interface exactly as it appears on MSDN. My ...

  1. #1
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540

    Failing to initialize COM

    Alright so I am attempting to initialize direct music via the COM interface exactly as it appears on MSDN. My function looks like this:

    Code:
    HRESULT CDirectX::initDirectSound (HWND hwnd) {
    
    	_Performance = NULL;
    	_Loader = NULL;
    
    	
    	CoInitialize(NULL);
    		
    	CoCreateInstance(CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC, IID_IDirectMusicLoader8, (void**) &_Loader);
    	if(_Loader = NULL)
    		return E_FAIL;
    	
    	CoCreateInstance(CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC, IID_IDirectMusicPerformance8, (void**)& _Performance);
    	
    	if(_Performance = NULL)
    		return E_FAIL;
    
    	_Performance->InitAudio(NULL, NULL, hwnd, DMUS_APATH_SHARED_STEREOPLUSREVERB, 64, DMUS_AUDIOF_ALL, NULL);
    	
    	_Loader->SetSearchDirectory (GUID_DirectMusicAllTypes, 
    		                         L"C:\\Documents and Settings\\Andrew Hunter\\My Documents\\My Music",
    								 FALSE );
    	return S_OK;
    }
    The problem is that _Loader never appears to become initialized, aka the program halts and the value of _Loader is NULL. Has anyone seen this before?

  2. #2
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    I have run the D3D debug and it turns out that Loader is NULL, IDirectMusicPerformance is NULL, IUnknown is null and through the vfptr all values beneath indicate CXX0030:Expression cannot be evaluated.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    95
    if(_Loader = NULL)

    You're confusing the = and == operators

    This sets _Loader to NULL then evaluates whether that's true. Which isn't what you want.

    You want

    if(_Loader == NULL)

    Same applies for the if(_Performance = NULL) line.

  4. #4
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    I can't believe I did that!!!!! Sometimes I guess you just get to into a project. Thanx plenty.

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    95
    BTW, an easy way to not use = when you want == is to write (completely equivalently) it like this:

    if (NULL == _Loader)

    Then if you wrote

    if (NULL = _Loader)

    you'd get a compiler error, rather than weird behaviour at runtime.

  6. #6
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    All right I fixed the above mentioned assignment problem (I am an idiot - thx again azteched) unfortunately I am still receiving an error when I attempt to load the file. This is the function I am using:

    Code:
    if(FAILED(_Loader->LoadObjectFromFile (CLSID_DirectMusicSegment,
    										   IID_IDirectMusicSegment8,
    										   szfileName,
    										   (void**)& _Segment)))
    	   return E_FAIL;
    Unfortunately the pointers are as described above with null values. _Loader doesn't seem to ever get anything put into it. Any ideas?

  7. #7
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Ok it still isn't initializing. this is the line I am using:

    Code:
    CoCreateInstance(CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC, IID_IDirectMusicLoader8, (void**) _Loader);
    Any ideas. The COM object isn't being found I guess?

  8. #8
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You've lost the & at some point.
    Code:
    CoCreateInstance(CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC, IID_IDirectMusicLoader8, (void**) &_Loader);
    Last edited by anonytmouse; 12-22-2004 at 03:56 PM.

  9. #9
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    anonytmouse thank you. I must have dropped it off when I was moving my code around in the source file. Greatly appreciated all. I will try not to be soo stupid in the future.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-10-2009, 03:20 AM
  2. how to initialize char *
    By vignesh in forum C Programming
    Replies: 3
    Last Post: 03-30-2009, 02:17 AM
  3. initializes all components of failing to false
    By romeoz in forum C++ Programming
    Replies: 21
    Last Post: 08-01-2003, 10:30 PM
  4. using constructor to initialize data
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 03-19-2002, 08:55 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21