I'll post some details when I get home from work. However not sure what question 2 is asking:
Are you asking, for example, how to "run a TXT file" such that it will open in Notepad (or whatever is the user's associated program)? Or something else?
EDIT:
You can call pretty much any program from your VB6 app regardless of where it is on your HD. The program you call might expect the current working directory to be set to it's own directory though, rather than the directory of your VB6 app, so you might have to set this using a separate API.
You can call programs in several different ways. Here's an example of how I might call oggdec.exe to convert an OGG file to a WAV:
App.Path is the directory your app's executable is in.
The above code calls three API functions that you need to declare:
And there are two constants used that you need to declare:
If the program you are calling expects the current working directory to be set then you should search for the "SetCurrentDirectory" API function.
If you want to open, say, a text file with the user's default program do something like this:
Or a URL with their default web browser:
OpenLocation is a function I made (see: copied from someone else) that simplifies a call to an API function:
And ShellExecute is declared thusly:
There are other ways to do this but those are the ways I use the most.
You may need to play around with quotes and short/long filenames depending on what you're calling and where on the hard drive it is.
You can find most of the info you need on the web, you just gotta think how to structure your search. I learnt what I know 10% taught at school, 60% web searching and 30% trial and error.
Are you asking, for example, how to "run a TXT file" such that it will open in Notepad (or whatever is the user's associated program)? Or something else?
EDIT:
You can call pretty much any program from your VB6 app regardless of where it is on your HD. The program you call might expect the current working directory to be set to it's own directory though, rather than the directory of your VB6 app, so you might have to set this using a separate API.
You can call programs in several different ways. Here's an example of how I might call oggdec.exe to convert an OGG file to a WAV:
Code:
dim sOggPath as string
dim process_id
dim process_handle
sOggPath = "C:\my_sound.ogg"
process_id = Shell(App.Path & "\Resource\oggdec.exe" & " " & sOggPath, vbNormal)
process_handle = OpenProcess(SYNCHRONIZE, 0, process_id)
If process_handle <> 0 Then
WaitForSingleObject process_handle, INFINITE 'this waits until oggdec.exe has finished it's job
CloseHandle process_handle
End If
The above code calls three API functions that you need to declare:
Code:
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Code:
Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = -1&
If you want to open, say, a text file with the user's default program do something like this:
Code:
If OpenLocation(sTextFilePath) < 32 Then Call frmMain.WriteLogEntry("Error opening " & sTextFilePath, LogMsgBox)
Code:
If OpenLocation(sWebsite) < 32 Then Call MsgBox("Unable to open " & sWebsite, vbOKOnly + vbInformation, App.Title)
Code:
Public Function OpenLocation(ByVal WhichFilePath As String, Optional sParams As String = "", Optional sStartIn As String = vbNullString, Optional lngOpenMode As Long = 1) As Long
OpenLocation = ShellExecute(0, "Open", WhichFilePath, sParams, sStartIn, lngOpenMode)
End Function
Code:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
There are other ways to do this but those are the ways I use the most.
You may need to play around with quotes and short/long filenames depending on what you're calling and where on the hard drive it is.
You can find most of the info you need on the web, you just gotta think how to structure your search. I learnt what I know 10% taught at school, 60% web searching and 30% trial and error.
Ever wondered what the hell is going on?
Believe me friend you're not the only one.
--Lysdexia
Check out Launch Base for RA2/YR - http://marshall.strategy-x.com
Also home to the Purple Alert mod, 1.002 UMP, and the YR Playlist Manager.
Believe me friend you're not the only one.
--Lysdexia
Check out Launch Base for RA2/YR - http://marshall.strategy-x.com
Also home to the Purple Alert mod, 1.002 UMP, and the YR Playlist Manager.