Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to rebuild a struct from bytes after transfer [C#]
    primarykey
    data
    text
    <p>I am using Named Pipes to transfer data from a client (C++) to a server (C#), the client does the following:</p> <pre><code>// C++ Client sending message struct MESSAGE { char cCommand[8]; string sParameter; }; MESSAGE msg; strcpy(msg.cCommand, "COMMAND"); strcpy(msg.sParameter, "DO SOMETHING"); DWORD dwWrote = 0; WriteFile (hpipe, &amp;msg, sizeof(msg), dwWrote, NULL); // Then, at the receiving end the C# server recieve message: IntPtr chRequest; bool fSuccess = ReadFile(hPipeInst, chRequest, uSize, cbRead, OverlappedPtr); if (fSuccess) byte[] temp = Encoding.ASCII.GetBytes(Marshal.PtrToStringAnsi(chRequest)); </code></pre> <p>Now, at the receiving end, I need to transform the temp (byte[]) back into the STRUCT or something equivalent so I can access the members cCommand and sPatameter - but at this point I have no clue how to proceed... In reality doesn't need to be a struct, I just need to extract the data itself.</p> <p>Note - the STRUCT MESSAGE is something I came up with, meaning that it can be changed if a different format would be helpful in the reconstruction (add the length of sParameter for example?), I just need a COMMAND and PARAMETER to be transfered in a single block (if possible).</p> <p>Requirements are simple: - COMMAND is a fixed-length 8-characters long string that indicates what action needs to be performed - PARAMETER is a variable-length (unless this causes issues) parameter dependant on each COMMAND</p> <p>For example: COMMAND = TRANS</p> <p>PARAMETER = C:\FILE.txt C:\NewFolder\FILE.TXT</p> <p>(this is just to illustrate, there are a lot more applications)</p> <p>If possible I would like to extract it as a chunk of data (byte[]) and then pass it along to my application where it could be decomposed, not a fan of reading in the size, then a field, then a size, then a field - that requires that my Communication be overly linked with my implementation.</p> <p>If there is a more suitable way to implement this transfer please let me know... advice would be welcome... Any help would be much appreciated. Thanks,</p>
    singulars
    1. This table or related slice is empty.
    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.
    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