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

  • SEARCH
  • Home
  • 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 8439039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:53:42+00:00 2026-06-10T07:53:42+00:00

I have as class as follows: #include <Windows.h> class MyClass { void A(); static

  • 0

I have as class as follows:

#include <Windows.h>
class MyClass
{
   void A();
   static BOOL CALLBACK proc(HWND hwnd, LPARAM lParam);
};

void MyClass::A()
{
   EnumChildWindows(GetDesktopWindow(), MyClass::proc, static_cast<LPARAM>(this));
}

BOOL CALLBACK MyClass::proc(HWND hwnd, LPARAM lParam)
{
   // ...
   return TRUE;
}

When I attempt to compile this in Visual C++ 2010, I get the following compiler error:

error C2440: ‘static_cast’ : cannot convert from ‘MyClass *const ‘ to ‘LPARAM’
There is no context in which this conversion is possible

If I change the definition of MyClass::A as follows, then the compile succeeds:

void MyClass::A()
{
   EnumChildWindows(GetDesktopWindow(), MyClass::proc, (LPARAM)this);
}

What is the explanation for the error in the first example?

  • 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-06-10T07:53:44+00:00Added an answer on June 10, 2026 at 7:53 am

    You need to use a reinterpret_cast not a static_cast to perform a cast to a completely unrelated type. See this When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? for more details on the different types of C++ casts.

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

Sidebar

Related Questions

I have created a class as follows: #include <iostream> #define DLLEXPORT _declspec( dllexport )
I have a class that inherits from a generic dictionary as follows: Class myClass
I have an exception class as follows: #include <exception> struct InvalidPathException : public std::exception
I have a class defined as follows: #include <iostream> using namespace std; class Point
I have a function in a native DLL defined as follows: #include <string> void
I have Mongoid classes as follows: class Order include Mongoid::Document embeds_many :animals end class
I have class structure as follows: @JsonTypeName(0) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property
I have a class A as follows: class A { public: A() { printf(A
I have a class as follows :- interface IFilterCondition { List<Name> ApplyFilter(List<Name> namesToFilter); }
I have a class with a structure as follows: class Test { private $var1;

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.