Thread: BYTE, char data corruption

  1. #16
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Quote Originally Posted by Denethor2000
    error C2440: 'initializing' : cannot convert from 'unsigned char [300]' to 'unsigned char'
    What's _Buffer? According to the error, it's an 'unsigned char'.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  2. #17
    Super Moderator Harbinger's Avatar
    Join Date
    Nov 2004
    Posts
    74
    > input Line = { GetCurrentProcessId(), Address, Length, _Buffer };
    You can't assign arrays - use memcpy()

    Having BYTE *bytes; in your struct would work, but that wouldn't be making a copy of the buffer.

  3. #18
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    Quote Originally Posted by dwks
    What's _Buffer? According to the error, it's an 'unsigned char'.
    Yeah, I edited that in a minute later, sorry about that.

    It's a BYTE array.
    Code:
    BYTE _Buffer[300];

  4. #19
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Code:
    input Line = { GetCurrentProcessId(), Address, Length, _Buffer };
    What the hell is the above? what are those curly-braces doing there? First calls GetCurrentProcessID() and assigns the return value to Line (which is wrong because Input is not a DWORD). but what's the purpose of Address, Length, and _Buffer in that line?
    Last edited by Ancient Dragon; 11-12-2005 at 05:42 PM.

  5. #20
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    Quote Originally Posted by Ancient Dragon
    Code:
    input Line = { GetCurrentProcessId(), Address, Length, _Buffer };
    What the hell is the above? what are those curly-braces doing there? First calls GetCurrentProcessID() and assigns the return value to Line (which is probably wrong if Input is not a DWORD). but what's the purpose of Address, Length, and _Buffer in that line?
    It's a struct. Which I included in the same post.

    It gets passed to a driver with DeviceIoControl. Which has nothing to do with my problem.

  6. #21
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Probably to initialize the remaining members of the structure.
    Code:
    struct s {
        int x;
        float f;
    };
    
    s one;
    s two = {1};
    s three = {1, 2.0};
    [edit]You beat me to it.[/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #22
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Which has nothing to do with my problem.
    It might, depending on what _Buffer is. It's [300], right?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #23
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by Denethor2000
    It's a struct. Which I included in the same post..
    Yes, I reread your previous post and found that out. You can't assign members of a struct like that -- each member requires its own assign statement.
    Code:
    Line.processid = GetProcessID();
    Line.address = Address;
    Line.bytestowrite = Length;
    // The next line may not work if sizeof(Line.bytes) > siezof(_Buffer)
    memcpy(Line.bytes,_Buffer,sizeof(Line.bytes));

  9. #24
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You can too assign a struct like that. How about you re-read my post:

    Quote Originally Posted by dwks
    Code:
    struct s {
        int x;
        float f;
    };
    
    s one;
    s two = {1};
    s three = {1, 2.0};
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #25
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    And what's siezof?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #26
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by dwks
    You can too assign a struct like that. How about you re-read my post:
    That obscure trick won't work with his struct because it contains character arrays which cannot be copied like that.

  12. #27
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    That obscure trick
    I use it all the time.

    won't work with his struct because it contains character arrays
    Yes, you're right. (It does work for char*, not for char[].) But
    but what's the purpose of Address, Length, and _Buffer in that line?
    Address and Length are valid.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  13. #28
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by dwks
    I use it all the time.
    You are one of a very select few who do. I've never see that before in over 20 years.


    Quote Originally Posted by dwks
    Yes, you're right. (It does work for char*, not for char[].)
    well, it really does not work for char* either -- unless all you want copied is the address and not the object to which it points.

  14. #29
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You are one of a very select few who do. I've never see that before in over 20 years.
    What? Really? That's amazing.

    well, it really does work for char* either -- unless all you want copied is the address and not the object to which it points.
    It does work? Oh, you mean doesn't. It does work, because all I want copied is the address.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  15. #30
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    technically you aren't doing assignment. You are doing initalization.

    Denethor2000 instead of rationing out your limitations to us how about you give us all the info in the beginning?

    A BYTE is nothing more then a fancy unsigned char.

    Changing both types to char[300] is accepted, but "corrupts" it.
    how does it corrupt it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 06:02 PM
  4. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM