LPCTSTR and HRESULT

This is a discussion on LPCTSTR and HRESULT within the C Programming forums, part of the General Programming Boards category; Hello everyone, If I want to convert LPCTSTR and HRESULT to standard C/C++ data type (like char*, int, long, etc.), ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    LPCTSTR and HRESULT

    Hello everyone,


    If I want to convert LPCTSTR and HRESULT to standard C/C++ data type (like char*, int, long, etc.), I am wondering what standard data types should I convert to be safe and do not lose and data precise?


    thanks in advance,
    George

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    LPCTSTR is conat char* if UNICODE is not defined
    and const wchar_t* if UNICODE is defined. It is used so your application could be compiled both ways without including #ifdefs in your code

    If you plan to program UNICODE only - you can safely use the second one (together with wstring, wstringstream etc)

    HRESULT - I wouldn't replace by the standard C/C++ types because it will may your code less compatible with the future versions of the API you use...

    If you do not want to expose this type outsie your functions that wrapping the Windows API - make some conversion function that could be replaced once the declaration of the HRESULT will be changed
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Now, I can see how you SOMETIMES may want to do this, but in general, there is a REASON that the programmers (in this case at Microsoft) go through the trouble of declaring specific types for things, that you are supposed to use.

    Types like char, int, long, short, double, float, etc are NOT standard in C/C++ - each compiler has every right to define those as it feels is right. You can have one compiler that does 16-bit int, another does 32-bit int and a third (weird one) uses 31-bit int.

    So having a definition that you can change ONCE based on compiler, version of OS, etc, etc, makes sense, right?

    Now, if you want to do something like this:

    Code:
    typedef HRESULT myresult;
    typedef LPCSTR mystring;
    That would be perfectly legal and correct.

    --
    Mats

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. add your program to start menu ?
    By Anddos in forum Windows Programming
    Replies: 6
    Last Post: 04-17-2008, 05:15 AM
  2. linker errors?
    By X3no in forum C++ Programming
    Replies: 7
    Last Post: 09-06-2007, 03:12 PM
  3. Autorun - How?
    By nouneim in forum C++ Programming
    Replies: 30
    Last Post: 06-23-2004, 07:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21