int CALLBACK DirList_CompareProcRw(LPARAM lp1,LPARAM lp2,LPARAM lFlags) { HRESULT hr; int result; LPLV_ITEMDATA lplvid1 = (LPLV_ITEMDATA)lp1; LPLV_ITEMDATA lplvid2 = (LPLV_ITEMDATA)lp2; hr = (lplvid1->lpsf->lpVtbl->CompareIDs( lplvid1->lpsf, lFlags, lplvid1->pidl, lplvid2->pidl)); result = -(short)(SCODE_CODE(GetScode(hr))); if (result != 0) return(result); hr = (lplvid1->lpsf->lpVtbl->CompareIDs( lplvid1->lpsf, 0, lplvid1->pidl, lplvid2->pidl)); result = -(short)(SCODE_CODE(GetScode(hr))); return(result); }
void DisplayDaoException(CDaoException* e) { CString strMsg; if (e->m_pErrorInfo!=NULL) { strMsg.Format( _T("%s (%d)\n\n") _T("Would you like to see help?"), (LPCTSTR)e->m_pErrorInfo->m_strDescription, e->m_pErrorInfo->m_lErrorCode); if (AfxMessageBox(strMsg, MB_YESNO) == IDYES) { WinHelp(GetDesktopWindow(), e->m_pErrorInfo->m_strHelpFile, HELP_CONTEXT, e->m_pErrorInfo->m_lHelpContext); } } else { strMsg.Format( _T("ERROR:CDaoException\n\n") _T("SCODE_CODE =%d\n") _T("SCODE_FACILITY =%d\n") _T("SCODE_SEVERITY =%d\n") _T("ResultFromScode =%d\n"), SCODE_CODE (e->m_scode), SCODE_FACILITY (e->m_scode), SCODE_SEVERITY (e->m_scode), ResultFromScode (e->m_scode)); AfxMessageBox(strMsg); } }
int CALLBACK CCJShellTree::TreeViewCompareProc(LPARAM lparam1, LPARAM lparam2, LPARAM /*lparamSort*/) { LPTVITEMDATA lptvid1=(LPTVITEMDATA)lparam1; LPTVITEMDATA lptvid2=(LPTVITEMDATA)lparam2; HRESULT hr; hr = lptvid1->lpsfParent->CompareIDs(0, lptvid1->lpi, lptvid2->lpi); if (FAILED(hr)) return 0; return (short)SCODE_CODE(GetScode(hr)); }
int CALLBACK CMyTreeView::CompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { UNREFERENCED_PARAMETER(lParamSort); TreeItemData* pItem1 = (TreeItemData*)lParam1; TreeItemData* pItem2 = (TreeItemData*)lParam2; HRESULT hr; hr = pItem1->GetParentFolder().CompareIDs(0, pItem1->GetRelCpidl(), pItem2->GetRelCpidl()); if (FAILED(hr)) return 0; return (short)SCODE_CODE(GetScode(hr)); }
BOOL WriteFileWithRetry(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, DWORD nNumRetries) { DWORD nTry; BOOL readFilePointer; LARGE_INTEGER liFilePointer, liZero = { { 0,0 } }; static char* retry_msg = " - retrying..."; // Need to get the current file pointer in case we need to retry readFilePointer = SetFilePointerEx(hFile, liZero, &liFilePointer, FILE_CURRENT); if (!readFilePointer) uprintf(" Warning - Could not read file pointer: %s", WindowsErrorString()); if (nNumRetries == 0) nNumRetries = 1; for (nTry = 1; nTry <= nNumRetries; nTry++) { // Need to rewind our file position on retry - if we can't even do that, just give up if ((nTry > 1) && (!SetFilePointerEx(hFile, liFilePointer, NULL, FILE_BEGIN))) { uprintf(" Could not set file pointer - aborting"); break; } if (WriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, NULL)) { if (nNumberOfBytesToWrite == *lpNumberOfBytesWritten) return TRUE; // Some large drives return 0, even though all the data was written - See github #787 */ if (large_drive && (*lpNumberOfBytesWritten == 0)) { uprintf("Warning: Possible short write"); return TRUE; } uprintf(" Wrote %d bytes but requested %d%s", *lpNumberOfBytesWritten, nNumberOfBytesToWrite, nTry < nNumRetries ? retry_msg : ""); } else { uprintf(" Write error [0x%08X]%s", GetLastError(), nTry < nNumRetries ? retry_msg : ""); } // If we can't reposition for the next run, just abort if (!readFilePointer) break; Sleep(200); } if (SCODE_CODE(GetLastError()) == ERROR_SUCCESS) SetLastError(ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT); return FALSE; }
// Fehler-Behandlung realisieren void DisplayDaoException(CDaoException* e) { ASSERT (NULL != e); ASSERT (e -> IsKindOf (RUNTIME_CLASS(CDaoException))); CString strMsg; if (e->m_pErrorInfo!=NULL) { CString strCaption; strCaption.Format(_T("Datenbankfehler %ld"), e->m_pErrorInfo->m_lErrorCode); strMsg.Format( _T("\"%s\"\n\n") _T("Hilfe zum Fehler aufrufen ?"), (LPCTSTR)e->m_pErrorInfo->m_strDescription); if (::MessageBox(GetDesktopWindow(), strMsg, strCaption, MB_YESNO|MB_ICONQUESTION) == IDYES) { CString strHelpFile; VERIFY (strHelpFile.LoadString (IDS_ERROR_HELP_FILE_NAME)); ::WinHelp(GetDesktopWindow(), // e->m_pErrorInfo->m_strHelpFile, strHelpFile, HELP_CONTEXT, e->m_pErrorInfo->m_lHelpContext); } } else { strMsg.Format( _T("Fehler: CDaoException\n\n") _T("SCODE_CODE =%d\n") _T("SCODE_FACILITY =%d\n") _T("SCODE_SEVERITY =%d\n") _T("ResultFromScode =%d\n"), SCODE_CODE (e->m_scode), SCODE_FACILITY (e->m_scode), SCODE_SEVERITY (e->m_scode), ResultFromScode (e->m_scode)); ::MessageBox(GetDesktopWindow(), strMsg, AfxGetAppName (), MB_OK|MB_ICONINFORMATION); } }
int CALLBACK COXShellNamespaceNavigator::CompareObjectsProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { #if defined (_WINDLL) #if defined (_AFXDLL) AFX_MANAGE_STATE(AfxGetAppModuleState()); #else AFX_MANAGE_STATE(AfxGetStaticModuleState()); #endif #endif UNREFERENCED_PARAMETER(lParamSort); LPNAMESPACEOBJECT lpFolder1=(LPNAMESPACEOBJECT)lParam1; LPNAMESPACEOBJECT lpFolder2=(LPNAMESPACEOBJECT)lParam2; ASSERT(lpFolder1->lpsfParent==lpFolder2->lpsfParent); // Use IShellBrowser::CompareIDs method to compare two folders. // The first argument have to be zero. // If this method is successful, the CODE field of the status code (SCODE) // contains one of the following values: // Less than zero - The first item should precede the second // (pidl1 < pidl2). // Greater than zero - The first item should follow the second // (pidl1 > pidl2). // Zero - The two items are the same (pidl1 = pidl2). // // If this method is unsuccessful, it returns an OLE-defined error code. HRESULT hResult=lpFolder1->lpsfParent-> CompareIDs(0,lpFolder1->lpRelativeIDL,lpFolder2->lpRelativeIDL); // if above method failed let's take it as items are equal if(FAILED(hResult)) return 0; // return CODE field of status code of result value return (short)SCODE_CODE(GetScode(hResult)); }
/* #FN# Callback routine for sorting the tree */ int CALLBACK /* #AS# A negative value if the first item should precede the second, a positive value if the first item should follow the second, or zero if the two items are equivalent */ CShellTree:: TreeViewCompareProc( LPARAM lparam1, /* #IN# */ LPARAM lparam2, /* #IN# */ LPARAM lparamSort /* #IN# */ ) { LPTVITEMDATA lptvid1 = (LPTVITEMDATA)lparam1; LPTVITEMDATA lptvid2 = (LPTVITEMDATA)lparam2; HRESULT hr = lptvid1->lpsfParent->CompareIDs( 0, lptvid1->lpi, lptvid2->lpi ); if( FAILED(hr) ) return 0; return (short)SCODE_CODE(GetScode( hr )); } /* #OF# CShellTree::TreeViewCompareProc */
int DriveBox_Fill(HWND hwnd) { LPSHELLFOLDER lpsfDesktop; LPSHELLFOLDER lpsf; // Workspace == CSIDL_DRIVES LPITEMIDLIST pidl; LPITEMIDLIST pidlEntry; LPENUMIDLIST lpe; COMBOBOXEXITEM cbei; LPDC_ITEMDATA lpdcid; ULONG dwAttributes = 0; DWORD grfFlags = SHCONTF_FOLDERS; // Init ComboBox SendMessage(hwnd,WM_SETREDRAW,0,0); SendMessage(hwnd,CB_RESETCONTENT,0,0); ZeroMemory(&cbei,sizeof(COMBOBOXEXITEM)); cbei.mask = CBEIF_TEXT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_LPARAM; cbei.pszText = LPSTR_TEXTCALLBACK; cbei.cchTextMax = MAX_PATH; cbei.iImage = I_IMAGECALLBACK; cbei.iSelectedImage = I_IMAGECALLBACK; // Get pidl to [My Computer] if (NOERROR == SHGetSpecialFolderLocation(hwnd, CSIDL_DRIVES, &pidl)) { // Get Desktop Folder if (NOERROR == SHGetDesktopFolder(&lpsfDesktop)) { // Bind pidl to IShellFolder if (NOERROR == lpsfDesktop->lpVtbl->BindToObject( lpsfDesktop, pidl, NULL, &IID_IShellFolder, &lpsf)) { // Create an Enumeration object for lpsf if (NOERROR == lpsf->lpVtbl->EnumObjects( lpsf, hwnd, grfFlags, &lpe)) { // Enumerate the contents of [My Computer] while (NOERROR == lpe->lpVtbl->Next( lpe, 1, &pidlEntry, NULL)) { // Add item to the List if it is part of the // Filesystem dwAttributes = SFGAO_FILESYSTEM; lpsf->lpVtbl->GetAttributesOf( lpsf, 1, &pidlEntry, &dwAttributes); if (dwAttributes & SFGAO_FILESYSTEM) { // Windows XP: check if pidlEntry is a drive SHDESCRIPTIONID di; HRESULT hr; hr = SHGetDataFromIDList(lpsf,pidlEntry,SHGDFIL_DESCRIPTIONID, &di,sizeof(SHDESCRIPTIONID)); if (hr != NOERROR || (di.dwDescriptionId >= SHDID_COMPUTER_DRIVE35 && di.dwDescriptionId <= SHDID_COMPUTER_OTHER)) { lpdcid = CoTaskMemAlloc(sizeof(DC_ITEMDATA)); //lpdcid->pidl = IL_Copy(pidlEntry); lpdcid->pidl = pidlEntry; lpdcid->lpsf = lpsf; lpsf->lpVtbl->AddRef(lpsf); // Insert sorted ... { COMBOBOXEXITEM cbei2; LPDC_ITEMDATA lpdcid2; HRESULT hr; cbei2.mask = CBEIF_LPARAM; cbei2.iItem = 0; while ((SendMessage(hwnd,CBEM_GETITEM,0,(LPARAM)&cbei2))) { lpdcid2 = (LPDC_ITEMDATA)cbei2.lParam; hr = (lpdcid->lpsf->lpVtbl->CompareIDs( lpdcid->lpsf, 0, lpdcid->pidl, lpdcid2->pidl)); if ((short)(SCODE_CODE(GetScode(hr))) < 0) break; else cbei2.iItem++; } cbei.iItem = cbei2.iItem; cbei.lParam = (LPARAM)lpdcid; SendMessage(hwnd,CBEM_INSERTITEM,0,(LPARAM)&cbei); } } } } // IEnumIDList::Next() lpe->lpVtbl->Release(lpe); } // IShellFolder::EnumObjects() lpsf->lpVtbl->Release(lpsf); } // IShellFolder::BindToObject() CoTaskMemFree(pidl); } // SHGetSpecialFolderLocation() lpsfDesktop->lpVtbl->Release(lpsfDesktop); } // SHGetDesktopFolder() SendMessage(hwnd,WM_SETREDRAW,1,0); // Return number of items added to combo box return ((int)SendMessage(hwnd,CB_GETCOUNT,0,0)); }
DWORD CEncryptionDriver::WaitForNotification(_Out_ /*PUCA_NOTIFICATION*/ PVOID *Notification, _Out_ LPDWORD lpdwBufferSize) { #if 0 UCA_FLT_QUERY_MESSAGE QueryMessage; UCA_FLT_GET_MESSAGE RequestMessage; UCA_NOTIFICATION_INFO NotificationInfo; DWORD BytesReturned; HRESULT hResult; DWORD dwError; TRACE_ENTER(TraceHandle); if (!Notification || !lpdwBufferSize) return ERROR_INVALID_PARAMETER; *Notification = NULL; *lpdwBufferSize = 0; /* Request the next message info */ QueryMessage.Header.Message = FLT_GET_NEXT_MESSAGE; /* This call blocks, so set the cancel IO event */ QueryMessage.Header.hCancelIo = m_hCancelIo; /* Send the message to the driver */ hResult = FilterSendMessage(m_hPort, &QueryMessage, sizeof(UCA_FLT_QUERY_MESSAGE), &NotificationInfo, sizeof(UCA_NOTIFICATION_INFO), &BytesReturned); if (hResult != S_OK) { TRACE_ERROR(TraceHandle, "Failed to send a query message to the driver : %X", hResult); return SCODE_CODE(hResult); } TRACE_INFO(TraceHandle, "Handle is %X", NotificationInfo.NotificationHandle); TRACE_INFO(TraceHandle, "Allocating %lu bytes", NotificationInfo.NotificationSize); /* Allocate memory to hold the data */ *Notification = (PUCA_NOTIFICATION)HeapAlloc(GetProcessHeap(), 0, NotificationInfo.NotificationSize); if (*Notification == NULL) return ERROR_NOT_ENOUGH_MEMORY; /* Set the header to actually get the message */ RequestMessage.Header.Message = FLT_GET_MESSAGE; RequestMessage.Header.hCancelIo = NULL; /* Set the handle to the data we want */ RequestMessage.NotificationHandle = NotificationInfo.NotificationHandle; /* Send the message to the driver */ hResult = FilterSendMessage(m_hPort, &RequestMessage, sizeof(UCA_FLT_GET_MESSAGE), *Notification, NotificationInfo.NotificationSize, &BytesReturned); if (hResult == S_OK) { /* Store the buffer size */ *lpdwBufferSize = NotificationInfo.NotificationSize; dwError = ERROR_SUCCESS; } else { /* Cleanup */ TRACE_ERROR(TraceHandle, "Failed to send a get message to the driver : %X", hResult); dwError = SCODE_CODE(hResult); HeapFree(GetProcessHeap(), 0, *Notification); *Notification = NULL; } TRACE_EXIT(TraceHandle); #endif return 0;//dwError; }
const char* StrError(DWORD error_code) { if ( (!IS_ERROR(error_code)) || (SCODE_CODE(error_code) == ERROR_SUCCESS)) { return "Success"; } if (SCODE_FACILITY(error_code) != FACILITY_STORAGE) { uprintf("StrError: non storage - %08X (%X)\n", error_code, SCODE_FACILITY(error_code)); SetLastError(error_code); return WindowsErrorString(); } switch (SCODE_CODE(error_code)) { case ERROR_GEN_FAILURE: return "Undetermined error while formatting"; case ERROR_INCOMPATIBLE_FS: return "Cannot use the selected file system for this media"; case ERROR_ACCESS_DENIED: return "Access to the media is denied"; case ERROR_WRITE_PROTECT: return "Media is write protected"; case ERROR_DEVICE_IN_USE: return "The device is in use by another process\n" "Please close any other process that may be accessing the device"; case ERROR_CANT_QUICK_FORMAT: return "Quick format is not available for this device"; case ERROR_LABEL_TOO_LONG: return "The volume label is invalid"; case ERROR_INVALID_CLUSTER_SIZE: return "The selected cluster size is not valid for this device"; case ERROR_INVALID_VOLUME_SIZE: return "The volume size is invalid"; case ERROR_NO_MEDIA_IN_DRIVE: return "Please insert a media in drive"; case ERROR_NOT_SUPPORTED: return "An unsupported command was received"; case ERROR_NOT_ENOUGH_MEMORY: return "Memory allocation error"; case ERROR_READ_FAULT: return "Read error"; case ERROR_WRITE_FAULT: return "Write error"; case ERROR_OPEN_FAILED: return "Could not open media. It may be in use by another process.\n" "Please re-plug the media and try again"; case ERROR_PARTITION_FAILURE: return "Error while partitioning drive"; case ERROR_CANNOT_COPY: return "Could not copy files to target drive"; case ERROR_CANCELLED: return "Cancelled by user"; case ERROR_CANT_START_THREAD: return "Unable to create formatting thread"; case ERROR_BADBLOCKS_FAILURE: return "Bad blocks check didn't complete"; case ERROR_ISO_SCAN: return "ISO image scan failure"; case ERROR_ISO_EXTRACT: return "ISO image extraction failure"; case ERROR_CANT_REMOUNT_VOLUME: return "Unable to remount volume. You may have to use the\n" "mountvol.exe command to make your device accessible again"; case ERROR_CANT_PATCH: return "Unable to patch/setup files for boot"; default: uprintf("Unknown error: %08X\n", error_code); SetLastError(error_code); return WindowsErrorString(); } }
const char* _StrError(DWORD error_code) { if ( (!IS_ERROR(error_code)) || (SCODE_CODE(error_code) == ERROR_SUCCESS)) { return lmprintf(MSG_050); } if (SCODE_FACILITY(error_code) != FACILITY_STORAGE) { uprintf("StrError: non storage - %08X (%X)\n", error_code, SCODE_FACILITY(error_code)); SetLastError(error_code); return WindowsErrorString(); } switch (SCODE_CODE(error_code)) { case ERROR_GEN_FAILURE: return lmprintf(MSG_051); case ERROR_INCOMPATIBLE_FS: return lmprintf(MSG_052); case ERROR_ACCESS_DENIED: return lmprintf(MSG_053); case ERROR_WRITE_PROTECT: return lmprintf(MSG_054); case ERROR_DEVICE_IN_USE: return lmprintf(MSG_055); case ERROR_CANT_QUICK_FORMAT: return lmprintf(MSG_056); case ERROR_LABEL_TOO_LONG: return lmprintf(MSG_057); case ERROR_INVALID_HANDLE: return lmprintf(MSG_058); case ERROR_INVALID_CLUSTER_SIZE: return lmprintf(MSG_059); case ERROR_INVALID_VOLUME_SIZE: return lmprintf(MSG_060); case ERROR_NO_MEDIA_IN_DRIVE: return lmprintf(MSG_061); case ERROR_NOT_SUPPORTED: return lmprintf(MSG_062); case ERROR_NOT_ENOUGH_MEMORY: return lmprintf(MSG_063); case ERROR_READ_FAULT: return lmprintf(MSG_064); case ERROR_WRITE_FAULT: return lmprintf(MSG_065); case ERROR_INSTALL_FAILURE: return lmprintf(MSG_066); case ERROR_OPEN_FAILED: return lmprintf(MSG_067); case ERROR_PARTITION_FAILURE: return lmprintf(MSG_068); case ERROR_CANNOT_COPY: return lmprintf(MSG_069); case ERROR_CANCELLED: return lmprintf(MSG_070); case ERROR_CANT_START_THREAD: return lmprintf(MSG_071); case ERROR_BADBLOCKS_FAILURE: return lmprintf(MSG_072); case ERROR_ISO_SCAN: return lmprintf(MSG_073); case ERROR_ISO_EXTRACT: return lmprintf(MSG_074); case ERROR_CANT_REMOUNT_VOLUME: return lmprintf(MSG_075); case ERROR_CANT_PATCH: return lmprintf(MSG_076); case ERROR_CANT_ASSIGN_LETTER: return lmprintf(MSG_077); case ERROR_CANT_MOUNT_VOLUME: return lmprintf(MSG_078); case ERROR_NOT_READY: return lmprintf(MSG_079); default: uprintf("Unknown error: %08X\n", error_code); SetLastError(error_code); return WindowsErrorString(); } }
Error WordViewer::showDocument(QString& path) { Error errorHR = Success(); HRESULT hr = S_OK; // Allow Word to become the foreground window. CoAllowSetForegroundWindow // would be preferable here, since we'd be able to restrict activation to // only the process we started, but it is not exposed by MinGW headers. // Note that AllowSetForegroundWindow already limits activation to processes // initiated by the foreground process, and self-expires on user input. AllowSetForegroundWindow(ASFW_ANY); // If we have an active IDispatch pointer to Word, check to see whether // it has been closed if (idispWord_ != NULL) { // Test the interface by looking up a known DISPID const WCHAR* wstrQuit = L"Quit"; DISPID dispid; hr = idispWord_->GetIDsOfNames(IID_NULL, const_cast<WCHAR**>(&wstrQuit), 1, LOCALE_USER_DEFAULT, &dispid); // If the lookup fails, release this IDispatch pointer--it's stale. // We'll CoCreate a new instance of Word below. if (FAILED(hr) && SCODE_CODE(hr) == RPC_S_SERVER_UNAVAILABLE) { idispWord_->Release(); idispWord_ = NULL; } } // Get an IDispatch for the Word Application root object if (idispWord_ == NULL) { CLSID clsid; LPCOLESTR progId = L"Word.Application"; CoInitialize(NULL); VERIFY_HRESULT(CLSIDFromProgID(progId, &clsid)); VERIFY_HRESULT(CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, reinterpret_cast<void**>(&idispWord_))); idispWord_->AddRef(); } // Make Word visible errorHR = showWord(); if (errorHR) return errorHR; IDispatch* idispDocs; IDispatch* idispDoc; VERIFY_HRESULT(getIDispatchProp(idispWord_, L"Documents", &idispDocs)); // Open the documenet path = path.replace(QChar(L'/'), QChar(L'\\')); errorHR = openDocument(path, idispDocs, &idispDoc); if (errorHR) return errorHR; if (docPath_ == path) { // Reopening the last-opened doc: apply the scroll position if we have // one cached if (docScrollX_ > 0 || docScrollY_ > 0) setDocumentPosition(idispDoc, docScrollX_, docScrollY_); } else { // Opening a different doc: forget scroll position and save the doc name docScrollX_ = 0; docScrollY_ = 0; docPath_ = path; } // Bring Word to the foreground VERIFY_HRESULT(invokeDispatch(DISPATCH_METHOD, NULL, idispWord_, L"Activate", 0)); LErrExit: return errorHR; }
bool PluginLoader::RegisterShellExtDll(QString dllPath, bool bRegister,bool quiet) { if(Debug) { QString message; if(bRegister) message+=QString("Try load the dll: %1, and ").arg(dllPath); else message+=QString("Try unload the dll: %1, and ").arg(dllPath); if(quiet) message+=QString("don't open the UAC"); else message+=QString("open the UAC if needed"); QMessageBox::information(NULL,"Debug",message); } ////////////////////////////// First way to load ////////////////////////////// wchar_t arrayArg[65535]; int size_lenght; // first try - load dll and register it manually. HRESULT hResult = S_OK; // if failed - try by loading extension manually (would fail on vista when running as user) hResult = CoInitializeEx(NULL, COINIT_MULTITHREADED); if(SUCCEEDED(hResult)) { HRESULT (STDAPICALLTYPE *pfn)(void); size_lenght=dllPath.toWCharArray(arrayArg); HINSTANCE hMod = LoadLibrary(arrayArg); // load the dll if(hMod == NULL) hResult = HRESULT_FROM_WIN32(GetLastError()); if(SUCCEEDED(hResult) && !hMod) hResult = E_FAIL; if(SUCCEEDED(hResult)) { (FARPROC&)pfn = GetProcAddress(hMod, (bRegister ? "DllRegisterServer" : "DllUnregisterServer")); if(pfn == NULL) hResult = E_FAIL; if(SUCCEEDED(hResult)) hResult = (*pfn)(); CoFreeLibrary(hMod); } CoUninitialize(); if(SUCCEEDED(hResult) && SCODE_CODE(hResult) != ERROR_ACCESS_DENIED) return true; else ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("fail by LoadLibrary: %1, error code: %2").arg(dllPath).arg((quint32)hResult)); } else ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("fail by CoInitializeEx: %1, error code: %2").arg(dllPath).arg((quint32)hResult)); ////////////////////////////// Second way to load ////////////////////////////// QStringList arguments; if(!Debug) arguments.append("/s"); if(!bRegister) arguments.append("/u"); arguments.append(dllPath); QString argumentsString; for (int i = 0; i < arguments.size(); ++i) { if(argumentsString.isEmpty()) argumentsString+=arguments.at(i); else if(i == arguments.size()) argumentsString+=" \""+arguments.at(i)+"\""; else argumentsString+=' '+arguments.at(i); } ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start: regsvr32 "+argumentsString); int result=QProcess::execute("regsvr32",arguments); bool ok=false; if(result==0) ok=true; #if ! defined(_M_X64) if(result==999 && !changeOfArchDetected)//code of wrong arch for the dll { changeOfArchDetected=true; QStringList temp; temp = importantDll; secondDll = importantDll; importantDll = temp; return false; } #endif if(result==5) { if(!quiet || (!bRegister && correctlyLoaded.contains(dllPath))) { ////////////////////////////// Last way to load ////////////////////////////// ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"try it in win32"); // try with regsvr32, win32 because for admin dialog size_lenght=argumentsString.toWCharArray(arrayArg); //size_lenght*sizeof(wchar_t) wcscpy(arrayArg+size_lenght*sizeof(wchar_t),TEXT("\0")); SHELLEXECUTEINFO sei; memset(&sei, 0, sizeof(sei)); sei.cbSize = sizeof(sei); sei.fMask = SEE_MASK_UNICODE; sei.lpVerb = TEXT("runas"); sei.lpFile = TEXT("regsvr32.exe"); ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"in win32 mode: arrayArg: "+QString::fromWCharArray(arrayArg,size_lenght)); sei.lpParameters = arrayArg; sei.nShow = SW_SHOW; ok=ShellExecuteEx(&sei); } else ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"not try because need be quiet: "+dllPath); } else ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("regsvr32 terminated with: %1").arg(result)); correctlyLoaded.remove(dllPath); if(!bRegister) HardUnloadDLL(dllPath); return ok; }
int __cdecl wmain( __in int argc, __in WCHAR * argv[] ) { HRESULT hr = S_OK; LPWSTR pwzCommandLine = NULL; LPWSTR wzAppId = NULL; GUID guidApp; DWORD64 dw64Version; LPWSTR pwzFeedUri = NULL; LPWSTR pwzApplicationPath = NULL; LPWSTR pwzApplicationDirectory = NULL; DWORD64 dw64NextUpdateTime = 0; BOOL fUpdateReady = FALSE; DWORD64 dw64UpdateVersion = 0; LPWSTR pwzFeedPath = NULL; LPWSTR pwzSetupPath = NULL; DWORD dwTimeToLive = 0; LPWSTR pwzApplicationId = NULL; LPWSTR pwzApplicationSource = NULL; BOOL bDeleteUpdateInfoPath = FALSE; BOOL bDeleteUpdateBinaryPath = FALSE; HANDLE hProcess = INVALID_HANDLE_VALUE; HANDLE hUpdateMutex = INVALID_HANDLE_VALUE; // // Process command-line arguments. // for (int i=1; i<argc; i++) { if (argv[i][0] == L'-' || argv[i][0] == L'/') { if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], -1, L"ac", -1)) { if (wzAppId) { ExitOnFailure(hr = E_INVALIDARG, "May only specify one -ac switch."); } wzAppId = argv[++i]; hr = ::CLSIDFromString(wzAppId, &guidApp); ExitOnFailure(hr, "Failed to parse the -ac argument."); } } else { ExitOnFailure1(hr = E_INVALIDARG, "Bad commandline argument: %S", argv[i]); } } ExitOnNull(wzAppId, hr, E_INVALIDARG, "Must specify a -ac switch."); hr = GetUpdateMutex(&guidApp, &hUpdateMutex); if (FAILED(hr)) { TraceError(hr, "Failed to query the update mutex. Proceeding as if this process didn't acquire the mutex."); } hr = RssUpdateGetAppInfo(wzAppId, &dw64Version, &pwzFeedUri, &pwzApplicationPath); ExitOnFailure(hr, "Failed to get app info."); // If we acquired the update lock and there is already an update downloaded, install that now. if (INVALID_HANDLE_VALUE != hUpdateMutex) { Trace(REPORT_DEBUG, "Got the update mutex. Will check for updates on local machine before launching app."); // If an update is available and higher version that the application currently on the local // machine, launch the install and bail. hr = RssUpdateTryLaunchUpdate(wzAppId, dw64Version, &hProcess, &dw64NextUpdateTime); if (SUCCEEDED(hr)) { if (hProcess) { ::CloseHandle(hProcess); ExitFunction(); // bail since we're doing an update } } } else { Trace(REPORT_DEBUG, "Didn't get the update mutex. Won't check for updates."); } hr = PathExpand(&pwzCommandLine, pwzApplicationPath, PATH_EXPAND_FULLPATH); ExitOnFailure(hr, "Failed to expand application path."); if (pwzCommandLine && L'\"' != pwzCommandLine[0]) { // Get the working directory. hr = PathGetDirectory(pwzCommandLine, &pwzApplicationDirectory); ExitOnFailure(hr, "Failed to get application directory from command-line."); // Put quotes around the command line. hr = StrAllocPrefix(&pwzCommandLine, L"\"", 0); ExitOnFailure(hr, "Failed to prefix command-line with quote."); hr = StrAllocConcat(&pwzCommandLine, L"\"", 0); ExitOnFailure(hr, "Failed to concat command-line with quote."); } Trace1(REPORT_DEBUG, "Launching the target app with commandline: %ls.", pwzCommandLine); hr = LaunchTarget(pwzCommandLine, pwzApplicationDirectory, &hProcess); ExitOnFailure1(hr, "Failed to launch %ls", pwzCommandLine); // If we acquired the update lock then check to see if enough time has passed such that we look for more updates. if (INVALID_HANDLE_VALUE != hUpdateMutex) { hr = RssUpdateCheckFeed(wzAppId, dw64Version, pwzFeedUri, dw64NextUpdateTime); hr = S_OK; } LExit: if (INVALID_HANDLE_VALUE != hUpdateMutex) { ::CloseHandle(hUpdateMutex); } if (INVALID_HANDLE_VALUE != hProcess) { ::CloseHandle(hProcess); } if (bDeleteUpdateInfoPath) { ::DeleteFileW(pwzFeedPath); } if (bDeleteUpdateBinaryPath) { ::DeleteFileW(pwzSetupPath); } ReleaseStr(pwzApplicationSource); ReleaseStr(pwzApplicationId); ReleaseStr(pwzSetupPath); ReleaseStr(pwzFeedPath); ReleaseStr(pwzApplicationPath); ReleaseStr(pwzFeedUri); ReleaseStr(pwzCommandLine); ReleaseStr(pwzApplicationDirectory); return SCODE_CODE(hr); }
//*************************************************************************************** int CBCGPShellList::OnCompareItems (LPARAM lParam1, LPARAM lParam2, int iColumn) { ASSERT_VALID (this); LPBCGCBITEMINFO pItem1 = (LPBCGCBITEMINFO)lParam1; LPBCGCBITEMINFO pItem2 = (LPBCGCBITEMINFO)lParam2; ASSERT (pItem1 != NULL); ASSERT (pItem2 != NULL); SHFILEINFO sfi1; SHFILEINFO sfi2; TCHAR szPath1 [MAX_PATH]; TCHAR szPath2 [MAX_PATH]; CFileStatus fs1; CFileStatus fs2; int nRes = 0; switch (iColumn) { case BCGPShellList_ColumnName: { HRESULT hr = pItem1->pParentFolder->CompareIDs (0, pItem1->pidlRel, pItem2->pidlRel); if (FAILED (hr)) { return 0; } nRes = (short) SCODE_CODE (GetScode (hr)); } break; case BCGPShellList_ColumnType: if (SHGetFileInfo ((LPCTSTR)pItem1->pidlFQ, 0, &sfi1, sizeof(sfi1), SHGFI_PIDL | SHGFI_TYPENAME) && SHGetFileInfo ((LPCTSTR)pItem2->pidlFQ, 0, &sfi2, sizeof(sfi2), SHGFI_PIDL | SHGFI_TYPENAME)) { nRes = lstrcmpi (sfi1.szTypeName, sfi2.szTypeName); } break; case BCGPShellList_ColumnSize: case BCGPShellList_ColumnModified: if (SHGetPathFromIDList (pItem1->pidlFQ, szPath1) && CFile::GetStatus (szPath1, fs1)) { if (SHGetPathFromIDList (pItem2->pidlFQ, szPath2) && CFile::GetStatus (szPath2, fs2)) { if (iColumn == BCGPShellList_ColumnSize) { nRes = fs1.m_size < fs2.m_size ? -1 : fs1.m_size > fs2.m_size ? 1 : 0; } else { nRes = fs1.m_mtime < fs2.m_mtime ? -1 : fs1.m_mtime > fs2.m_mtime ? 1 : 0; } } else { nRes = 1; } } else { nRes = -1; } break; } return nRes; }