I should first say, I don't know why it's crashing, but it would help if you told us where the program is crashing?
BTW, GlobalAlloc/LocalAlloc are hangovers from WIN16. You really should try to avoid them unless you're using an API call that requires one of them. Use HeapAlloc instead, it was introduced in WIN32.
b4 it was like this:
when I open the file, it all works well, and then it shows me chinese letters
and if I open another file within few secs I get access violation before open file dialog is shown(if I wait few secs i get again chinese letters)
Can you just point to a line in the code you originally presented where the crash occurs. There no point in us scourering your code looking for faults that don't exist when you can just tell us where the crash happens.
Your lpstrFilter parameter must be double nul terminated, which is not in your example. Just copy and paste the damn thing from some website, there are hundreds of examples on the web.
i copied this from some other tutorial
yet it doesnt work
for break points:
i haven't seen any break point in code while debugging
this is output form debug:
Windows has triggered a breakpoint in win32 open file.exe.
This may be due to a corruption of the heap, which indicates a bug in win32 open file.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while win32 open file.exe has focus.
The output window may have more diagnostic information.
pszFileText[dwFileSize] = '\0';//i deleted this part of code and now it works
no more access violation is shown
still i got chinese letters (in the .txt file there are no chinese letters only normal latin letters..)
funny thing:
I typed "asdf" in file and I've opened it with my program, google translator has displayed that this is written in chinese:
Xi met Ben B Lane??? Flattering 䬰 ˤ
You don't know how to use a memory buffer. Please read a decent tutorial and then come back.
Your file is NOT UTF16-LE encoded, as you try to read it by wrongly casting ReadFile() buffer to LPTSTR (which in your build settings means pointer to wchar_t's).