1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#define _WIN32_WINNT 0x0500
/* Il faut définir la version de Windows ciblée à 5.0 (Windows 2000) */
/* car la fonction GetConsoleWindow n'existe qu'à partir de cette version. */
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
OPENFILENAME ofn;
HWND hwnd = GetConsoleWindow();
char lpszFile[MAX_PATH] = "";
char lpszFileTitle[MAX_PATH] = "";
freopen("null", "w", stderr); /* Cette ligne permet de ne pas avoir
les éventuels messages d'erreurs dans la console. */
printf("Choisissez un fichier...\n\n");
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "0Tous (*.*)\0*.*\0";
ofn.lpstrFile = lpszFile;
ofn.nMaxFile = sizeof(lpszFile) / sizeof(lpszFile[0]);
ofn.lpstrFileTitle = lpszFileTitle;
ofn.nMaxFileTitle = sizeof(lpszFileTitle) / sizeof(lpszFileTitle[0]);
ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_CREATEPROMPT;
if (GetOpenFileName(&ofn)){
CHAR *buffer;
int i;
HANDLE hf;
DWORD FileSize,nbcharRead ;
CHAR szFile[MAX_PATH]={0};
hf = CreateFile(szFile, GENERIC_READ, 0,NULL,OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL, NULL);
FileSize = GetFileSize(hf, NULL);
buffer = (PCHAR)LocalAlloc(LMEM_FIXED, FileSize+1);
ReadFile(hf, buffer, FileSize, &nbcharRead, NULL) ;
buffer[FileSize] = 0;
for( i = 0;i <= 2;i ++)
{
printf("code->> %2X \n",buffer[i]&0xFF);
}
LocalFree(buffer);
CloseHandle(hf);
}
return 0;
} |
Partager