THis is the Dll code
#ifdef HELLO_EXPORTS
#define CLASS_DECLSPEC __declspec(dllexport)
#else
#define CLASS_DECLSPEC __declspec(dllimport)
#endif
CLASS_DECLSPEC FILE* GetStdout() {
return stdout;
}
CLASS_DECLSPEC void dump_code(FILE* fd, const void* data, size_t len)
{
unsigned char* p = (unsigned char*)data;
size_t i;
for(i = 1; i < len + 1; ++i){
fprintf(fd, "0x%.2x, ", p[i-1]);
if((i%16)==0) fprintf(fd, "\n");
}
fprintf(fd, "\n");
}
This is the test code:
#include <stdio.h>
#include <stdlib.h>
#include "dump.h"
int main(){
char data[] = {
0x1f,0xc2,0x8b,0x08,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xc3,0x8d,0xc2,0x90,0x3d
};
dump_code(GetStdout(), data, 16);
//dump_code(stdout, data, 16);
}
If I directly use stdout: dump_code(stdout, data, 16);, the program will crash in _lock_file.
But it will ok to use GetStdout() instead of stdout.