This is the code I am using:
Code:
void Opendialog(HWND hwnd){
OPENFILENAME ofn;
TCHAR buf[60];
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize=sizeof(ofn);
ofn.lpstrFile=buf;
ofn.lpstrFile[0]='\0';
ofn.hwndOwner=hwnd;
ofn.nMaxFile=sizeof(buf);
ofn.lpstrFilter=TEXT("All Files(*.*)\0*.*\0");
ofn.nFilterIndex=1;
ofn.lpstrInitialDir=NULL;
ofn.lpstrFileTitle=NULL;
ofn.Flags= OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if(GetOpenFileName(&ofn))
Loadfile(ofn.lpstrFile);
}
void Loadfile(LPSTR file){
HANDLE hfile;
DWORD dwsize;
DWORD dw;
LPBYTE Ipbuffer=NULL;
hfile=CreateFile(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
dwsize=GetFileSize(hfile, NULL);
Ipbuffer=(LPBYTE)HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, dwsize+1);
ReadFile(hfile, (LPWSTR)Ipbuffer, dwsize, &dw, NULL);
CloseHandle(hfile);
Ipbuffer[dwsize]=0;
SetWindowText(ghwndedit, (const char *)Ipbuffer);
HeapFree(GetProcessHeap(), 0, Ipbuffer);
}