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

    [RESOLVED] Windows API data types + LPCBYTE

    Can anyone tell me what an LPCBYTE is (found reading through someones code) and how it differs from a long pointer to byte LPBYTE? It doesn't seem to be part of the windows api ...

    A more general question - is there a simple reason why windows defines its own versions of the basic types (char as BYTE, short as WORD, long as DWORD).. and more importantly why you should use them?

    Many thanks in advance


  2. #2
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    2,147

    Re: Windows API data types + LPCBYTE


    LPCBYTE is a const LPBYTE or a const char * (as defined in ODBCSS.H)

    The API used its own defines so that it can remain consistent across all supported platforms. A WORD on a 16-bit platform, should be the same size as a WORD on a 64-bit platform (both 16-bit unsigned integers), whereas an int value is entirely different (16 vs 64).

    Hope this helps,

    - Nigel




  3. #3
    Join Date
    Mar 2018
    Posts
    1

    Re: Windows API data types + LPCBYTE

    Quote Originally Posted by NigelQ View Post
    LPCBYTE is a const LPBYTE
    This information is wrong LPCBYTE is not const LPBYTE! This makes the pointer itself constant not the value pointed to!

    Even const char* is the wrong track. BYTE should be unsigned, so const unsigned char* or const BYTE * (if windows.h is included) may be a way.

    PS: I know that the thread is old, but wrong information should be corrected (Just my 2 cents).

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Windows API data types + LPCBYTE



    Yes, I agree that wrong information should be corrected.

    LPCBYTE is defined as

    Code:
    typedef const BYTE *LPCBYTE;
    with BYTE defined as

    Code:
    typedef unsigned char BYTE;
    Hence LPCBYTE is actually

    Code:
    typedef const unsigned char* LPCBYTE;
    which can be changed to be

    Code:
    typedef unsigned char const * LPCBYTE;
    which can be read from right to left as
    a pointer to const unsigned char. ie a non-const pointer to const memory of type unsigned char.

    If it was a const pointer to non-const memory then the definition would be

    Code:
    typedef BYTE * const CLPBYTE;
    which, from right to left, is const pointer to non-const BYTE (unsigned char).

    For a const pointer to const memory, it would be

    Code:
    typedef BYTE const * const CLPCBYTE;
    or

    Code:
    typedef const BYTE * const CLPCBYTE;
    ie const pointer to const BYTE data.
    Last edited by 2kaud; March 8th, 2018 at 07:24 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

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