2013년 3월 16일 토요일

[win32api] read file

 HANDLE hFile = CreateFile(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
 if (hFile != INVALID_HANDLE_VALUE)
 {
  // Get text length of data in editbox
  DWORD dwTextLength = GetWindowTextLength(GetDlgItem(hWnd, editID));
  if (dwTextLength > 0)
  {
   char* pszRead;
   DWORD dwBufferSize = dwTextLength + 1; // + 1 because NULL character needed (\0)

   pszRead = (char*)malloc(dwBufferSize);
   // Read text from editbox
   if (GetWindowText(GetDlgItem(hWnd, editID), pszRead, dwBufferSize))
   {
    DWORD dwWritten;

    WriteFile(hFile, pszRead, dwTextLength, &dwWritten, NULL);
    bSaved = TRUE;
   }
   free(pszRead);
  }

  CloseHandle(hFile);

댓글 없음:

댓글 쓰기