2

I want to read Windows Contacts (Windows 7 address book) but the CoGetClassObject returns an error and I don't know why ?

My code is :

    IClassFactory* pFactory = NULL;
HRESULT rc;
rc = CoGetClassObject(CLSID_Contact,CLSCTX_INPROC_SERVER,NULL,IID_IClassFactory, (void **) &pFactory);
wprintf( L"Error : %d\n",rc);

It returns "Error : -2147221008"

If someone had a suggestion for me it would be wonderful !

Denis

P. S. Details : Based on http://msdn.microsoft.com/en-us/library/ms735866.aspx (which is quite bugged) I tried to do it myself but function CoGetClassObject returns an error and I don't know why ?

Denis BUCHER
  • 310
  • 4
  • 16

1 Answers1

5

This number is 0x800401F0 when printed as a hex number

This error translates to CoInitialize has not been called.

Call CoInitialize before calling any COM code

If you have visual studio, you can find the error lookup tool under the Tools menu for future use

Attila
  • 28,265
  • 3
  • 46
  • 55
Andrew Brock
  • 1,374
  • 8
  • 13
  • In between that's what I found : after some research on the specific error converted to binary it seems to be 8004100A. http://groups.google.com/group/microsoft.public.win32.programmer.ole/browse_thread/thread/221a258a85f652dd/790a6024acac439c%3Fq%3D%2522%2BGuastaferri%2522%23790a6024acac439c&ei=iGwTS6eaOpW8Qpmqic0O&sa=t&ct=res&cd=13&source=groups&usg=AFQjCNGX4sexZRyNWAMRzlcPuQBUXbzz2A Therefore I added this : rc = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); Now at least I have no errors anymore but nothing happens. I think I should post another separate question. – Denis BUCHER Apr 29 '12 at 12:00
  • OK I asked the new question under http://stackoverflow.com/questions/10372035/trying-to-read-windows-7-contacts-doesnt-work – Denis BUCHER Apr 29 '12 at 12:13
  • By the way, there is no error lookup tool under the Tools menu of my Visual Studio (MS VS C++ 2010 Express) – Denis BUCHER Apr 29 '12 at 12:14
  • @DenisBUCHER The error lookup tool may only be part of the ultimate version which am using (and possibly professional) of visual studio. In most cases googling the error code will turn up what you want anyway. – Andrew Brock Apr 29 '12 at 12:17