shell32.dll ; ShellExecute() not running in Powerbuilder 11.5
I have trouble in fixing one bug that was assigned to me. It supposed to print a pdf file stated on the parameter. It 开发者_StackOverflowuses ShellExecute() function to print directly the document. My question is a pdf file considered a document file? the ShellExecute() is returning 2 w/c I found out that it means invalid path or filename. Just wondering why it returned 2. I also try the action "open" but still no action. Will really appreciate all your help.
Make sure to use the Unicode version (ShellExecuteW) and not the ANSI version (ShellExecuteA) :
FUNCTION long ShellExecute (uint ihwnd,string lpszOp,string
lpszFile,string lpszParams, string lpszDir,int wShowCmd )
LIBRARY "Shell32.dll" ALIAS FOR "ShellExecuteW"
Here are your return codes for ShellExecute, once you handle for these you should be able to determine the cause of any problem. This is probably overkill but you can decide which you want to catch.
I've worked a similar issue on PB project, and when running a PDF via shell execute it is the same as double clicking a PDF file in windows explorer. If there is a file association set up for PDF then the PDF will be opened using the default program. If you run shell execute on a .doc file then in most cases the file will be opened with Word. If no association is available then you will get exception 31, no file association.
WHEN 0 THEN txt = "The operating system is out of memory or resources.".
WHEN 2 THEN txt = "The specified file was not found".
WHEN 3 THEN txt = "The specified path was not found.".
WHEN 5 THEN txt = "Windows 95 only: The operating system denied "
+ "access to the specified file".
WHEN 8 THEN txt = "Windows 95 only: There was not enough memory to "
+ "complete the operation.".
WHEN 10 THEN txt = "Wrong Windows version".
WHEN 11 THEN txt = "The .EXE file is invalid (non-Win32 .EXE or "
+ "error in .EXE image).".
WHEN 12 THEN txt = "Application was designed for a different operating system".
WHEN 13 THEN txt = "Application was designed for MS-DOS 4.0".
WHEN 15 THEN txt = "Attempt to load a real-mode program".
WHEN 16 THEN txt = "Attempt to load a second instance of "
+ "an application with non-readonly data segments".
WHEN 19 THEN txt = "Attempt to load a compressed application file".
WHEN 20 THEN txt = "Dynamic-link library (DLL) file failure".
WHEN 26 THEN txt = "A sharing violation occurred.".
WHEN 27 THEN txt = "The filename association is incomplete or invalid.".
WHEN 28 THEN txt = "The DDE transaction could not be completed "
+ "because the request timed out.".
WHEN 29 THEN txt = "The DDE transaction failed.".
WHEN 30 THEN txt = "The DDE transaction could not be completed because "
+ "other DDE transactions were being processed.".
WHEN 31 THEN txt = "There is no application associated with "
+ "the given filename extension.".
WHEN 32 THEN txt = "Windows 95 only: The specified dynamic-link "
+ "library was not found.".
OTHERWISE txt = "undocumented".
精彩评论