|
|
|
At times you may need to access the command line passed to the application from within an ActiveX DLL. Unfortunately, when inside a DLL the Command$ function returns a null string, so you have to resort to some API trickery: |
Click here to copy the following block | Private Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineA" _ () As Long Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal _ lpString1 As String, ByVal lpString2 As Long) As Long
Dim lpStr As Long, i As Long Dim buffer As String Dim exePath As String, cmdLine As String
lpStr = GetCommandLine()
buffer = Space$(512) lstrcpy buffer, lpStr
buffer = Left$(buffer, InStr(buffer & vbNullChar, vbNullChar) - 1) If Left$(buffer, 1) = """" Then i = InStr(2, buffer, """") exePath = Mid$(buffer, 2, i - 2) cmdLine = LTrim$(Mid$(buffer, i + 1)) Else i = InStr(buffer, " ") exePath = Left$(buffer, i - 1) cmdLine = LTrim$(Mid$(buffer, i)) End If |
Now cmdLine holds the command line passed to the main application, and exePath is the name and path of the EXEcutable file. Note that according to MSDN exePath contains only the EXE name under NT/2000 (as opposed to the full path) but it doesn't appear to be true (at least under NT SP4).
|
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|