-
May 29th, 2013, 01:36 AM
#1
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.
-
May 29th, 2013, 02:31 AM
#2
Re: CreateInstance fails on xp
How does it fail?
Could you show your code?
Victor Nijegorodov
-
May 29th, 2013, 02:31 AM
#3
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...
-
May 29th, 2013, 02:48 AM
#4
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)
-
May 29th, 2013, 02:56 AM
#5
Re: CreateInstance fails on xp
It means:
80040154 error indicates REGDB_E_CLASSNOTREG, or "class not registered."
Victor Nijegorodov
-
May 29th, 2013, 03:58 AM
#6
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..?)
-
May 29th, 2013, 04:03 AM
#7
Re: CreateInstance fails on xp
RegDeleteValue -?
See also Registry Functions in MSDN.
Victor Nijegorodov
-
May 29th, 2013, 04:47 AM
#8
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.
-
May 29th, 2013, 05:09 AM
#9
Re: CreateInstance fails on xp
Originally Posted by ovidiucucu
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
-
May 29th, 2013, 05:14 AM
#10
Re: CreateInstance fails on xp
Originally Posted by VictorN
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
-
May 29th, 2013, 05:20 AM
#11
-
May 29th, 2013, 05:25 AM
#12
Re: CreateInstance fails on xp
Originally Posted by VictorN
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!
-
May 29th, 2013, 12:35 PM
#13
Re: CreateInstance fails on xp
Originally Posted by ovidiucucu
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)
-
May 29th, 2013, 01:57 PM
#14
Re: CreateInstance fails on xp
Originally Posted by 2kaud
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.
-
May 29th, 2013, 04:55 AM
#15
Re: CreateInstance fails on xp
Other possible replacement for RegDeleteKeyValue is SHDeleteValue function,
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|