[commit: Win32] encoding: Fix BMP code, including legacy _lwrite calls.. how old is this anyway? (41a5260)

Max Bolingbroke batterseapower at hotmail.com
Wed Apr 6 16:37:40 CEST 2011


Repository : ssh://darcs.haskell.org//srv/darcs/packages/Win32

On branch  : encoding

http://hackage.haskell.org/trac/ghc/changeset/41a52607a4d2da96609284551739532c9ee0c74d

>---------------------------------------------------------------

commit 41a52607a4d2da96609284551739532c9ee0c74d
Author: Max Bolingbroke <batterseapower at hotmail.com>
Date:   Wed Apr 6 13:47:04 2011 +0100

    Fix BMP code, including legacy _lwrite calls.. how old is this anyway?

>---------------------------------------------------------------

 cbits/dumpBMP.c   |   11 ++++++-----
 include/dumpBMP.h |    2 +-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/cbits/dumpBMP.c b/cbits/dumpBMP.c
index df89a96..18a5ba5 100644
--- a/cbits/dumpBMP.c
+++ b/cbits/dumpBMP.c
@@ -36,7 +36,7 @@
 
 void CreateBMPFile(LPCTSTR pszFileName, HBITMAP hBmp, HDC hDC)
 {
-    int         hFile;
+    HANDLE      hFile;
     HBITMAP     hTmpBmp, hBmpOld;
     BOOL        bSuccess;
     BITMAPFILEHEADER    bfh;
@@ -45,6 +45,7 @@ void CreateBMPFile(LPCTSTR pszFileName, HBITMAP hBmp, HDC hDC)
     BITMAPINFO  bmi;
     PBYTE pjTmp, pjTmpBmi;
     ULONG sizBMI;
+	DWORD 		dwBytesWritten;
 
 
     bSuccess = TRUE;
@@ -150,7 +151,7 @@ void CreateBMPFile(LPCTSTR pszFileName, HBITMAP hBmp, HDC hDC)
     //
     // Write out the file header now
     //
-    if (_lwrite(hFile, (LPSTR)&bfh, sizeof(BITMAPFILEHEADER)) == -1) {
+    if (WriteFile(hFile, (LPCVOID)&bfh, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL) == -1) {
         fprintf(stderr, "Failed in WriteFile!");
         bSuccess = FALSE;
         goto ErrExit3;
@@ -178,7 +179,7 @@ void CreateBMPFile(LPCTSTR pszFileName, HBITMAP hBmp, HDC hDC)
     //
     // Now write out the BitmapInfoHeader and color table, if any
     //
-    if (_lwrite(hFile, (LPSTR)pbmi, sizBMI) == -1) {
+    if (WriteFile(hFile, (LPCVOID)pbmi, sizBMI, &dwBytesWritten, NULL) == -1) {
         fprintf(stderr, "Failed in WriteFile!");
         bSuccess = FALSE;
         goto ErrExit4;
@@ -187,7 +188,7 @@ void CreateBMPFile(LPCTSTR pszFileName, HBITMAP hBmp, HDC hDC)
     //
     // write the bits also
     //
-    if (_lwrite(hFile, (LPSTR)pBits, pbmi->bmiHeader.biSizeImage) == -1) {
+    if (WriteFile(hFile, (LPCVOID)pBits, pbmi->bmiHeader.biSizeImage, &dwBytesWritten, NULL) == -1) {
         fprintf(stderr, "Failed in WriteFile!");
         bSuccess = FALSE;
         goto ErrExit4;
@@ -198,7 +199,7 @@ ErrExit4:
     SelectObject(hDC, hBmpOld);
     DeleteObject(hTmpBmp);
 ErrExit3:
-    _lclose(hFile);
+    CloseHandle(hFile);
 ErrExit2:
     GlobalFree(pbmi);
 ErrExit1:
diff --git a/include/dumpBMP.h b/include/dumpBMP.h
index 358f5d3..2561648 100644
--- a/include/dumpBMP.h
+++ b/include/dumpBMP.h
@@ -3,4 +3,4 @@
 /* There's currently no #define that indicate whether we're
    compiling a .hc file. */
 
-extern void CreateBMPFile(LPCSTR pszFileName, HBITMAP hBmp, HDC hDC);
+extern void CreateBMPFile(LPCTSTR pszFileName, HBITMAP hBmp, HDC hDC);





More information about the Cvs-libraries mailing list