/** * @brief make primitive_content attribute string data * @param[in] payload : payload buffer * @param[in] attrs : oneM2M_Attribute list data pointer * @param[in] resourceType : oneM2M resource type value * @param[in] size : size of attrs list */ static void SetPCElement(char* payload, oneM2M_Attribute* attrs, int resourceType, int size) { char attr[512]; char pc[1024]; memset(attr, 0, sizeof(attr)); memset(pc, 0, sizeof(pc)); SetElement(attr, attrs, size); char* resource = RESOURCE_STR(resourceType); snprintf(pc, sizeof(pc), "<%s><%s>%s</%s></%s>", ATTR_PC, resource, attr, resource, ATTR_PC); strncat(payload, pc, strlen(pc)); }
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // // _tWinMain // Main entry point. Chooses appropriate startup mode. // int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE, LPTSTR lpCmdLine, int) { int nReturn = 0; // This is safe since lpCmdLine has no leading spaces and is never NULL if (lpCmdLine[0] == _T('!')) { // // Mode 1: Command line !bang handling // nReturn = HandleCommandLineBang(lpCmdLine); } else { TCHAR szAltConfigFile[MAX_PATH] = { 0 }; WORD wStartFlags = ParseCommandLine( lpCmdLine, szAltConfigFile, COUNTOF(szAltConfigFile)); if (GetSystemMetrics(SM_CLEANBOOT)) { // We're in safe mode. We really want Explorer to run now, in case // LiteStep is the reason we're here. // But if we can't, make sure we at least ignore startup apps // (see docs for GetSystemMetrics(SM_CLEANBOOT)) wStartFlags |= LSF_RUN_EXPLORER; wStartFlags &= ~LSF_RUN_STARTUPAPPS; } do { if (wStartFlags & LSF_RUN_EXPLORER) { // // Mode 2: (Try to) start Explorer // if (StartExplorerShell(EXPLORER_WAIT_TIMEOUT)) { // Explorer started as shell, no need try LiteStep as well wStartFlags &= ~LSF_RUN_LITESTEP; } else { wStartFlags &= ~LSF_RUN_EXPLORER; } } if (wStartFlags & LSF_RUN_LITESTEP) { HANDLE hMutex = NULL; if (IsOtherInstanceRunning(&hMutex)) { // // Mode 3a: Other LiteStep instance already running // RESOURCE_STR(hInst, IDS_LITESTEP_ERROR1, L"A previous instance of LiteStep was detected.\n" L"Are you sure you want to continue?"); // Can show a MessageBox here since the other instance // should have closed the welcome screen already INT idConfirm = RESOURCE_MSGBOX_F( L"LiteStep", MB_ICONINFORMATION | MB_YESNO | MB_DEFBUTTON2); if (idConfirm == IDNO) { wStartFlags &= ~LSF_RUN_LITESTEP; } } if (wStartFlags & LSF_RUN_LITESTEP) { // // Mode 3b: Start the shell! // nReturn = StartLitestep(hInst, wStartFlags, szAltConfigFile); } if (hMutex) { CloseHandle(hMutex); } if (nReturn == LRV_EXPLORER_START) { // User wants Explorer as shell anyway wStartFlags |= LSF_RUN_EXPLORER; } } } while (nReturn == LRV_EXPLORER_START && (wStartFlags & LSF_RUN_LITESTEP)); } return nReturn; }
bool Module::_LoadDll() { bool bReturn = false; if (!m_hInstance) { // Modules like popup2 like to call SetErrorMode. While that may not be // good style, there is little we can do about it. However, LoadLibrary // usually produces helpful error messages such as // "msvcp70.dll not found" which are not displayed if a module has // disabled them via SetErrorMode. We force their display here. // First, make Windows display all errors UINT uOldMode = SetErrorMode(0); if ((m_hInstance = LoadLibraryW(m_wzLocation.c_str())) != nullptr) { AssignToFunction(m_pInit, (initModuleProc) GetProcAddress( m_hInstance, "initModuleW")); if (!m_pInit) // Might be a legacy module, check for initModuleEx { initModuleProcA pInit = (initModuleProcA)GetProcAddress( m_hInstance, "initModuleEx"); if (!pInit) // Might be a BC module, check for underscore { pInit = (initModuleProcA)GetProcAddress( m_hInstance, "_initModuleEx"); } if (pInit) { m_pInit = [pInit] (HWND hWnd, HINSTANCE hInst, LPCWSTR pwzPath) -> int { char szPath[MAX_PATH]; WideCharToMultiByte(CP_ACP, 0, pwzPath, -1, szPath, sizeof(szPath), "", nullptr); return pInit(hWnd, hInst, szPath); }; } } m_pQuit = (quitModuleProc)GetProcAddress( m_hInstance, "quitModule"); if (!m_pQuit) // Might be a BC module, check for underscore { m_pQuit = (quitModuleProc)GetProcAddress( m_hInstance, "_quitModule"); } if (m_pInit == nullptr) { RESOURCE_STR(nullptr, IDS_INITMODULEEXNOTFOUND_ERROR, L"Error: Could not find initModule().\n" L"\n" L"Please confirm that the dll is a LiteStep module,\n" L"and check with the author for updates."); } else if (m_pQuit == nullptr) { RESOURCE_STR(nullptr, IDS_QUITMODULENOTFOUND_ERROR, L"Error: Could not find quitModule().\n" L"\n" L"Please confirm that the dll is a LiteStep module."); } else { bReturn = true; } } else { HRESULT hrError = HrGetLastError(); #if defined(_WIN64) if (GetModuleArchitecture(m_wzLocation.c_str()) == IMAGE_NT_OPTIONAL_HDR32_MAGIC) { RESOURCE_STR(nullptr, IDS_MODULEWRONGARCH64_ERROR, L"Error: Could not load module.\n" L"\n" L"The module seems to compiled for 32-bit LiteStep. This is a 64-bit version of LiteStep, which can only load 64-bit modules."); } #else if (GetModuleArchitecture(m_wzLocation.c_str()) == IMAGE_NT_OPTIONAL_HDR64_MAGIC) { RESOURCE_STR(nullptr, IDS_MODULEWRONGARCH32_ERROR, L"Error: Could not load module.\n" L"\n" L"The module seems to compiled for 64-bit LiteStep. This is a 32-bit version of LiteStep, which can only load 32-bit modules."); } #endif else if (PathFileExistsW(m_wzLocation.c_str())) { RESOURCE_STR(nullptr, IDS_MODULEDEPENDENCY_ERROR, L"Error: Could not load module.\n" L"\n" L"This is likely a case of a missing C Run-Time Library" L"or other dependency." L"\n" L"Error Information:" L"\n"); size_t nLen = 0; StringCchLengthW(resourceTextBuffer, _countof(resourceTextBuffer), &nLen); DescriptionFromHR(hrError, resourceTextBuffer + nLen, _countof(resourceTextBuffer) - nLen); } else { RESOURCE_STR(nullptr, IDS_MODULENOTFOUND_ERROR, L"Error: Could not locate module.\n" L"\n" L"Please check your configuration."); } } // Second, restore the old state SetErrorMode(uOldMode); if (!bReturn) { LPCWSTR pwzFileName = PathFindFileNameW(m_wzLocation.c_str()); RESOURCE_MSGBOX_F(pwzFileName, MB_ICONERROR); if (m_hInstance) { FreeLibrary(m_hInstance); m_hInstance = nullptr; } } } return bReturn; }