| 66 | |
| 67 | |
| 68 | BOOL Writetofile(PBYTE file, DWORD contentLen, PCHAR path) |
| 69 | { |
| 70 | |
| 71 | HANDLE pFile; |
| 72 | PBYTE tmpBuf = nullptr; |
| 73 | DWORD dwBytesWrite, dwBytesToWrite; |
| 74 | pFile = CreateFileA(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
| 75 | if (pFile == INVALID_HANDLE_VALUE) |
| 76 | { |
| 77 | CloseHandle(pFile); |
| 78 | HeapFree(GetProcessHeap(), 0, file); |
| 79 | return FALSE; |
| 80 | } |
| 81 | dwBytesToWrite = contentLen; |
| 82 | dwBytesWrite = 0; |
| 83 | tmpBuf = file; |
| 84 | do { |
| 85 | WriteFile(pFile, tmpBuf, dwBytesToWrite, &dwBytesWrite, NULL); |
| 86 | dwBytesToWrite -= dwBytesWrite; |
| 87 | tmpBuf += dwBytesWrite; |
| 88 | |
| 89 | } while (dwBytesToWrite > 0); |
| 90 | |
| 91 | CloseHandle(pFile); |
| 92 | HeapFree(GetProcessHeap(), 0, file); |
| 93 | return TRUE; |
| 94 | } |