CreateInstance fails on xp
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: CreateInstance fails on xp

  1. #1
    Join Date
    Apr 2013
    Posts
    17

    CreateInstance fails on xp

    i created an com client that try to create com server with the command CreateInstance.
    at win 7 it works fine (both 32 and 64 bit).
    but with xp it fails.
    someone know what is the problem?
    i created the app with win 7 - 64 bit.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,421

    Re: CreateInstance fails on xp

    How does it fail?
    Could you show your code?
    Victor Nijegorodov

  3. #3
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,027

    Re: CreateInstance fails on xp

    1. CreateInstance is a function, not a command.
    2. With no other details, nobody can guess what's your problem. Not even looking in a crystal ball...
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  4. #4
    Join Date
    Apr 2013
    Posts
    17

    Re: CreateInstance fails on xp

    MyBlLib::IMyServPtr m_spSrv;
    hr = m_spSrv.CreateInstance(MyBlLib::CLSID_MyServ);
    hr return with -2147221164

    with WIN 7 it works fine (both 32 and 64 bit)

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,421

    Re: CreateInstance fails on xp

    It means:
    80040154 error indicates REGDB_E_CLASSNOTREG, or "class not registered."
    Victor Nijegorodov

  6. #6
    Join Date
    Apr 2013
    Posts
    17

    Re: CreateInstance fails on xp

    thanx Victor, you right.
    the problem was with function RegDeleteKeyValue that win xp doesn't support.
    do you know how can i delete registry key value at win xp? (didn't find it at google..?)

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,421

    Re: CreateInstance fails on xp

    RegDeleteValue -?
    See also Registry Functions in MSDN.
    Victor Nijegorodov

  8. #8
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,027

    Re: CreateInstance fails on xp

    Unlike RegDeleteValue, RegDeleteKeyValue has an extra argument, lpSubKey.
    Indeed, it requires at least Windows Vista / Server 2008.
    If your target system is Windows XP and older, replace RegDeleteKeyValue with RegOpenKeyEx (to open the sub-key), followed by RegDeleteValue.
    And don't forget to handle errors, to avoid further misleading situations.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  9. #9
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,027

    Re: CreateInstance fails on xp

    Other possible replacement for RegDeleteKeyValue is SHDeleteValue function,
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,421

    Re: CreateInstance fails on xp

    Quote Originally Posted by ovidiucucu View Post
    If your target system is Windows XP and older, replace RegDeleteKeyValue with RegOpenKeyEx (to open the sub-key), followed by RegDeleteValue.
    And don't forget to handle errors, to avoid further misleading situations.
    And don't forget to call RegCloseKey to close the key opened by RegOpenKeyEx.
    Victor Nijegorodov

  11. #11
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,027

    Re: CreateInstance fails on xp

    Quote Originally Posted by VictorN View Post
    And don't forget to call RegCloseKey to close the key opened by RegOpenKeyEx.
    Of course, thanks Victor!

    One additional note: if your target OS is Windows XP and later, to avoid using newer functions which are not supported on XP, go to targetver.h or stdafx.h (depending on VS version) and set WINVER and _WIN32_WINNT values to 0x0501.

    Example

    Code:
    #ifndef WINVER              // Allow use of features specific to Windows XP or later.
    #define WINVER 0x0501       // Change this to the appropriate value to target other versions of Windows.
    #endif
    
    #ifndef _WIN32_WINNT        // Allow use of features specific to Windows XP or later.                   
    #define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
    #endif
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,421

    Re: CreateInstance fails on xp

    Quote Originally Posted by ovidiucucu View Post
    Of course, thanks Victor!
    Ovidiu! I wrote it not for you (cause I know that you do know it!) but for OP!
    Victor Nijegorodov

  13. #13
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,027

    Re: CreateInstance fails on xp

    Quote Originally Posted by VictorN View Post
    Ovidiu! I wrote it not for you (cause I know that you do know it!) but for OP!
    I know that you know that I know it. Good to know for everybody. Thanks again!
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  14. #14
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,460

    Re: CreateInstance fails on xp

    Quote Originally Posted by ovidiucucu View Post
    One additional note: if your target OS is Windows XP and later, to avoid using newer functions which are not supported on XP, go to targetver.h or stdafx.h (depending on VS version) and set WINVER and _WIN32_WINNT values to 0x0501.

    Example

    Code:
    #ifndef WINVER              // Allow use of features specific to Windows XP or later.
    #define WINVER 0x0501       // Change this to the appropriate value to target other versions of Windows.
    #endif
    
    #ifndef _WIN32_WINNT        // Allow use of features specific to Windows XP or later.                   
    #define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
    #endif
    But surely if you do this using guards and if WINVER/_WIN32_WINNT are already defined you may still compile code for functions not supported on XP? Wouldn't it be better that if WINVER or _WIN32_WINNT are already defined, to undefine these and then explicity define them to be the required values like this

    Code:
    #pragma once
    
    #ifdef WINVER
    	#undef WINVER
    #endif
    #define WINVER 0x0501
    
    #ifdef _WIN32_WINNT
    	#undef _WIN32_WINNT
    #endif
    #define _WIN32_WINNT WINVER
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  15. #15
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,027

    Re: CreateInstance fails on xp

    Quote Originally Posted by 2kaud View Post
    But surely if you do this using guards and if WINVER/_WIN32_WINNT are already defined you may still compile code for functions not supported on XP? Wouldn't it be better that if WINVER or _WIN32_WINNT are already defined, to undefine these and then explicity define them to be the required values like this

    Code:
    #pragma once
    
    #ifdef WINVER
    	#undef WINVER
    #endif
    #define WINVER 0x0501
    
    #ifdef _WIN32_WINNT
    	#undef _WIN32_WINNT
    #endif
    #define _WIN32_WINNT WINVER
    Generally yes. Particularly, not really necessary if placed in stdafx.h (or targetver.h) and use precompiled headers. Anyway, I've shown the code generated by the wizard.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center