Results 1 to 4 of 4

Thread: [RESOLVED] ShellExecute PDF "file already open" error

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    100

    Resolved [RESOLVED] ShellExecute PDF "file already open" error

    Greetings,

    Running Vista and VB6:

    I'm using shellexecute to launch files with their associated application. This works for all files except PDF files. With PDF files, I can launch a given file one time successfully, then any subsequent attempts to launch that same file results in the following:

    * Adobe Reader opens
    * Adobe Reader reports the following error:
    "There was an error opening this document. This file is already open or in use by another application."

    I can open the file by double-clicking on it from Windows Explorer.

    After some time passes, I may or may not be able to successfully launch this same PDF file from my app. Restarting my app has no effect on this behavior.

    Here is the code I'm using:

    Code:
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    
    Const SW_SHOWNORMAL as Long = 1
    
    sAddr = sAddr & vbNullChar
    lHndl = ShellExecute(mf.hwnd, "open", sAddr, "", "", SW_SHOWNORMAL)
    Any clues would be much appreciated.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: ShellExecute PDF "file already open" error

    i tested your code it had no problem, on my machine opened the same file many times, if the file was still open, it activated the adobe reader window, are you writing the pdf before opening?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ShellExecute PDF "file already open" error

    I just tested your code as well and has no difficulties, so something else has to be going on with something other than the code that you posted.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    100

    Re: ShellExecute PDF "file already open" error

    Thanks all.

    Apparently a call to ShellExecute will return before the program being called opens the file being passed to it, at least with PDF files. My program was calling a quick file open binary shared after the ShellExecute command under the assumption that Adobe had already launched.

    Resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width