bool cNTServiceControlManager::registerDevice(const cString& driverName, const cString& displayName, const cString& pathName, bool bootTime) { ASSERT(driverName.length() < 256); ASSERT(displayName.length() < 256); SC_HANDLE serviceHandle; serviceHandle = ::CreateService(m_scmHandle, driverName.getBuffer(), // name of service displayName.getBuffer(), // name to display SERVICE_ALL_ACCESS, // desired access SERVICE_KERNEL_DRIVER, // service type bootTime ? SERVICE_BOOT_START : SERVICE_DEMAND_START, // start type SERVICE_ERROR_NORMAL, // error control type pathName.getBuffer(), // service's binary NULL, // no load ordering group NULL, // no tag identifier NULL, // no dependencies NULL, // LocalSystem account NULL); // no password if (serviceHandle == NULL) { DWORD lastError = ::GetLastError(); if (lastError != ERROR_SERVICE_EXISTS) { // Access deined. XSTL_THROW(cDeviceException, cOS::getLastErrorString().getBuffer(), EXCEPTION_FAILED); } else { return false; } } ::CloseServiceHandle(serviceHandle); return true; }
bool cFile::isFileExist(const cString& filename) { WIN32_FIND_DATA findData; HANDLE hFind = FindFirstFile(OS_CSTRING(filename.getBuffer()), &findData); if (hFind == INVALID_HANDLE_VALUE) return false; FindClose(hFind); // If filename contains * or ? character this prevent any problems. if ((filename.find("*") == filename.length()) && (filename.find("?") == filename.length())) return true; return false; }
cFile::cFile(const cString& filename, const uint flags /* = cFile::READ */) : m_handle(INVALID_FILE_HANDLE) { DWORD dwShareMode = 0; DWORD dwDesiredAccess = 0; DWORD dwCreationDisposition = OPEN_EXISTING; /* fill in the dwDesiredAccess variable */ if (flags & READWRITE) dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; else { if (flags & READ) dwDesiredAccess|= GENERIC_READ; if (flags & WRITE) dwDesiredAccess|= GENERIC_WRITE; } /* fill in the dwSharedMode variable */ if (flags & SHARE_READ) dwShareMode|= FILE_SHARE_READ; if (flags & SHARE_WRITE) dwShareMode|= FILE_SHARE_WRITE; /* fill in the dwCreationDisposition variable */ if (flags & CREATE) dwCreationDisposition = CREATE_ALWAYS; HANDLE handle = CreateFile(OS_CSTRING(filename.getBuffer()), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, NULL); /* Test for open errors */ if (handle == INVALID_FILE_HANDLE) { cString msg = cOS::getLastErrorString() + ": " + filename; XSTL_THROW(cFileException, msg.getBuffer()); } openHandle(handle, flags, true); }
cNTServiceControlManager::cNTService::cNTService( cNTServiceControlManager* scmManager, const cString& serviceName) : m_scmManager(scmManager), m_serviceHandle(NULL) { ASSERT(m_scmManager != NULL); // Open the service m_serviceHandle = ::OpenService(m_scmManager->getSCMhandle(), serviceName.getBuffer(), SERVICE_ALL_ACCESS); if (m_serviceHandle == NULL) { // Access deined. XSTL_THROW(cDeviceException, cOS::getLastErrorString().getBuffer(), EXCEPTION_FAILED); } }
void basicOutput::writeUnicodeNullString(const cString& string, bool shouldPutZeroTerminator) { #ifdef XSTL_UNICODE // UNICODE version, just put it throw uint length = string.length(); if (shouldPutZeroTerminator) length++; pipeWrite(string.getBuffer(), length * sizeof(character)); #else unichar ch; for (uint i = 0; i < string.length(); i++) { ch = string[i]; pipeWrite(&ch, sizeof(ch)); } if (shouldPutZeroTerminator) { // Write the null terminated character ch = 0; pipeWrite(&ch, sizeof(ch)); } #endif }
bool cFile::deleteFile(const cString& filename) { return (::DeleteFile(OS_CSTRING(filename.getBuffer())) == TRUE); }
cString::CompareType cString::icompare(const cString& other) const { return icompare(other.getBuffer()); }