Thread: LPCTSTR and HRESULT

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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, 04:15 AM
  2. linker errors?
    By X3no in forum C++ Programming
    Replies: 7
    Last Post: 09-06-2007, 02:12 PM
  3. Autorun - How?
    By nouneim in forum C++ Programming
    Replies: 30
    Last Post: 06-23-2004, 06:15 PM