Data types in Embedded C++

This is a discussion on Data types in Embedded C++ within the C++ Programming forums, part of the General Programming Boards category; I have this code: Edit_SetText(hctl_data, (LPTSTR)SCNBUF_GETDATA(lpScanBuffer)); Edit_SetText have parameters type HWND y LPTSTR, (LPTSTR) convert to LPTSTR the content of ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    2

    Data types in Embedded C++

    I have this code:

    Edit_SetText(hctl_data, (LPTSTR)SCNBUF_GETDATA(lpScanBuffer));

    Edit_SetText have parameters type HWND y LPTSTR, (LPTSTR) convert to LPTSTR the content of SCNBUF_GETDATA(lpScanBuffer)

    I need convert the content of SCNBUF_GETDATA(lpScanBuffer) to CHAR type, in order to use in the command fputs(), I mut use (CHAR) before ?? (I try this and gives me a en error)

    any suggestion??

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    Casts don't convert anything at all when you're dealing with pointers.

    char *p = "1234";

    Saying
    int *q = (int*)p;
    doesn't make *q magically return the numeric value 1234.

    You need to find some appropriate conversion function, which takes a TSTR and returns a char pointer.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    2
    OK, thanks for your answer

    in "Edit_SetText(hctl_data, (LPTSTR)SCNBUF_GETDATA(lpScanBuffer));"

    what (LPTSTR) does over SCNBUF_GETDATA(lpScanBuffer) ?
    can you explain to me, or advice me a doc to learn about, I'm a VFP programmer, I need to modify this code in c++ in order to make functional a data collector.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,437
    LPTSTR is a typedef for some pointer to some string. But a pointer is a variable that points to some location and the type tells the compiler how to interpret the data. Casting to another pointer type simply changes how the compiler interprets the data. It does not actually change any of the data stored (ie, convert it to another type)!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what are the data types?
    By Milhas in forum C Programming
    Replies: 3
    Last Post: 03-26-2008, 08:31 AM
  2. Data Types
    By drrcknlsn in forum C++ Programming
    Replies: 7
    Last Post: 01-17-2008, 02:52 AM
  3. data types types...
    By gftmc in forum C++ Programming
    Replies: 3
    Last Post: 09-11-2006, 11:30 AM
  4. data types
    By Micko in forum Windows Programming
    Replies: 2
    Last Post: 05-18-2004, 06:23 AM
  5. Data types
    By KrAzY CrAb in forum C Programming
    Replies: 4
    Last Post: 02-04-2003, 05:43 AM

Tags for this Thread


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