Note that there are some explanatory texts on larger screens.

plurals
  1. POc++ unsigned char memory copy
    primarykey
    data
    text
    <p>I need to pass an unsigned char array from one method to another, and i tried using this code:</p> <pre><code>{ unsigned char *lpBuffer = new unsigned char[182]; ReceiveSystemState(lpBuffer); } BOOL ReceiveSystemState(unsigned char *lpBuffer) { unsigned char strRecvBuffer[182] = { 0 }; //strRecvBuffer construction memcpy(lpBuffer, strRecvBuffer, sizeof(strRecvBuffer)); return TRUE; } </code></pre> <p>Neither of those 3 methods (used in <code>ReceiveSystemState</code>) worked as i expected. After using each one of them all that it is copied is the first char from <code>strRecvBuffer</code> and nothing more. The <code>strRecvBuffer</code> has empty chars from element to element, but i need those as they are, because that string is a message from a hardware device and that message will be anallysed using a protocol. What do i miss here? Do i initialize <code>lpBuffer</code> wrong?</p> <p>EDIT: I've used a simple <code>memcpy</code> method to do the job. Still the same result: all that it is copied is the first char of <code>strRecvBuffer</code>.</p> <p>EDIT2: Working code:</p> <pre><code>{ unsigned char *lpBuffer = new unsigned char[182]; ReceiveSystemState(lpBuffer); for (int i = 0; i &lt; 144; i++) { memcpy(&amp;c_dateKG[i], lpBuffer + i * sizeof(unsigned char), sizeof(unsigned char) ); } } BOOL ReceiveSystemState(unsigned char *lpBuffer) { unsigned char strRecvBuffer[182] = { 0 }; //strRecvBuffer construction memcpy(lpBuffer, strRecvBuffer, sizeof(strRecvBuffer)); return TRUE; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload