Autor Beitrag
Funny Mister Rabbit
Hält's aus hier
Beiträge: 2


D4
BeitragVerfasst: Mi 24.11.04 14:34 
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:

ausblenden 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) , nilnil, SW_SHOWNORMAL);


Moderiert von user profile iconChristian S.: Replaced Code- with Delphi-Tags
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 24.11.04 15:23 
ausblenden 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' , nilnil, SW_SHOWNORMAL);
end;

Works fine under Windows 2000.
Funny Mister Rabbit Threadstarter
Hält's aus hier
Beiträge: 2


D4
BeitragVerfasst: 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. :)
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: 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
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: 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
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1033
Erhaltene Danke: 1

WinXP Pro SP2
Delphi 6 Prof.
BeitragVerfasst: 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

_________________
"people knew how to write small, efficient programs [...], a skill that has subsequently been lost"
Andrew S. Tanenbaum - Modern Operating Systems