Results 1 to 5 of 5

Thread: C code - check my syntax for me

  1. #1

    C code - check my syntax for me

    I've come up with the code below. Within context it does exactly what I want it to do. I'm paranoid its gonna give me a memory error somehow - specifically the first line of Main.

    Validate please!


    LPVOID pVoid = (LPVOID)NULL;
    JCHAR cTempChar = {0 };


    //Main
    pVoid = (LPVOID*)_J("X");
    memcpy((void *) &cTempChar,(const void *) pVoid, sizeof(cTempChar));

  2. #2
    Senior Member craig_welton's Avatar
    Join Date
    Oct 2000
    Location
    Litchfield, CT
    Posts
    1,003
    You can just do:

    cTempChar = _J('X');
    Craig Welton
    PatWel Group Inc.
    http://www.patwel.com
    Home of the FREE JDE Object Browser, JDETrace, NERDup and BusBuild+ Tools

    E1 9.0 8.98.4.2 Wintel SQL 2008
    E1 9.2 9.2.1.4 iSeries

  3. #3
    Thanks Craig

    I need to go via pVoid as I'm getting the original value from JDB_GetTableColValue (which you helped me out in a previous thread).

    In the code above I'm try, to override the value of pVoid before I use it in JDB_AssignColumnValue.

    So the line that worries me is:
    pVoid = (LPVOID*)_J("X");

    In my head I read it as:
    "X" is a unicode string. Using '*', get me a pointer to it but return it as a pointer of type (LPVOID). This way I can assign it to the pointer variable pVoid.

    It seams to work and don't give me any problems but still I would like someone to cast a eye over it.

    This line I just use for debugging so I can see whats in pVoid.
    memcpy((void *) &cTempChar,(const void *) pVoid, sizeof(cTempChar));




  4. #4
    Thanks Craig.

    In my code pVoid gets set by JDB_GetTableColValue (something you prev helped me out on).
    Eventually, pVoid gets used in JDB_AssignColumnValue.

    Here I'm just trying to override the pVoid value (given that the column has a DD type of EDSP)

    So the line that worries me is:
    pVoid = (LPVOID*)_J("X");
    In my head it reads: Return me a pointer to "X". Instead of a pointer to a string, cast it into a pointer of type (LPVOID) so it can be assigned to variable pVoid

    That sound right?

  5. #5
    Senior Member craig_welton's Avatar
    Join Date
    Oct 2000
    Location
    Litchfield, CT
    Posts
    1,003
    GetTableColValue returns a pointer to the column value. To be safe, you should copy the value to a local variable of the proper type.
    Simplified code:

    JCHAR cEDSP;

    memcpy(&cEDSP, GetTableColValue(...), sizeof(JCHAR));

    if you want to change that value, and set the column value:

    cEDSP = _J('X');
    AssignColumnValue(..., (LPVOID)&cEDSP);
    Craig Welton
    PatWel Group Inc.
    http://www.patwel.com
    Home of the FREE JDE Object Browser, JDETrace, NERDup and BusBuild+ Tools

    E1 9.0 8.98.4.2 Wintel SQL 2008
    E1 9.2 9.2.1.4 iSeries

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
The legal restrictions and terms of use applicable to this site are available here.
Use of this site signifies your agreement to the terms of use.
JDELIST is NOT affiliated with JD Edwards® & Company, Oracle or Peoplesoft. Contents of this site are neither endorsed nor approved by JD Edwards® & Company and, or Oracle.