1

Office ファイルを開くときに、ShellExecuteEx からエラーが返されました。これは、同じ OS/Office バージョンなどを使用している場合でも、一部の PC でのみ発生します。

私が取得しているエラーは ERROR_DDE_FAIL で、オフィスから次のテキストを含むメッセージが表示されます。「コマンドをアプリケーションに送信中にエラーが発生しました。」

これは私が使用しているコードです:

// Create SHELLEXECUTEINFO structure for passing as parameter to the ShellExecuteEx
// function. Suppress errors by enabling SEE_MASK_FLAG_NO_UI on fMask member.
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize           = sizeof( SHELLEXECUTEINFO );
ShExecInfo.fMask            = SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI ;
ShExecInfo.hwnd             = NULL;
ShExecInfo.lpFile           = lpFile;
ShExecInfo.lpVerb           = "open";
ShExecInfo.lpDirectory      = NULL;
ShExecInfo.nShow            = SW_SHOWNORMAL;
ShExecInfo.hInstApp         = NULL;

//HINSTANCE nResult = ShellExecute(NULL, "open", lpFile, NULL, NULL, SW_SHOWNORMAL);
HRESULT hr = ::ShellExecuteEx( &ShExecInfo );

if (hr == TRUE)
{
    ::WaitForInputIdle( ShExecInfo.hProcess, INFINITE );

    DWORD dwProcessId =  ::GetProcessId( ShExecInfo.hProcess );

    BOOL bHadLock = FALSE;

    // Wait while file lock has been released.
    while ( FileInUse( lpFile ) ) {
        bHadLock = TRUE;
        Sleep( 100 );
    }

    // Wait while process has stopped running in case of notepad or other
    // editors who don't lock file.
    if ( !bHadLock ) {
        DWORD lpExitCode;
        ::GetExitCodeProcess( ShExecInfo.hProcess, &lpExitCode );

        while ( lpExitCode == STATUS_PENDING ) {

            Sleep( 100 );
            ::GetExitCodeProcess( ShExecInfo.hProcess, &lpExitCode );
        }
    }
}
else
{
    DWORD dwError = ::GetLastError( );
    if (dwError == ERROR_DDE_FAIL) {
        // Why do I get this error and how to prevent this?
    }
}
4

0 に答える 0