Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4619026
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:22:06+00:00 2026-05-22T02:22:06+00:00

Can anybody tell me why the following code doesn’t work? I don’t get any

  • 0

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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:22:06+00:00Added an answer on May 22, 2026 at 2:22 am

    The third parameter is typed as a HANDLE, so IMO to meet the explicit contract of the function you should save the property as a HANDLE by allocating a HGLOBAL memory 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…

    SetProp(hWnd, _T("TestProp"), (HANDLE)(10)); // or (HANDLE)(short*)(10)
    ...
    (short)GetProp(hWnd, _T("TestProp"));
    

    … 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 HGLOBAL instead to follow the specific types of the function signature, you can follow this example in MSDN.

    Even though a HANDLE is 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 a short when the function calls for a HANDLE, you need a memory handle (an HGLOBAL).

    The sample code linked above copies data as a string, but you can instead set it as another data type:

    // TODO: Add error handling
    hMem = GlobalAlloc(GPTR, sizeof(short));
    lpMem = GlobalLock(hMem);
    if (lpMem != NULL)
    {
        *((short*)lpMem) = 10;
        GlobalUnlock(hMem);
    }
    

    To read it back, when you GetProp to get the HANDLE you must lock it to read the memory:

    // TODO: Add error handling
    short val;
    hMem = (HGLOBAL)GetProp(hwnd, ...); 
    if (hMem)
    {
        lpMem = GlobalLock(hMem);
        if (lpMem)
        {
            val = *((short*)lpMem);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody tell my why this doesn't work in the Android emulator? From the
I have the following code which is working fine , but can anybody tell
The following code is visual basic, .NET, ASP... all of the above? Can anybody
Can anybody tell me the most optimal Combres settings? I've got the following but
Can i get the source code for a WAMP stack installer somewhere? Any help
I need to solve the following question which i can't get to work by
can anybody tell me what is wrong with this code, i am getting the
Can anybody tell me when Application_End is triggered in a lifecycle of an application?
Can anybody tell me how to identify the middle part interestedInThis and backreference the
if(!eregi(^([0-9a-z_\[\]\*\- ])+$, $subuser)) $form->setError($field, * Username not alphanumeric); Can anybody tell me why it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.