locked
convert long to unsigned char* RRS feed

  • Question

  • Hello all,

    I would like some help converting a long value (which is the adress start) to a unsigned char*
    I am developing in eVC++ 4.0

    What I tried was
    long l1 = 708726;
    unsigned char * ch;
    ch = (unsigned char*)l1;

    when this is run the data that is contained by ch isn't correct.
    can someone please help me

    kind regards

    Jkorsten
    Wednesday, November 4, 2009 12:38 PM

Answers

  • ok I've solved it this way:

    long l1 = 708726;
    unsigned char *ch;
    CString str((char *)l1);
    ch = (unsigned char*)str.GetBuffer(str.GetLength());

    now the ch contains the data I want.
    It isn't very pretty but when I do a AfxMessageBox on the ch now it will display the correct data.

    Thanx

    jkorsten
    • Marked as answer by jkorsten Wednesday, November 4, 2009 2:40 PM
    Wednesday, November 4, 2009 2:40 PM

All replies

  • That will only work if you are converting pointers belonging to the same process. If you are passing a pointer from another process it will be invalid.
    João Paulo Figueira (Device Application Development MVP)
    Wednesday, November 4, 2009 2:02 PM
  • ok I've solved it this way:

    long l1 = 708726;
    unsigned char *ch;
    CString str((char *)l1);
    ch = (unsigned char*)str.GetBuffer(str.GetLength());

    now the ch contains the data I want.
    It isn't very pretty but when I do a AfxMessageBox on the ch now it will display the correct data.

    Thanx

    jkorsten
    • Marked as answer by jkorsten Wednesday, November 4, 2009 2:40 PM
    Wednesday, November 4, 2009 2:40 PM