Hi,
I encountered a problem when using RegOpenKeyEx with the OEM
unidriver from Win2K DDK. The RegOpenKeyEx failed with error code 2 when the
unidriver is run on WinXP. No such problem when run on Win2K. Does anyone
has any idea why this happens?
Detail Description:
The following codes are inserted at the beginning of the sample
unidriver program from Microsoft Win2K DDK under
/Win2KDDK/src/print/oemdll/oemui/devmode.cpp. Opening of Registry Key for
reading is not always successful on WinXP when printing to a printer with
“Advanced Printing Features” enabled. No such problem on Win2K. Also no such
problem if print to file or with “Advanced Printing Features” disabled on
WinXP.
BOOL ConvertOEMDevmode(PCOEMDEV pOEMDevIn, POEMDEV
pOEMDevOut)
{
FILE *stream;
stream = fopen(“C:\log.txt”, “a”);
fprintf(stream, “\n%s”, “ConvertOEMDevmode: Testing
RegOpenKeyEx”);
HKEY hKey = NULL;
long lResult;
lResult = RegOpenKeyEx(HKEY_CURRENT_USER, // handle to
open key
_T(“SOFTWARE\Test”), // subkey name
0,
// reserved
KEY_READ,
// security access mask
&hKey);
// handle to open key
if (lResult == ERROR_SUCCESS)
{
fprintf(stream, “\nSuccessful.\n”);
// Done with the key. Close it.
RegCloseKey(hKey);
}
else
{
fprintf(stream, “\nFailed to open registry key!
Code is %ld (0x%lx)\n”, lResult);
}
fclose(stream);
…
}
Steps:
- Create the registry key \HKEY_CURRENT_USER\SOFTWARE\Test using
regedit. - Choose -> from Word Pad.
3. Select the OEM driver.
4. Click on the button. The Printer Preferences panel
appears.
5. Select the Advanced button.
6. Make sure that the Advanced Printing Features is Enabled.
7. Print the word pad document to a printer.
8. The log file is store in c:\log.txt.
Results: As shown below, RegOpenKeyEx is not always successful. It
fails to open registry key with error code 2 in some cases.
ConvertOEMDevmode: Testing RegOpenKeyEx
Successful.
ConvertOEMDevmode: Testing RegOpenKeyEx
Successful.
ConvertOEMDevmode: Testing RegOpenKeyEx
Failed to open registry key! Code is 2
(0xfdeb0c)
ConvertOEMDevmode: Testing RegOpenKeyEx
Failed to open registry key! Code is 2
(0xfdeb0c)
ConvertOEMDevmode: Testing RegOpenKeyEx
Successful.
…
Best Regards,
TGH