Can anybody tell me why the following code doesn’t work? I don’t get any compiler errors.
short value = 10;
SetProp(hCtl, "value", (short*) value);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The third parameter is typed as a
HANDLE, so IMO to meet the explicit contract of the function you should save the property as aHANDLEby allocating aHGLOBALmemory block. However, as noted in the comments below, MSDN states that any value can be specified, and indeed when I try it on Windows 7 using…… I get back 10 from GetProp. I suspect somewhere between your SetProp and GetProp one of two things happens: (1) the value of hWnd is different — you’re checking a different window or (2) a timing issue — the property hasn’t been set yet or had been removed.
If you wanted to use an
HGLOBALinstead to follow the specific types of the function signature, you can follow this example in MSDN.Even though a
HANDLEis just a pointer, it’s a specific data type that is allocated by calls into the Windows API. Lots of things have handles: icons, cursors, files, … Unless the documentation explicitly states otherwise, to use a blob of data such as ashortwhen the function calls for aHANDLE, you need a memory handle (anHGLOBAL).The sample code linked above copies data as a string, but you can instead set it as another data type:
To read it back, when you
GetPropto get theHANDLEyou must lock it to read the memory: