I found this code somewhere else on stackexchange and it works great.
char *szData = new char[str_hex.size()+1] = "\x4d\x4d\x4d\x5a\x90\x00\x03\x00\x00\x00\x04\x00\x00\x00\xe0\x00\x00\x00\x0e\x1f\xba\x0e\x00\xb4\x09\xcd\x00\x00\x00\x00\x00\x00\x00\x00";
system("pause");
HANDLE hFile;
DWORD dwBytesWritten = 0;
TCHAR szPath[MAX_PATH] = "C:\\Users\\Jules\\Desktop\\halloskos.txt";
hFile = CreateFile (szPath,
GENERIC_WRITE,
0,
NULL,
CREATE_NEW,
FILE_ATTRIBUTE_NORMAL,
NULL);
WriteFile( hFile,&hexCh,sizeof(hexCh)-1, &dwBytesWritten, NULL );
CloseHandle(hFile);
delete [] szData;
However, i want to pull the hex data from a text file (stored like this: 4d5a9000f4 etc...).
With fstream i can turn the contents of the text file to a string, but how can i convert this to the array shown in the code example? (So an char array like this: \x4d\x5a\x90\x00\xf4 etc...)
Conversion example:
from:
string str_hex = "4d5a9000f4";
to:
char *ch_hex = new char[str_hex.size()+1] = "\x4d\x5a\x90\x00\xf4"
Thanks for your help!