Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Apr 28, 2017 10:25 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Createprocess() & Shellexecute Directory Issues.
PostPosted: Thu Feb 14, 2013 4:26 am 
Offline

Joined: Sat Jul 16, 2011 2:45 pm
Posts: 76
Hey guys,

I have tried both CreateProcess() and ShellExecute() to launch a program and both return error codes 267 / 2 respectively (directory /file does not exist).

The Program /Directory 100% does exist - not only was it copied from explorer, I can cut and paste it into cmd.exe and it will load / launch.

I have tried changing directories, tried launching other programs, tried various combinations of directories /command line variations etc and it seems windows refuses to acknowledge the directory?

This is on windows 8 if that changes anything. Is there any particular reason why realstudio in combination with this API wouldn't work? I am completely lost as to how to launch a simple program .

Folderitem.launch is not a viable option because i need to set the "current directory" of the launched application for it to load properly. If i place my built real studio application in the "current directory" needed (because it inherits the current directory) it will work, but that is not a viable solution because it regularly changes and there is more than one application that needs launching.

Any help much appreciated

edit: Well I managed to get it to work yey!


Last edited by lukus001 on Thu Feb 14, 2013 12:41 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Createprocess() & Shellexecute Directory Issues.
PostPosted: Thu Feb 14, 2013 5:25 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Quote:
Folderitem.launch is not a viable option

Yes it is.

Quote:
i need to set the "current directory" of the launched application

why?

if you know the right path to the file, you can do

myFolderItem = GetFolderItem(theFullPath)
after that, does myFolderItem.exists return true? If no, the path is wrong.

If yes, then myFolderItem.launch should work just fine
You shouldnt normally be forcing the launched EXE to 'think' it is running in another location.

Quote:
If i place my built real studio application in the "current directory" needed (because it inherits the current directory) it will work


So are you NOT supplying the full path to the required file?
That will only work if the program you want to laucnh exists on the windows 'PATH' environment variable.
(Places where it looks for exectuables if someone forgets to say where the program lives)

Quote:
that is not a viable solution because it regularly changes

That sounds suspect...


Top
 Profile  
 
 Post subject: Re: Createprocess() & Shellexecute Directory Issues.
PostPosted: Thu Feb 14, 2013 5:40 am 
Offline

Joined: Sat Jul 16, 2011 2:45 pm
Posts: 76
kermit wrote:
You shouldnt normally be forcing the launched EXE to 'think' it is running in another location.

...

So are you NOT supplying the full path to the required file?
That will only work if the program you want to laucnh exists on the windows 'PATH' environment variable.
(Places where it looks for exectuables if someone forgets to say where the program lives)
I think you misunderstood.

Every application has a "current directory" value which is irrelevant to where the application is actually located or one's ability to load that application, but affects that application's relative references to files or directories.

Processmonitor will show "application: C:\fulladdress to executable.exe + commandline vars" & "currentDirectory: C:\myrealstudioapp_directory"

The problem is, that the application I want to load requires access to certain files relative to it's location or it will close, and for it to have access to those files it's "current directory" value has to be set to the directory the executable was located. This is not my application, this is not something I can alter, it is out of my control regardless of whether that is or isn't normal behavior.

The problem with folderitem.launch is that it does not allow one to set the "current directory" value, the launched process then inherits the parent processes' directory which of course will not work for the sub process and it will self terminate.

I will clarify, folderitem.launch DOES load the application but the application will self terminate without the correct "current directory" value set, which folderitem.launch does not facilitate.

Thus, I require CreateProcess() or ShellExecute() both of which seem to dislike accepting the directory even though it's valid




edit: Well I managed to get it to work yey!


Top
 Profile  
 
 Post subject: Re: Createprocess() & Shellexecute Directory Issues.
PostPosted: Thu Feb 14, 2013 12:53 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
Since apps launched with FolderItem.Launch inherit the parent app's CWD, change the CWD before launching and then change it back, e.g.:

Sub LaunchInWD(File As FolderItem, WD As FolderItem)
Declare Function SetCurrentDirectoryW Lib "Kernel32" (PathName As WString) As Boolean
Declare Function GetCurrentDirectoryW Lib "Kernel32" (BufferLen As Integer, Buffer As Ptr) As Integer

'first get the actual CWD
Dim buffer As New MemoryBlock(2048)
Dim sz As Integer = GetCurrentDirectoryW(buffer.Size, Buffer)
If sz > Buffer.Size And sz <> 0 Then
Buffer = New MemoryBlock(sz)
Call GetCurrentDirectoryW(buffer.Size, Buffer)
End If

'set the process working directory to WD
If SetCurrentDirectoryW(CWD.AbsolutePath) Then
file.Launch 'Launch the app
Call SetCurrentDirectoryW(Buffer) 'reset the CWD
End If
End Sub

_________________
Boredom Software


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group