CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2010
    Posts
    75

    Typecast from a const char* to an integer

    I'm looking for something like
    Code:
    SendMessage(hStatic, WM_SETTEXT, 0, cast<LPARAM>("mytext"));
    LPARAM is actually an integer btw, right?

  2. #2
    Join Date
    Jun 2008
    Posts
    592

    Re: Typecast from a const char* to an integer

    Why not
    reinterpret_cast< LPARAM >( "abc" )
    or
    (LPARAM)"abc"

    Quote Originally Posted by paprica
    LPARAM is actually an integer btw, right?
    typedef LONG_PTR LPARAM;
    typedef long LONG_PTR, *PLONG_PTR;

    of course long can be any byte size >= char
    0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
    0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000
    0000 0000 0000 0000

  3. #3
    Join Date
    Jul 2010
    Posts
    75

    Re: Typecast from a const char* to an integer

    I've been taught that c-style casts are bad.
    Are you sure that reinterpret_cast is the right choice? It just converts pointer to pointer or pointer to integer and vice versa...

  4. #4
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Typecast from a const char* to an integer

    Quote Originally Posted by paprica View Post
    Are you sure that reinterpret_cast is the right choice?
    This is exactly the sort of thing that reinterpret cast is for. I use this technique all the time to pass object addresses to a window, in a message. I use reinterpret cast to convert the pointer back again to its real type at the receiving end.
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured