IsFile, isURL

  • Thread starter Thread starter C. A. Kelly
  • Start date Start date
C

C. A. Kelly

I have a program that I want to launch links if certain criteria is met, the
problem is how can I determine if a string is a program to launch, here is
an example
with quotes->
"c:\Program Files\Windows Media Player\wmplayer.exe"
"c:\program files\windows media player\mplayer2.exe" /open
"http://radio.msn.com/asx/generate.aspx?type=genre&id=10002364" /play
http://myfavoritepages

it won't always be c:\ drive and sometimes it might be a ftp link below is
currently what i'm doing

Function isURL(ByVal kcString As String)
Dim kcFound As String = kcString.IndexOf("://")
If kcFound > 0 Then
Return True
Else
Return False
End If
End Function

Function isFile(ByVal kcString As String)
Dim kcFound As String = kcString.IndexOf(":\")
If kcFound > 0 Then
Return True
Else
Return False
End If
End Function
 
C.A. Kelly,
Have you looked at either the System.IO.Path or System.Uri classes?

I believe just Uri itself can be used. Something like:

Declare Unicode Function CommandLineToArgv Lib "shell32" Alias
"CommandLineToArgvW"
(<MarshalAs(Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal commandLine
As String, <Out()> ByRef numberArgs As Integer) As IntPtr

Public Shared Function ParseCommandLine(ByVal commandLine As String) As
String()
Dim count As Integer
Dim ptr As IntPtr

ptr = CommandLineToArgv(commandLine, count)

Dim args(count - 1) As String

For index As Integer = 0 To count - 1
Dim ptrStr As IntPtr = Marshal.ReadIntPtr(ptr, index *
IntPtr.Size)
Dim str As String = Marshal.PtrToStringUni(ptrStr)
args(index) = str
Next
Return args
End Function

Public Shared Function IsURL(ByVal kcString As String) As Boolean
Dim kcUri As New Uri(kcString)
Return kcUri.Scheme <> Uri.UriSchemeFile
End Function

Public Shared Function IsFile(ByVal kcString As String) As Boolean
Dim kcUri As New Uri(kcString)
Return kcUri.Scheme = Uri.UriSchemeFile
End Function

Public Shared Sub Main()
Dim commandLines() As String = {"""c:\Program Files\Windows Media
Player\wmplayer.exe""", _
"""c:\program files\windows media player\mplayer2.exe"" /open",
_
"""http://radio.msn.com/asx/generate.aspx?type=genre&id=10002364""
/play http://myfavoritepages"}

For Each commandLine As String In commandLines
Dim args() As String = ParseCommandLine(commandLine)
Debug.WriteLine(commandLine, "commandLine")
Debug.Indent()
Debug.WriteLine(IsURL(args(0)), "isUrl")
Debug.WriteLine(IsFile(args(0)), "isFile")
For Each arg As String In args
Debug.WriteLine(arg, "arg")
Next
Debug.Unindent()
Next
End Sub

NOTE: I use the CommandLineToArgvW Win32 API along with the ParseCommandLine
function to parse the string into individual arguments.

Hope this helps
Jay

|I have a program that I want to launch links if certain criteria is met,
the
| problem is how can I determine if a string is a program to launch, here is
| an example
| with quotes->
| "c:\Program Files\Windows Media Player\wmplayer.exe"
| "c:\program files\windows media player\mplayer2.exe" /open
| "http://radio.msn.com/asx/generate.aspx?type=genre&id=10002364" /play
| http://myfavoritepages
|
| it won't always be c:\ drive and sometimes it might be a ftp link below is
| currently what i'm doing
|
| Function isURL(ByVal kcString As String)
| Dim kcFound As String = kcString.IndexOf("://")
| If kcFound > 0 Then
| Return True
| Else
| Return False
| End If
| End Function
|
| Function isFile(ByVal kcString As String)
| Dim kcFound As String = kcString.IndexOf(":\")
| If kcFound > 0 Then
| Return True
| Else
| Return False
| End If
| End Function
|
|
|
 
Doh!

That's going to have a slow unmanaged memory leak.

I should be calling LocalFree on the return value from CommandLineToArgvW.

| Declare Unicode Function CommandLineToArgv Lib "shell32" Alias
| "CommandLineToArgvW"
| (<MarshalAs(Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal
commandLine
| As String, <Out()> ByRef numberArgs As Integer) As IntPtr
|

Declare Auto Function LocalFree Lib "kernel32" (ByVal hMem As IntPtr) As
IntPtr


| Public Shared Function ParseCommandLine(ByVal commandLine As String) As
| String()
| Dim count As Integer
| Dim ptr As IntPtr
| ptr = CommandLineToArgv(commandLine, count)
| Dim args(count - 1) As String
| For index As Integer = 0 To count - 1
| Dim ptrStr As IntPtr = Marshal.ReadIntPtr(ptr, index *
| IntPtr.Size)
| Dim str As String = Marshal.PtrToStringUni(ptrStr)
| args(index) = str
| Next

LocalFree(ptr)

| Return args
| End Function

I would consider wrapping the For Loop in a Try/Finally block to ensure that
LocalFree was called even in an exception occurred...

Hope this helps
Jay

| C.A. Kelly,
| Have you looked at either the System.IO.Path or System.Uri classes?
|
| I believe just Uri itself can be used. Something like:
|
| Declare Unicode Function CommandLineToArgv Lib "shell32" Alias
| "CommandLineToArgvW"
| (<MarshalAs(Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal
commandLine
| As String, <Out()> ByRef numberArgs As Integer) As IntPtr
|
| Public Shared Function ParseCommandLine(ByVal commandLine As String) As
| String()
| Dim count As Integer
| Dim ptr As IntPtr
|
| ptr = CommandLineToArgv(commandLine, count)
|
| Dim args(count - 1) As String
|
| For index As Integer = 0 To count - 1
| Dim ptrStr As IntPtr = Marshal.ReadIntPtr(ptr, index *
| IntPtr.Size)
| Dim str As String = Marshal.PtrToStringUni(ptrStr)
| args(index) = str
| Next
| Return args
| End Function
|
| Public Shared Function IsURL(ByVal kcString As String) As Boolean
| Dim kcUri As New Uri(kcString)
| Return kcUri.Scheme <> Uri.UriSchemeFile
| End Function
|
| Public Shared Function IsFile(ByVal kcString As String) As Boolean
| Dim kcUri As New Uri(kcString)
| Return kcUri.Scheme = Uri.UriSchemeFile
| End Function
|
| Public Shared Sub Main()
| Dim commandLines() As String = {"""c:\Program Files\Windows Media
| Player\wmplayer.exe""", _
| """c:\program files\windows media player\mplayer2.exe"" /open",
| _
|
"""http://radio.msn.com/asx/generate.aspx?type=genre&id=10002364""
| /play http://myfavoritepages"}
|
| For Each commandLine As String In commandLines
| Dim args() As String = ParseCommandLine(commandLine)
| Debug.WriteLine(commandLine, "commandLine")
| Debug.Indent()
| Debug.WriteLine(IsURL(args(0)), "isUrl")
| Debug.WriteLine(IsFile(args(0)), "isFile")
| For Each arg As String In args
| Debug.WriteLine(arg, "arg")
| Next
| Debug.Unindent()
| Next
| End Sub
|
| NOTE: I use the CommandLineToArgvW Win32 API along with the
ParseCommandLine
| function to parse the string into individual arguments.
|
| Hope this helps
| Jay
|
| ||I have a program that I want to launch links if certain criteria is met,
| the
|| problem is how can I determine if a string is a program to launch, here
is
|| an example
|| with quotes->
|| "c:\Program Files\Windows Media Player\wmplayer.exe"
|| "c:\program files\windows media player\mplayer2.exe" /open
|| "http://radio.msn.com/asx/generate.aspx?type=genre&id=10002364" /play
|| http://myfavoritepages
||
|| it won't always be c:\ drive and sometimes it might be a ftp link below
is
|| currently what i'm doing
||
|| Function isURL(ByVal kcString As String)
|| Dim kcFound As String = kcString.IndexOf("://")
|| If kcFound > 0 Then
|| Return True
|| Else
|| Return False
|| End If
|| End Function
||
|| Function isFile(ByVal kcString As String)
|| Dim kcFound As String = kcString.IndexOf(":\")
|| If kcFound > 0 Then
|| Return True
|| Else
|| Return False
|| End If
|| End Function
||
||
||
|
|
 
Hmm...

FYI:

Reading Adam Nathan's ".NET and COM - The Complete Interoperability Guide",
I believe I could have simply used Marshal.FreeHGlobal, instead of declaring
the LocalFree function. As FreeHGlobal calls the GlobalFree Win32 API, which
under Win32 does the "same thing" as LocalFree Win32 API...

Jay

| Doh!
|
| That's going to have a slow unmanaged memory leak.
|
| I should be calling LocalFree on the return value from CommandLineToArgvW.
|
|| Declare Unicode Function CommandLineToArgv Lib "shell32" Alias
|| "CommandLineToArgvW"
|| (<MarshalAs(Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal
| commandLine
|| As String, <Out()> ByRef numberArgs As Integer) As IntPtr
||
|
| Declare Auto Function LocalFree Lib "kernel32" (ByVal hMem As IntPtr)
As
| IntPtr
|
|
|| Public Shared Function ParseCommandLine(ByVal commandLine As String)
As
|| String()
|| Dim count As Integer
|| Dim ptr As IntPtr
|| ptr = CommandLineToArgv(commandLine, count)
|| Dim args(count - 1) As String
|| For index As Integer = 0 To count - 1
|| Dim ptrStr As IntPtr = Marshal.ReadIntPtr(ptr, index *
|| IntPtr.Size)
|| Dim str As String = Marshal.PtrToStringUni(ptrStr)
|| args(index) = str
|| Next
|
| LocalFree(ptr)
|
|| Return args
|| End Function
|
| I would consider wrapping the For Loop in a Try/Finally block to ensure
that
| LocalFree was called even in an exception occurred...
|
| Hope this helps
| Jay
|
| || C.A. Kelly,
|| Have you looked at either the System.IO.Path or System.Uri classes?
||
|| I believe just Uri itself can be used. Something like:
||
|| Declare Unicode Function CommandLineToArgv Lib "shell32" Alias
|| "CommandLineToArgvW"
|| (<MarshalAs(Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal
| commandLine
|| As String, <Out()> ByRef numberArgs As Integer) As IntPtr
||
|| Public Shared Function ParseCommandLine(ByVal commandLine As String)
As
|| String()
|| Dim count As Integer
|| Dim ptr As IntPtr
||
|| ptr = CommandLineToArgv(commandLine, count)
||
|| Dim args(count - 1) As String
||
|| For index As Integer = 0 To count - 1
|| Dim ptrStr As IntPtr = Marshal.ReadIntPtr(ptr, index *
|| IntPtr.Size)
|| Dim str As String = Marshal.PtrToStringUni(ptrStr)
|| args(index) = str
|| Next
|| Return args
|| End Function
||
|| Public Shared Function IsURL(ByVal kcString As String) As Boolean
|| Dim kcUri As New Uri(kcString)
|| Return kcUri.Scheme <> Uri.UriSchemeFile
|| End Function
||
|| Public Shared Function IsFile(ByVal kcString As String) As Boolean
|| Dim kcUri As New Uri(kcString)
|| Return kcUri.Scheme = Uri.UriSchemeFile
|| End Function
||
|| Public Shared Sub Main()
|| Dim commandLines() As String = {"""c:\Program Files\Windows Media
|| Player\wmplayer.exe""", _
|| """c:\program files\windows media player\mplayer2.exe""
/open",
|| _
||
| """http://radio.msn.com/asx/generate.aspx?type=genre&id=10002364""
|| /play http://myfavoritepages"}
||
|| For Each commandLine As String In commandLines
|| Dim args() As String = ParseCommandLine(commandLine)
|| Debug.WriteLine(commandLine, "commandLine")
|| Debug.Indent()
|| Debug.WriteLine(IsURL(args(0)), "isUrl")
|| Debug.WriteLine(IsFile(args(0)), "isFile")
|| For Each arg As String In args
|| Debug.WriteLine(arg, "arg")
|| Next
|| Debug.Unindent()
|| Next
|| End Sub
||
|| NOTE: I use the CommandLineToArgvW Win32 API along with the
| ParseCommandLine
|| function to parse the string into individual arguments.
||
|| Hope this helps
|| Jay
||
|| |||I have a program that I want to launch links if certain criteria is met,
|| the
||| problem is how can I determine if a string is a program to launch, here
| is
||| an example
||| with quotes->
||| "c:\Program Files\Windows Media Player\wmplayer.exe"
||| "c:\program files\windows media player\mplayer2.exe" /open
||| "http://radio.msn.com/asx/generate.aspx?type=genre&id=10002364" /play
||| http://myfavoritepages
|||
||| it won't always be c:\ drive and sometimes it might be a ftp link below
| is
||| currently what i'm doing
|||
||| Function isURL(ByVal kcString As String)
||| Dim kcFound As String = kcString.IndexOf("://")
||| If kcFound > 0 Then
||| Return True
||| Else
||| Return False
||| End If
||| End Function
|||
||| Function isFile(ByVal kcString As String)
||| Dim kcFound As String = kcString.IndexOf(":\")
||| If kcFound > 0 Then
||| Return True
||| Else
||| Return False
||| End If
||| End Function
|||
|||
|||
||
||
|
|
 
Thank you for your input, I will be trying yours and a couple of other
techniques to see what works best.
Thank you for your comments.
Hmm...

FYI:

Reading Adam Nathan's ".NET and COM - The Complete Interoperability Guide",
I believe I could have simply used Marshal.FreeHGlobal, instead of declaring
the LocalFree function. As FreeHGlobal calls the GlobalFree Win32 API, which
under Win32 does the "same thing" as LocalFree Win32 API...

Jay

| Doh!
|
| That's going to have a slow unmanaged memory leak.
|
| I should be calling LocalFree on the return value from CommandLineToArgvW.
|
|| Declare Unicode Function CommandLineToArgv Lib "shell32" Alias
|| "CommandLineToArgvW"
|| (<MarshalAs(Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal
| commandLine
|| As String, <Out()> ByRef numberArgs As Integer) As IntPtr
||
|
| Declare Auto Function LocalFree Lib "kernel32" (ByVal hMem As IntPtr)
As
| IntPtr
|
|
|| Public Shared Function ParseCommandLine(ByVal commandLine As String)
As
|| String()
|| Dim count As Integer
|| Dim ptr As IntPtr
|| ptr = CommandLineToArgv(commandLine, count)
|| Dim args(count - 1) As String
|| For index As Integer = 0 To count - 1
|| Dim ptrStr As IntPtr = Marshal.ReadIntPtr(ptr, index *
|| IntPtr.Size)
|| Dim str As String = Marshal.PtrToStringUni(ptrStr)
|| args(index) = str
|| Next
|
| LocalFree(ptr)
|
|| Return args
|| End Function
|
| I would consider wrapping the For Loop in a Try/Finally block to ensure
that
| LocalFree was called even in an exception occurred...
|
| Hope this helps
| Jay
|
| || C.A. Kelly,
|| Have you looked at either the System.IO.Path or System.Uri classes?
||
|| I believe just Uri itself can be used. Something like:
||
|| Declare Unicode Function CommandLineToArgv Lib "shell32" Alias
|| "CommandLineToArgvW"
|| (<MarshalAs(Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal
| commandLine
|| As String, <Out()> ByRef numberArgs As Integer) As IntPtr
||
|| Public Shared Function ParseCommandLine(ByVal commandLine As String)
As
|| String()
|| Dim count As Integer
|| Dim ptr As IntPtr
||
|| ptr = CommandLineToArgv(commandLine, count)
||
|| Dim args(count - 1) As String
||
|| For index As Integer = 0 To count - 1
|| Dim ptrStr As IntPtr = Marshal.ReadIntPtr(ptr, index *
|| IntPtr.Size)
|| Dim str As String = Marshal.PtrToStringUni(ptrStr)
|| args(index) = str
|| Next
|| Return args
|| End Function
||
|| Public Shared Function IsURL(ByVal kcString As String) As Boolean
|| Dim kcUri As New Uri(kcString)
|| Return kcUri.Scheme <> Uri.UriSchemeFile
|| End Function
||
|| Public Shared Function IsFile(ByVal kcString As String) As Boolean
|| Dim kcUri As New Uri(kcString)
|| Return kcUri.Scheme = Uri.UriSchemeFile
|| End Function
||
|| Public Shared Sub Main()
|| Dim commandLines() As String = {"""c:\Program Files\Windows Media
|| Player\wmplayer.exe""", _
|| """c:\program files\windows media player\mplayer2.exe""
/open",
|| _
||
| """http://radio.msn.com/asx/generate.aspx?type=genre&id=10002364""
|| /play http://myfavoritepages"}
||
|| For Each commandLine As String In commandLines
|| Dim args() As String = ParseCommandLine(commandLine)
|| Debug.WriteLine(commandLine, "commandLine")
|| Debug.Indent()
|| Debug.WriteLine(IsURL(args(0)), "isUrl")
|| Debug.WriteLine(IsFile(args(0)), "isFile")
|| For Each arg As String In args
|| Debug.WriteLine(arg, "arg")
|| Next
|| Debug.Unindent()
|| Next
|| End Sub
||
|| NOTE: I use the CommandLineToArgvW Win32 API along with the
| ParseCommandLine
|| function to parse the string into individual arguments.
||
|| Hope this helps
|| Jay
||
|| |||I have a program that I want to launch links if certain criteria is met,
|| the
||| problem is how can I determine if a string is a program to launch, here
| is
||| an example
||| with quotes->
||| "c:\Program Files\Windows Media Player\wmplayer.exe"
||| "c:\program files\windows media player\mplayer2.exe" /open
||| "http://radio.msn.com/asx/generate.aspx?type=genre&id=10002364" /play
||| http://myfavoritepages
|||
||| it won't always be c:\ drive and sometimes it might be a ftp link below
| is
||| currently what i'm doing
|||
||| Function isURL(ByVal kcString As String)
||| Dim kcFound As String = kcString.IndexOf("://")
||| If kcFound > 0 Then
||| Return True
||| Else
||| Return False
||| End If
||| End Function
|||
||| Function isFile(ByVal kcString As String)
||| Dim kcFound As String = kcString.IndexOf(":\")
||| If kcFound > 0 Then
||| Return True
||| Else
||| Return False
||| End If
||| End Function
|||
|||
|||
||
||
|
|
 
I didn't spend enough time staring at the code to understand why you go to
all the work of calling the base Windows API to fetch the command line
arguments rather than simply calling Environment.GetCommandLineArgs, but...
I'm intrigued by the comment about LocalFree vs. Marshal.FreeHGlobal. I
have code that calls the Windows FormatMessage function with arguments that
cause FormatMessage to allocate a buffer on my behalf. The docs state that
I should call LocalFree to free the buffer.

Can someone please confirm that Marshal.FreeHGlobal is guranteed to work in
place of a p/invoke call to LocalFree. TIA!

- Bob
 
Bob,
|I didn't spend enough time staring at the code to understand why you go to
| all the work of calling the base Windows API to fetch the command line
| arguments rather than simply calling Environment.GetCommandLineArgs,
Rather then user Environment.GetCommandLineArgs I normally simply add
parameters to my Sub Main, something like:

Public Sub Main(ByVal args() as String)

I was using the Windows API as the original poster stated "launch links if
certain criteria is met", notice the plural "links", which to me suggests
that he is getting the "links" aka "command lines" from someplace other then
the command line to the program itself. Such as reading them from a file.

| Can someone please confirm that Marshal.FreeHGlobal is guranteed to work
in
| place of a p/invoke call to LocalFree. TIA!
I will see what I can find out.

Hope this helps
Jay


|I didn't spend enough time staring at the code to understand why you go to
| all the work of calling the base Windows API to fetch the command line
| arguments rather than simply calling Environment.GetCommandLineArgs,
but...
| I'm intrigued by the comment about LocalFree vs. Marshal.FreeHGlobal. I
| have code that calls the Windows FormatMessage function with arguments
that
| cause FormatMessage to allocate a buffer on my behalf. The docs state
that
| I should call LocalFree to free the buffer.
|
| Can someone please confirm that Marshal.FreeHGlobal is guranteed to work
in
| place of a p/invoke call to LocalFree. TIA!
|
| - Bob
|
| | > Hmm...
| >
| > FYI:
| >
| > Reading Adam Nathan's ".NET and COM - The Complete Interoperability
| Guide",
| > I believe I could have simply used Marshal.FreeHGlobal, instead of
| declaring
| > the LocalFree function. As FreeHGlobal calls the GlobalFree Win32 API,
| which
| > under Win32 does the "same thing" as LocalFree Win32 API...
| >
| > Jay
| >
message
| > | > | Doh!
| > |
| > | That's going to have a slow unmanaged memory leak.
| > |
| > | I should be calling LocalFree on the return value from
| CommandLineToArgvW.
| > |
| > || Declare Unicode Function CommandLineToArgv Lib "shell32" Alias
| > || "CommandLineToArgvW"
| > || (<MarshalAs(Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal
| > | commandLine
| > || As String, <Out()> ByRef numberArgs As Integer) As IntPtr
| > ||
| > |
| > | Declare Auto Function LocalFree Lib "kernel32" (ByVal hMem As
IntPtr)
| > As
| > | IntPtr
| > |
| > |
| > || Public Shared Function ParseCommandLine(ByVal commandLine As
String)
| > As
| > || String()
| > || Dim count As Integer
| > || Dim ptr As IntPtr
| > || ptr = CommandLineToArgv(commandLine, count)
| > || Dim args(count - 1) As String
| > || For index As Integer = 0 To count - 1
| > || Dim ptrStr As IntPtr = Marshal.ReadIntPtr(ptr, index *
| > || IntPtr.Size)
| > || Dim str As String = Marshal.PtrToStringUni(ptrStr)
| > || args(index) = str
| > || Next
| > |
| > | LocalFree(ptr)
| > |
| > || Return args
| > || End Function
| > |
| > | I would consider wrapping the For Loop in a Try/Finally block to
ensure
| > that
| > | LocalFree was called even in an exception occurred...
| > |
| > | Hope this helps
| > | Jay
| > |
| message
| > | | > || C.A. Kelly,
| > || Have you looked at either the System.IO.Path or System.Uri classes?
| > ||
| > || I believe just Uri itself can be used. Something like:
| > ||
| > || Declare Unicode Function CommandLineToArgv Lib "shell32" Alias
| > || "CommandLineToArgvW"
| > || (<MarshalAs(Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal
| > | commandLine
| > || As String, <Out()> ByRef numberArgs As Integer) As IntPtr
| > ||
| > || Public Shared Function ParseCommandLine(ByVal commandLine As
String)
| > As
| > || String()
| > || Dim count As Integer
| > || Dim ptr As IntPtr
| > ||
| > || ptr = CommandLineToArgv(commandLine, count)
| > ||
| > || Dim args(count - 1) As String
| > ||
| > || For index As Integer = 0 To count - 1
| > || Dim ptrStr As IntPtr = Marshal.ReadIntPtr(ptr, index *
| > || IntPtr.Size)
| > || Dim str As String = Marshal.PtrToStringUni(ptrStr)
| > || args(index) = str
| > || Next
| > || Return args
| > || End Function
| > ||
| > || Public Shared Function IsURL(ByVal kcString As String) As Boolean
| > || Dim kcUri As New Uri(kcString)
| > || Return kcUri.Scheme <> Uri.UriSchemeFile
| > || End Function
| > ||
| > || Public Shared Function IsFile(ByVal kcString As String) As Boolean
| > || Dim kcUri As New Uri(kcString)
| > || Return kcUri.Scheme = Uri.UriSchemeFile
| > || End Function
| > ||
| > || Public Shared Sub Main()
| > || Dim commandLines() As String = {"""c:\Program Files\Windows
| Media
| > || Player\wmplayer.exe""", _
| > || """c:\program files\windows media player\mplayer2.exe""
| > /open",
| > || _
| > ||
| > | """http://radio.msn.com/asx/generate.aspx?type=genre&id=10002364""
| > || /play http://myfavoritepages"}
| > ||
| > || For Each commandLine As String In commandLines
| > || Dim args() As String = ParseCommandLine(commandLine)
| > || Debug.WriteLine(commandLine, "commandLine")
| > || Debug.Indent()
| > || Debug.WriteLine(IsURL(args(0)), "isUrl")
| > || Debug.WriteLine(IsFile(args(0)), "isFile")
| > || For Each arg As String In args
| > || Debug.WriteLine(arg, "arg")
| > || Next
| > || Debug.Unindent()
| > || Next
| > || End Sub
| > ||
| > || NOTE: I use the CommandLineToArgvW Win32 API along with the
| > | ParseCommandLine
| > || function to parse the string into individual arguments.
| > ||
| > || Hope this helps
| > || Jay
| > ||
| > || | > |||I have a program that I want to launch links if certain criteria is
| met,
| > || the
| > ||| problem is how can I determine if a string is a program to launch,
| here
| > | is
| > ||| an example
| > ||| with quotes->
| > ||| "c:\Program Files\Windows Media Player\wmplayer.exe"
| > ||| "c:\program files\windows media player\mplayer2.exe" /open
| > ||| "http://radio.msn.com/asx/generate.aspx?type=genre&id=10002364"
/play
| > ||| http://myfavoritepages
| > |||
| > ||| it won't always be c:\ drive and sometimes it might be a ftp link
| below
| > | is
| > ||| currently what i'm doing
| > |||
| > ||| Function isURL(ByVal kcString As String)
| > ||| Dim kcFound As String = kcString.IndexOf("://")
| > ||| If kcFound > 0 Then
| > ||| Return True
| > ||| Else
| > ||| Return False
| > ||| End If
| > ||| End Function
| > |||
| > ||| Function isFile(ByVal kcString As String)
| > ||| Dim kcFound As String = kcString.IndexOf(":\")
| > ||| If kcFound > 0 Then
| > ||| Return True
| > ||| Else
| > ||| Return False
| > ||| End If
| > ||| End Function
| > |||
| > |||
| > |||
| > ||
| > ||
| > |
| > |
| >
| >
|
|
 
Reflector to the rescue! I looked at Marshal.FreeHGlobal using Lutz
Roeder's most excellent tool, and, sure enough, it just calls the native
LocalFree function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top