Click here to Skip to main content
15,884,537 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: MFC example Pin
CPallini15-Oct-08 21:56
mveCPallini15-Oct-08 21:56 
GeneralRe: MFC example Pin
BobInNJ16-Oct-08 4:44
BobInNJ16-Oct-08 4:44 
QuestionEnvironment Variables Pin
jpyp15-Oct-08 11:47
jpyp15-Oct-08 11:47 
AnswerRe: Environment Variables Pin
Mark Salsbery15-Oct-08 13:30
Mark Salsbery15-Oct-08 13:30 
GeneralRe: Environment Variables Pin
jpyp16-Oct-08 8:26
jpyp16-Oct-08 8:26 
GeneralRe: Environment Variables [modified] Pin
Mark Salsbery16-Oct-08 9:11
Mark Salsbery16-Oct-08 9:11 
GeneralRe: Environment Variables Pin
jpyp16-Oct-08 10:15
jpyp16-Oct-08 10:15 
GeneralRe: Environment Variables [modified] Pin
Mark Salsbery16-Oct-08 10:27
Mark Salsbery16-Oct-08 10:27 
What compiler are you using?

This line alone won't compile:

LPDWORD pKeyType = REG_SZ; <-- error C2440: 'initializing' : cannot convert from 'int' to 'LPDWORD'

There's several problems
HKEY hMyKey;
long lResult;
LPDWORD pKeyType = REG_SZ;   <code><-- wrong data type - should be a DWORD
It's also an OUT variable (if used correctly) so initializing it is pointless</code>
LPDWORD pKeySize = 0;  <code><-- wrong data type</code>
char* strKeyName = "SSSRights";
char* strKeyVal = "\0";   <code><-- You need to actually allocate space for the returned characters  
Had the query actually succeeded, it most likely would have crashed 
trying to write data to a const character array of length 1.</code>


jpyp wrote:
Why do I need the first call to RegQueryValueEx? What does it do?


It sets KeySize to the number of BYTES required to store the returned string.
I use that value to know how big the buffer needs to be, which I allocate on
the next line.

You could have just allocated an arbitrary number of bytes, but
you'd get a truncated string if the registry entry was longer than your buffer.
The function is capable of returning the necessary buffer size, so that's the
proper way to do it.

jpyp wrote:
Why does the first call fail when I provide a buffer instead of NULL?


Your incorrect use of LPDWORD pKeySize = 0; effectively reults in passing a NULL pointer as the
lpcbData parameter in the RegQueryValueEx() call. That is not allowed - the function
needs to know how big of a buffer it has to return data in and also needs to be able
to set the actual number of bytes placed in the buffer.

Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

modified on Thursday, October 16, 2008 4:35 PM

GeneralRe: Environment Variables Pin
jpyp16-Oct-08 10:52
jpyp16-Oct-08 10:52 
GeneralRe: Environment Variables Pin
Mark Salsbery16-Oct-08 11:03
Mark Salsbery16-Oct-08 11:03 
QuestionWeird error... Pin
Megidolaon15-Oct-08 11:08
Megidolaon15-Oct-08 11:08 
AnswerRe: Weird error... PinPopular
led mike15-Oct-08 11:32
led mike15-Oct-08 11:32 
GeneralRe: Weird error... Pin
Megidolaon15-Oct-08 11:37
Megidolaon15-Oct-08 11:37 
GeneralRe: Weird error... Pin
CPallini15-Oct-08 21:51
mveCPallini15-Oct-08 21:51 
QuestionRe: Weird error... Pin
David Crow15-Oct-08 17:29
David Crow15-Oct-08 17:29 
Questionautomatically click a button in another application Pin
Russell'15-Oct-08 9:34
Russell'15-Oct-08 9:34 
QuestionRe: automatically click a button in another application Pin
David Crow15-Oct-08 10:57
David Crow15-Oct-08 10:57 
AnswerRe: automatically click a button in another application Pin
Russell'15-Oct-08 11:28
Russell'15-Oct-08 11:28 
GeneralRe: automatically click a button in another application Pin
Russell'15-Oct-08 11:57
Russell'15-Oct-08 11:57 
QuestionSpin Control Pin
WayneK10015-Oct-08 9:03
WayneK10015-Oct-08 9:03 
AnswerRe: Spin Control Pin
David Crow15-Oct-08 10:58
David Crow15-Oct-08 10:58 
QuestionWhy the activex .ocx can't find msvcr80.dll & mfc80.dll even if I install the 2005 sp1 redist.exe ? Pin
oppstp15-Oct-08 7:11
oppstp15-Oct-08 7:11 
GeneralRe: Why the activex .ocx can't find msvcr80.dll & mfc80.dll even if I install the 2005 sp1 redist.exe ? Pin
oppstp16-Oct-08 0:07
oppstp16-Oct-08 0:07 
QuestionMFC App (Visual Studio 6) hangs when you click File, Open. Pin
Keith (MapMan)15-Oct-08 5:37
Keith (MapMan)15-Oct-08 5:37 
QuestionRe: MFC App (Visual Studio 6) hangs when you click File, Open. Pin
Mark Salsbery15-Oct-08 6:04
Mark Salsbery15-Oct-08 6:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.