Entwickler-Ecke
Windows API - ShellExecuteA or ExtractFilePath() fails in Win2000?
Funny Mister Rabbit - Mi 24.11.04 14:34
Titel: ShellExecuteA or ExtractFilePath() fails in Win2000?
First of all, apologies for using English on this forum. :oops: I am a Finn and I have studied Deutsch only 3 years at school, so my German is a bit rusty.
I wrote a small application with Delphi 4, that uses ShellExecuteA function of Shell32.dll to launch another exe. It works 100% on Windows 95, 98 and ME, but fails on Win2000. Error message says that Shell32.dll is not found, but Shell32.dll IS in System32 directory.
Apparently ShellExecuteA of Shell32.dll does not work on Windows 2000? :shock:
Any ideas? Other functions I could use?
Or could it be that it is ExtractFilePath(ParamStr(0)) that fails on Win2000? I use ExtractFilePath(ParamStr(0)) to define the path to the other exectuable which I start with ShellExecuteA.
Here's the code:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
| uses
function ShellExecute(hWnd: HWND; Operation, FileName, Parameters, Directory: PChar; ShowCmd: Integer): HINST; stdcall;
implements
function ShellExecute; external 'shell32' name 'ShellExecuteA';
Actual call:
ShellExecute(handle, 'open', Pchar(ExePath) , nil, nil, SW_SHOWNORMAL); |
Moderiert von
Christian S.: Replaced Code- with Delphi-Tags
Delete - Mi 24.11.04 15:23
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
| var Form1: TForm1; function ShellExecute(hWnd: HWND; Operation, FileName, Parameters, Directory: PChar; ShowCmd: Integer): HINST; stdcall;
implementation
{$R *.dfm}
function ShellExecute; external 'shell32.dll' name 'ShellExecuteA';
procedure TForm1.Button1Click(Sender: TObject); begin ShellExecute(handle, 'open', 'notepad.exe' , nil, nil, SW_SHOWNORMAL); end; |
Works fine under Windows 2000.
Funny Mister Rabbit - Mi 24.11.04 16:03
Thanks for testing the code!
My test Win2000 doesn't have SP4. Perhaps it's related to it somehow.
I changed the code so that I use CreateProcess instead of ShellExecuteA, and now it runs OK on the problematic Win2000 machine. Now I have to test it on the Win 9x machines. :)
Delete - Mi 24.11.04 17:03
Funny Mister Rabbit hat folgendes geschrieben: |
My test Win2000 doesn't have SP4. Perhaps it's related to it somehow.
|
That shouldn't matter.
AXMD - Mi 24.11.04 17:05
I think I've found your error: you should use 'shell32.dll' instead of 'shell32' - maybe the missing .dll is a reason for Win2k to complain ;)
AXMD
MrSaint - Do 25.11.04 14:05
That's definately not the problem. If you check the MSDN for the LoadLibrary function you get this:
Zitat: |
If no file name extension is specified in the lpFileName parameter, the default library extension .dll is appended. However, the file name string can include a trailing point character (.) to indicate that the module name has no extension. |
and the static linking to the library should work exactly like the LoadLibrary-way, apart from the fact, that the static way loads the DLL at load-time of the EXE.
MrSaint
Entwickler-Ecke.de based on phpBB
Copyright 2002 - 2011 by Tino Teuber, Copyright 2011 - 2025 by Christian Stelzmann Alle Rechte vorbehalten.
Alle Beiträge stammen von dritten Personen und dürfen geltendes Recht nicht verletzen.
Entwickler-Ecke und die zugehörigen Webseiten distanzieren sich ausdrücklich von Fremdinhalten jeglicher Art!