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
  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
    Hanover Germany
    Posts
    20,395

    Re: CreateInstance fails on xp

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

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  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
    Hanover Germany
    Posts
    20,395

    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
    Hanover Germany
    Posts
    20,395

    Re: CreateInstance fails on xp

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

  8. #8
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  9. #9
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: CreateInstance fails on xp

    Other possible replacement for RegDeleteKeyValue is SHDeleteValue function,
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    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
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    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
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  14. #14
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  15. #15
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

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
  •  





Click Here to Expand Forum to Full Width

Featured