Click here to Skip to main content
15,867,594 members

WINXP-SP3 - The specified program requires a newer version of Windows.

Ribhi Kamal asked:

Open original thread
It seems like I'm the only one on the plant (Earth) who is having this problem...

I wrote a very simple method which dynamically loads and executes RegCreateKeyExA and I get the following error from "GetProcAddress(Avapi32,RegCreateKeyExA)"
Error 1150. The specified program requires a newer version of Windows.


The same code works fine on Windows 7, so I went back to WINXP and opened advapi32.dll with notepad, and sure enough, RegCreateKeyExA was there.... what am I missing here :confused:

Here is the method:
UINT
regDyFunc::DyRegCreateKeyEx(HKEY hMainKey,
			   LPCTSTR lpSubKey,
			   PHKEY phkResult,
                           LPDWORD lpdwDisposition )
{
 // The type of the wanted function
 typedef UINT (CALLBACK* REGFUNCCreateKeyEx)( 	//LONG WINAPI RegCreateKeyEx(
  HKEY,	  //  __in        HKEY hKey,
  LPCTSTR,//  __in        LPCTSTR lpSubKey,
  DWORD,  //  __reserved  DWORD Reserved,
  LPTSTR, //  __in_opt    LPTSTR lpClass,
  DWORD,  //  __in        DWORD dwOptions,
  REGSAM, //  __in        REGSAM samDesired,
  LPSECURITY_ATTRIBUTES /*__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,*/,
  PHKEY,  //  __out       PHKEY phkResult,
  LPDWORD //  __out_opt   LPDWORD lpdwDisposition
 );

 REGFUNCCreateKeyEx regFuncCreateKeyEx; // Stores the wanted function
	
 long lResult = ERROR_SUCCESS; // Used to check for failure and return value

 // Verify parameters
 if (lpSubKey == NULL)
	lResult = ERROR_INVALID_ADDRESS;

 // Dynamically load the registry function
 if (lResult == ERROR_SUCCESS){
	regFuncCreateKeyEx =
              (REGFUNCCreateKeyEx)GetProcAddress(
                     hAvapi32,
                     (LPCSTR)"RegCreateKeyExA" );
        
	regDyFunc::csLastCall = "GetProcAddress(Avapi32,RegCreateKeyExA)";
	lResult = GetLastError();
 }
 
 // Execute the function
 if (lResult == ERROR_SUCCESS)
 {
	regDyFunc::csLastCall = "RegCreateKeyExA";
	lResult  = regFuncCreateKeyEx(
                                      hMainKey,
                                      lpSubKey,
                                      0,
                                      NULL,
                                      REG_OPTION_NON_VOLATILE,
                                      KEY_ALL_ACCESS,NULL,
                                      phkResult,
                                      lpdwDisposition);

 }
	
 return lResult;
}



And the function to load the library:
C#
bool
regDyFunc::openModules(void)
{
    bool bRet = true;
    regDyFunc::hAvapi32 = LoadLibrary("Advapi32");
    if (regDyFunc::hAvapi32 == NULL){
        _tprintf(_T("Unable to load Advapi32\n"));
        bRet = false;
    }
    if (bRet){
        // Always try to load all modules
        regDyFunc::hKtmW32 = LoadLibrary("KtmW32");
        //Give an error only if its Vista or later
        if ((regDyFunc::hKtmW32 == NULL) && (regDyFunc::Is_Vista_or_Later())) {
            _tprintf(_T("Unable to load KtmW32\n"));
            bRet = false;
        }
    }
    return bRet;
}


Thanks in advance
Tags: C++

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900