Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > Tools

Lost Password?

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 09-13-2011, 04:15 PM
Typhoonbot Typhoonbot is offline
Junior Member
 
Join Date: Nov 2010
Posts: 15
Question Small issue with ShellExecute running an application

Hi guys, I have a small issue that I cant find the answer to after a day of research so when all else fails I resort to this wonderful land of delphi answers

I want to execute the Call of Duty game from my delphi program. I know how to execute applications from a delphi program (using shellExecute ofcourse) but call of duty is giving me a hassle with the call of duty root/Main folder.

after running the shell execute statement as follows:

Code:
ShellExecute(Handle, 'open', PChar(MyAllEntries.Get_Entry(Which).Get_Path), nil, nil, SW_SHOWNORMAL)
(MyAllEntrries.Get_Entry(Which).Get_Path) returns the full path with the exe name which in this case is "C:\Program Files (x86)\Activision\Call of Duty 4 - Modern Warfare\iw3mp.exe"

I know whats giving me the error is that when executing the call of duty exe, the "Main" folder needs to be in the same directory as the exe. I tested this by cutting the Main folder to my desktop, and trying to run the actual exe in the call of duty root directory and I got the exact same error.

So my prediction is that when delphi runs a ShellExecute statement, it copies the exe to a temporary location where the Main folder can't be accessed and runs it there, therefore giving me the "Error during initialization: No IWD files found in /main" error?

Any help or advice on a different way to do this, or a solution to the problem would be appreciated

Thanks in advance
  #2  
Old 09-14-2011, 10:24 AM
Donovan Donovan is offline
Senior Member
 
Join Date: Jan 2011
Posts: 150
Send a message via Skype™ to Donovan
Default

You need to define the running directory of the application that you launch.

Try this...

Code:
ShellExecute(Handle, 'open', PChar(MyAllEntries.Get_Entry(Which).Get_Path),ExtractFilePath(MyAllEntries.Get_Entry(Which).Get_Path), nil, SW_SHOWNORMAL)
That will define that running folder as the folder where the COD executable is.
  #3  
Old 09-14-2011, 04:31 PM
Typhoonbot Typhoonbot is offline
Junior Member
 
Join Date: Nov 2010
Posts: 15
Default

Hi Donovan, thank you so much for your reply.

Unfortunately it doesn't seem to have sorted out the problem, my statement now looks like this:

Code:
ShellExecute(Handle, 'open', PChar(MyAllEntries.Get_Entry(Which).Get_Path),PWideChar(ExtractFilePath(MyAllEntries.Get_Entry(Which).Get_Path)), nil, SW_SHOWNORMAL)
I get the exact same error as described in the first post, and I am certain that ExtractFilePath gets the program file path as I put a showmessage that returns the value of PWideChar(ExtractFilePath(MyAllEntries.Get_Entry(W hich).Get_Path)) and it returns the correct COD root directory. Any other ideas or a solution to the program not finding the /main folder even after I define the root directory?

Thanks
  #4  
Old 09-14-2011, 10:53 PM
Typhoonbot Typhoonbot is offline
Junior Member
 
Join Date: Nov 2010
Posts: 15
Default

perhaps the use of CreateProcess is a better way, but a straight Createprocess statement doesnt seem to work. Also I was thinking could it be a problem with the spaces in the file path string without quotation marks? ""

Man its frustrating me that I cant figure this out
  #5  
Old 09-15-2011, 02:13 PM
mdixon7610 mdixon7610 is offline
Senior Member
 
Join Date: Sep 2003
Posts: 141
Default

Quote:
Originally Posted by Typhoonbot View Post
...So my prediction is that when delphi runs a ShellExecute statement, it copies the exe to a temporary location where the Main folder can't be accessed and runs it there, therefore giving me the "Error during initialization: No IWD files found in /main" error?...
Ok, first Delphi does no such thing, as ShellExecute is simply a call to the Windows ShellExecute API Function.

This is what shellexecute looks like:
ShellExecute(handle, operation, file, parameters, directory, show command)

The example Donovan gave, and that you posted as what your statement looks like now has the path as the parameters parameter, instead of the directory parameter. So swap the nil and path so it matches the bold items above, like this.

ShellExecute(Handle, 'open', PChar(MyAllEntries.Get_Entry(Which).Get_Path),nil , PWideChar(ExtractFilePath(MyAllEntries.Get_Entry(W hich).Get_Path)), SW_SHOWNORMAL)
  #6  
Old 09-15-2011, 02:36 PM
Typhoonbot Typhoonbot is offline
Junior Member
 
Join Date: Nov 2010
Posts: 15
Default

Hi mdixon, I really appreciate your reply.

This has worked perfectly and I learnt a bit more about ShellExecute and the way it executes files so I am very grateful for that.

Thanks to you too Donovan as you had the right idea, just mixed up the parameters a bit

Regards
  #7  
Old 09-15-2011, 02:42 PM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default

Can you run the program just by selecting Start->Run and then typing
"C:\Program Files (x86)\Activision\Call of Duty 4 - Modern Warfare\iw3mp.exe"?

Does the COD executable have a parameter to place the MainDir?
__________________
MrBaseball34

Hook 'em Horns
2005 College Football National Champions
2005 College Baseball National Champions
Closed Thread

Tags
callofduty, shellexecute

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:01 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.