| 132 | } |
| 133 | |
| 134 | BOOL writeToLogFile(const char * text) |
| 135 | { |
| 136 | DWORD lpNumberOfBytesWritten = 0; |
| 137 | size_t i = 0; |
| 138 | BOOL wfRet = 0; |
| 139 | HANDLE hFile = 0; |
| 140 | char buffer[260]; |
| 141 | |
| 142 | if (!GetModuleFileNameA(0, buffer, sizeof(buffer))) //get full path of exe |
| 143 | { |
| 144 | return FALSE; |
| 145 | } |
| 146 | |
| 147 | for (i = (lstrlenA(buffer) - 1); i >= 0; i--) //remove the exe file name from full path |
| 148 | { |
| 149 | if (buffer[i] == '\\') |
| 150 | { |
| 151 | buffer[i+1] = 0x00; |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | if (lstrcatA(buffer,logFileName) == 0) //append log file name to path |
| 157 | { |
| 158 | return FALSE; |
| 159 | } |
| 160 | |
| 161 | hFile = CreateFileA(buffer, GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); //open log file for writing |
| 162 | |
| 163 | if (hFile == INVALID_HANDLE_VALUE) |
| 164 | { |
| 165 | return FALSE; |
| 166 | } |
| 167 | |
| 168 | SetFilePointer(hFile, 0, 0, FILE_END); //set file pointer to the end of file |
| 169 | |
| 170 | if (WriteFile(hFile, text, (DWORD)lstrlenA(text), &lpNumberOfBytesWritten, 0)) //write message to logfile |
| 171 | { |
| 172 | wfRet = TRUE; |
| 173 | } |
| 174 | else |
| 175 | { |
| 176 | wfRet = FALSE; |
| 177 | } |
| 178 | |
| 179 | CloseHandle(hFile); |
| 180 | return wfRet; |
| 181 | } |
| 182 | |
| 183 | |
| 184 | #ifdef UNICODE |
no outgoing calls
no test coverage detected