API GetCommandLine in Word XP returns empty string

H

Hendrik Jan

Hi,

We developed a macro in which we read out the commandline. We use the API
call "GetComandLine" for this. It works great when we use Windows 2000 with
Office 2000, but when we run the macro under Windows 2000 with Office XP, the
API call returns an empty string.
Is there a difference between Office 2000 and Office XP?

Thanks,
Hendrik Jan
 
P

Patrick Smith [MSFT]

Hendrik,

Yes, there is a difference, however I'm not sure exactly what it is yet.

Could you provide the code that you are using on this including any
pertinent variable declarations such as where you are trying to put the
results of the GetCommandLine call?
 
H

Hendrik Jan

Hoi Patrick,

Herby I post some code. I stripped it a bit but the essentials are still in
it. I hope it makes things clear for you.

Thanks,
Hendrik Jan

===================================================
Option Explicit

Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineA" ()
As Long
Public Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal
lpString As Long) As Long
Public Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal
lpString1 As String, ByVal lpString2 As Long) As Long

Public Sub AutoOpen()
'---------------------------------------------------------------------------------------
'Beschrijving : Deze sub wordt uitgevoerd bij het starten van Correspondentie

'Historie
'---------------------------------------------------------------------------------------
'Datum Wie Povir Beschrijving
'---------- --- -----
------------------------------------------------------------
'10/01/2006 EK/HJS 7020 Eerste versie
'---------------------------------------------------------------------------------------

'error handling
On Error GoTo ErrHandler

'statements

'here is other code

'de commandline uitlezen voor het document dat moet worden afgehandeld
Call gen_HandleCommandLineParams("Document")

'here is other code

Exit Sub
'----------
ErrHandler:

Call err_ErrorHandler(Err, "modStartUp - AutoOpen")

End Sub


Public Sub gen_HandleCommandLineParams(acWaarde As String)
'------------------------------------------------------------------------------------------------
'Beschrijving : Uitlezen van de commandlineparameters en deze in de array
met parameters plaatsen
'In : acWaarde - "Document" dan nog geen extra info ophalen
'------------------------------------------------------------------------------------------------

'Historie
'------------------------------------------------------------------------------------------------
'Datum Wie Povir Beschrijving
'---------- --- -----
------------------------------------------------------------------------
'10/01/2006 EK 7020 Eerste versie
'------------------------------------------------------------------------------------------------

'error handling
On Error GoTo ErrHandler

'vars
Dim lcCommandLine As String

'statements
'lees commandline uit en zet deze in de var lcCommandLine
lcCommandLine = CmdLinetoString(GetCommandLine())

'here is other code

Exit Sub
'------------
ErrHandler:

Call err_ErrorHandler(Err, "gen_HandleCommandLineParams")

End Sub

Public Function CmdLinetoString(ByVal lngPtr As Long) As String
'--------------------------------------------------------------------------------------------
'Beschrijving :

'Historie
'--------------------------------------------------------------------------------------------
'Datum Wie Povir Beschrijving
'---------- --- -----
--------------------------------------------------------------------
'10/01/2006 EK 7020 Eeerste versie
'--------------------------------------------------------------------------------------------

'error handling
On Error GoTo ErrHandler

'vars

Dim strReturn As String
Dim StringLength As Long

'get the length of the string (not including the terminating null
character)
StringLength = lstrlen(lngPtr)

'initialize our string so it has enough characters including the null
character
strReturn = String$(StringLength + 1, 0)

'copy the string we have a pointer to into our new string
lstrcpy strReturn, lngPtr

'now strip off the null character at the end
strReturn = Left$(strReturn, StringLength)

'return the string
CmdLinetoString = strReturn

Exit Function
'------------
ErrHandler:

Call err_ErrorHandler(Err, "modGeneral - CmdLineToString")

End Function
===================================================


Thanks,
Hendrik Jan
 

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

Top