Launching of the Metro Style Application (Windows Reader) failed (throw the ShellExecute).

Answered Launching of the Metro Style Application (Windows Reader) failed (throw the ShellExecute).

  • Wednesday, March 28, 2012 4:35 PM
     
      Has Code

    Hi All,

    I have a problem with launching a Windows Reader from my desktop application under Windows 8. I use ShellExecute. This function should launch an application according to extension of document. Here are code below:

    // ShellExecuteTest.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    
    namespace OpenAs
    {
      static LPTSTR parameterBuffer = _T("shell32.dll,OpenAs_RunDLL d:\\Untitled1.pdf");
      static LPTSTR fileBuffer  = _T("rundll32.exe");
    }
    
    namespace NormalIsNotWorking
    {
      static LPTSTR parameterBuffer = 0;
      static LPTSTR fileBuffer      = _T("d:\\Untitled1.pdf");
    }
    
    namespace NormalRtf
    {
      static LPTSTR parameterBuffer = 0;
      static LPTSTR fileBuffer      = _T("d:\\Document.rtf");
    }
    
    
    #define ParamMode NormalIsNotWorking //SystemSwitcher
    
    namespace WithShellExecute
    {
      static DWORD WINAPI ThreadProc(LPVOID lpParamater)
      {
    	  SHELLEXECUTEINFO SHExecInfo; 
    
    	  ZeroMemory(&SHExecInfo, sizeof(SHExecInfo));
    	  SHExecInfo.cbSize       = sizeof(SHExecInfo);
    	  SHExecInfo.fMask        = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_DOENVSUBST;
    	  SHExecInfo.nShow        = SW_SHOWNORMAL;
    
    	  SHExecInfo.lpFile       = ParamMode::fileBuffer;
        SHExecInfo.lpParameters = ParamMode::parameterBuffer;
    		
        if (FAILED( CoInitializeEx(NULL, COINIT_MULTITHREADED) ))
        {
          assert(0);
        }
    		
        if(FALSE == ShellExecuteEx(&SHExecInfo) || 32 > (int)SHExecInfo.hInstApp) 
    	  { 
    		  assert(FALSE);
    	  }
    		
    	  return 0;
      }
    }
    
    #define RunMode WithShellExecute
    
    int _tmain(int argc, _TCHAR* argv[])
    {        
      DWORD lpThreadId;
      HANDLE threadHandle = ::CreateThread(NULL, 0, RunMode::ThreadProc, 0, 0, &lpThreadId);
    
      WaitForSingleObject(threadHandle, INFINITE);
    
    	return 0;
    }
    

    The Windows Reader launching but it is wrote a message: "Error while loading document". Is anybody know the right solution to solve this problem?

    Thank you,

    Egor.

    • Moved by Rob CaplanMicrosoft Employee Wednesday, March 28, 2012 7:40 PM desktop app development question, not metro style app question (From:Building Metro style apps with C++ )
    • Moved by Mike Dos ZhangMicrosoft Contingent Staff Thursday, March 29, 2012 10:44 AM Windows Shell API usage problem (From:General Windows Desktop Development Issues)
    •  

All Replies

  • Thursday, March 29, 2012 10:45 AM
     
     

    For Windows Shell APIs problem, please use this forum.

    Best wishes,


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us

  • Thursday, March 29, 2012 1:30 PM
     
     
    One more question: How can I attach to Metro Style Application to view a DDE(or other) messages? When I try to use Spy++ I have not success cause it does not see any messages from Windows Reader.
  • Thursday, March 29, 2012 1:39 PM
     
     
    I investigate this problem. The execute troubles is at Windows Reader only. All other metro style application launched normally.
  • Friday, March 30, 2012 3:43 PM
     
     
    For simple bug reproducing you can use a far: 
    1. Launch far. 
    2. Enter a command: start <file_path> 
    3. Press Enter. 
    At result, you will see the same Windows Reader error. 

    • Edited by EgoRich8 Monday, April 02, 2012 9:32 AM
    • Edited by EgoRich8 Monday, April 02, 2012 9:32 AM
    • Proposed As Answer by nmasao Monday, June 18, 2012 8:57 AM
    • Unproposed As Answer by nmasao Monday, June 18, 2012 8:57 AM
    •  
  • Tuesday, April 03, 2012 8:22 AM
     
     

    I think maybe you can use this forum, it is for the issue related to Win8 APP form Microsoft: http://answers.microsoft.com/en-us/windows/forum/windows_8-winapps

    I think you can use this "answers" forum to clear about the boot/load behavior of the Windows Reader, then it would give you some help to let it can run in command line and the Shell APIs.

    Best wishes,

     

    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us

  • Monday, June 18, 2012 9:07 AM
     
     Answered

    I met the same problem with both Windows 8 Customer Preview and Release Preview.

    The solution which I found is waiting for a while after ShellExecuteEx;

    ShellExecuteEx(&SHExecInfo);
    Sleep(10000);

    Of course, it is not so beautiful... When I used WaitForInputIdle(hProcess), it did not work well (maybe because Metro App does not have a window message loop), and when I used WaitForSingleObject(hProcess), Reader App hung up.

    • Marked As Answer by EgoRich8 Wednesday, August 08, 2012 1:31 PM
    •  
  • Monday, August 27, 2012 11:03 AM
     
     
    Well I have the same problem and if you burn a DVD with an application which launches a PDF file with ShellExecuteEx, The Sleep(10000) command, you add doesn't change anything! I have all the time the Message "Error while loading document".