Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Get the Command$ value from inside an ActiveX DLL

Total Hit ( 3177)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


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

' inside the ActiveX DLL
  
Dim lpStr As Long, i As Long
Dim buffer As String
Dim exePath As String, cmdLine As String
  
' get a pointer to the command line
lpStr = GetCommandLine()
' copy into a local buffer
buffer = Space$(512)
lstrcpy buffer, lpStr
' extract the null-terminated string
buffer = Left$(buffer, InStr(buffer & vbNullChar, vbNullChar) - 1)
  
If Left$(buffer, 1) = """" Then
  ' if the string begins with double quotes,
  ' find the closing quotes
  i = InStr(2, buffer, """")
  exePath = Mid$(buffer, 2, i - 2)
  ' the rest of the line is the command line
  cmdLine = LTrim$(Mid$(buffer, i + 1))
Else
  ' otherwise just find the space that separates
  ' the EXE name/path and the command line
  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 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.