From: DHarray on 6 Nov 2006 04:41 Hello, I want to enumerate my Band Objects with the use of IBandSite because i need a special band id for my application: _COM_SMARTPTR_TYPEDEF(IBandSite, __uuidof(IBandSite)); CoInitialize(NULL); // ... IBandSitePtr bs; bs.CreateInstance(CLSID_TrayBandSiteService); if (bs) { LONG count = bs->EnumBands(UINT(-1), 0); printf("%i",count); // -2147023116 } // ... CoUninitialize(); Any idea why EnumBands returns a wrong value? MSDN said that the first value has to be "-1" to get the number of bands. thanks for any help
From: Stuart Redmann on 6 Nov 2006 06:09 DHarray wrote: > Hello, > > I want to enumerate my Band Objects with the use of IBandSite because i > need a special band id for my application: > > _COM_SMARTPTR_TYPEDEF(IBandSite, __uuidof(IBandSite)); > > CoInitialize(NULL); > > // ... > > IBandSitePtr bs; > bs.CreateInstance(CLSID_TrayBandSiteService); > if (bs) > { > LONG count = bs->EnumBands(UINT(-1), 0); Try: DWORD Dummy; HRESULT hr = bs->EnumBands ((UINT)-1, &Dummy); and add if (!SUCCEEDED (hr)) { // Some error handling. } > > printf("%i",count); // -2147023116 Use the errlook tool that ships with Visual Studio to look up this error code. It will tell you that you have passed a NULL pointer for a top-level pointer, which is not allowed. > } > > // ... > > CoUninitialize(); > > Any idea why EnumBands returns a wrong value? MSDN said that the first > value has to be "-1" to get the number of bands. thanks for any help Though the second parameter to EnumBands will be ignored, you cannot pass a NULL pointer to the method (the call is made through a proxy which check that all top-level pointers are valid). This example shows that even Microsoft can create really, really awful APIs. It would have been quite easy to introduce a method HRESULT IBandSite::GetNumberOfBands ([out, retval] int* RetVal), instead of this ugly 'When you pass a minus one as _unsigned int_ parameter!!!, you'll get this, else you'll get that humdrum. Take this as an example of how to _not_ create an API. Regards, Stuart
|
Pages: 1 Prev: ShellExecute thows First-chance exception Next: Linker Warning in manifest file |