winapi - How to use Win32 API to specify directory to write file to using WriteFile? -
i've used following handle file:
char *filepathandname = "c:\projects\pic.bmp"; handle hfile = createfile(_t(filepathandname),generic_write, 0, null, create_always, file_attribute_normal, null);
and i've used following write file:
writefile(hfile, (lpstr)&bmfheader, sizeof(bitmapfileheader), &dwbyteswritten, null); writefile(hfile, (lpstr)&bi, sizeof(bitmapinfoheader), &dwbyteswritten, null); writefile(hfile, (lpstr)lpbitmap, dwbmpsize, &dwbyteswritten, null);
however, file writes project directory (i.e. microsoft visual studio solution file exists) rather c:\projects\ directory.
how can write .bmp file specified directory?
the _t()
macro can used literals (same text()
macro). , not escaping slashes in literal.
the c runtime uses _t()
macro. win32 api uses text()
macro. should not mix them, though same thing. use correct macro api using.
and don't need type-cast data lpstr
when calling writefile()
.
use instead:
lptstr filepathandname = text("c:\\projects\\pic.bmp"); handle hfile = createfile(filepathandname, generic_write, 0, null, create_always, file_attribute_normal, null); ... writefile(hfile, &bmfheader, sizeof(bitmapfileheader), &dwbyteswritten, null); writefile(hfile, &bi, sizeof(bitmapinfoheader), &dwbyteswritten, null); writefile(hfile, lpbitmap, dwbmpsize, &dwbyteswritten, null);
with said, typically should prompting user output filename, either getsavefilename()
or ifilesavedialog
. or @ least prompt destination folder using shbrowseforfolder()
(or ifilesavedialog, supports picking folder) if want use own filename.
Comments
Post a Comment