GlobalAlloc() question

Aciel aciel@speakeasy.net
Wed Aug 16 12:38:00 GMT 2000


This is PROBABLY one of those answers that stares you in the face, it's just
hard to see after 24 hours of not sleeping. But I've been staring at this
for the past 12, so I'm going to give in, and risk flaming.

I've got a function that's supposed to load a file (below), and inside of
that is a call to GlobalAlloc(). I borrowed it from a tutorial, the same one
I seem to borrow the rest of my code from <wink>. Now...in the Tutorial it
works just fine. But the minute I port it in to MY version of the Tutorial
code (only the variable names have been changed, to protect the innocent).
In fact, NONE of the variable names in this function are global, so NONE of
them have been changed. It should work flawlessly. But I get the following
error.

winmain.cpp:43: ANSI C++ forbids implicit conversion from 'void *' in
initialization

BOOL LoadFile(HWND hEdit, LPSTR pszFileName)
{
  BOOL bSuccess = FALSE;
  HANDLE hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ,
      (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, NULL, NULL);
  if(hFile != INVALID_HANDLE_VALUE) {
    DWORD dwFileSize = GetFileSize(hFile, (LPDWORD)NULL);
    if(dwFileSize != 0xFFFFFFFF) {
/*LINE 43*/
      LPSTR pszFileText = GlobalAlloc(GPTR, dwFileSize + 1);
/*LINE 43*/
      if(pszFileText != NULL) {
        DWORD dwRead;
        if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL)) {
          pszFileText[dwFileSize] = 0;  // Null terminator
          if(SetWindowText(hEdit, pszFileText)) bSuccess = TRUE; // It
worked!
        }
        GlobalFree(pszFileText);
      }
    }
    CloseHandle(hFile);
  }
  return bSuccess;
}

The only include file I have right now is <windows.h>, as it is in the
tutorial. What's the reasoning on a silly thing like this?


Thanks,
Aciel
aciel@speakeasy.net
Visit the RAN Free Speech Forum - www.rapedangel.net




More information about the Gcc-help mailing list