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 6090557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:13:39+00:00 2026-05-23T12:13:39+00:00

I am using the LPARAM (essentially a long , unless we’re on a 64-bit

  • 0

I am using the LPARAM (essentially a long, unless we’re on a 64-bit system in which case it is a long long) member of an LVITEM (called lParam) to store a pointer to the object that coincides with that entry in the ListView.

When I want to edit that item, I want to cast that LPARAM to a MyClass*, which works fine so long as the lParam is correctly set to be equal to a MyClass* in the first place, but I’d like to do some kind of checking to make sure it is, in fact, a MyClass that this number is pointing to.

Currently I have this:

LVITEM lv;
// lv is filled in by LVM_GETITEM
classPtr = static_cast<MyClass*>((void*)lv.lParam);
if ( !classPtr )
    return false;

Now, I’m not exactly clear: does static_cast return NULL if the argument is not a valid pointer? I assume not, since that’s what dynamic_cast is for, but I’m not entirely certain. And, if I am correct in this assumption, is there any way to check that classPtr is valid before I attempt to access its members and cause a crash…

  • 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-23T12:13:40+00:00Added an answer on May 23, 2026 at 12:13 pm

    You can’t check it at all in pure standard C++. You can only do a probabilistic check using the Windows API. So, in practice you can only guarantee it, by making your code correct.

    If you could check it you would still not know that it was the correct MyClass instance.

    So, the only good way is to make your code guaranteed correct. That’s easier when you limit access to things. C++ has many features to help you limit access, e.g. const; use them.

    Cheers & hth.,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using online interfaces to a version control system is a nice way to have
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using C#, I need a class called User that has a username, password, active
I am using the mousewheel in my DotNet application, which I have done by
I'm using AllocateHWnd in a class I'm writing to receive system messages with a
I am using a crude system to control a Flash movie from a C++/win32
I'm using a treeview with three levels of nodes, the second level which I've
Here is the thing, I wrote a program using windows api EnumWindows which requires
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a

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.