Note that there are some explanatory texts on larger screens.

plurals
  1. POmodifying a function parameter (a pointer) from within the application
    primarykey
    data
    text
    <p>This is a question based on C code for Win32. In one of my functions I have the following code:</p> <pre><code>void SeparateStuff() { HGLOBAL hMem; IStream* pStream; Status result; unsigned char* pBytes; DWORD size; FILE* fp; if (hMem = GlobalAlloc(GMEM_MOVEABLE, 0)) { if (CreateStreamOnHGlobal(hMem, FALSE, &amp;pStream) == S_OK) { // save the buffer to a file result = Scramble(pStream); pStream-&gt;Release(); if (result == Ok) { if (pBytes = (unsigned char *) GlobalLock(hMem)) { size = GlobalSize(hMem); // pBytes has the buffer now // in this case write it to a file if(fp = fopen("c:\\SomeFile.bin", "wb")) { fwrite(pBytes, size, 1, fp); fclose(fp); } } } } else { printf("error CreateStreamOnHGlobal. Last err: %d\n", GetLastError()); return; } } else { printf("error GlobalAlloc. Last err: %d\n", GetLastError()); return; } } </code></pre> <p>In this case the unsigned char* buffer is being saved to a file. Everything is fine. Now, I need to modify this code so the unsigned char* is returned. Something like:</p> <pre><code>void SeparateStuff(unsigned char* ReturnedBytes) </code></pre> <p>Where ReturnedBytes will be modified inside the function. I tried copying the pointer, i tried copying the data inside the pointer. I tries a lot of different approaches. It doesn't matter what I do I either get garbage in the calling function or an exception. The calling function (the main() for example) has to pass to SeparateStuff() also an unsigned char*.</p> <p>How do I do that?</p> <p>thanks!</p>
    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.
    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