Dear All;
When I run the following code in 32-bit Excel (Windows 10):
everything looks as expected, but in 64-bit Excel lstrlenW() call always returns 0.
What should I change to have this code '64-bit Excel' compatible?
Thanks in advance. S.Br.
When I run the following code in 32-bit Excel (Windows 10):
VBA Code:
Option Explicit
Option Base 0
Declare PtrSafe Function GetCommandLine Lib "Kernel32" Alias "GetCommandLineW" () As Long
Declare PtrSafe Function lstrlenW Lib "Kernel32" (ByVal lstrptr As Long) As Long
Declare PtrSafe Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" (pDest As Any, pSrc As Any, ByVal l As Long)
Sub Button1_Click()
Dim lCmdLineAddr As Long
Dim lCmdLineLen As Long 'length of command line
Dim sCmdLineStr As String
Dim buff() As Byte
On Error GoTo lblErr
lCmdLineAddr = GetCommandLine
lCmdLineLen = lstrlenW(lCmdLineAddr) * 2
ReDim buff(0 To (lCmdLineLen - 1)) As Byte
CopyMemory buff(0), ByVal lCmdLineAddr, lCmdLineLen
sCmdLineStr = buff
MsgBox "[" & sCmdLineStr & "]"
Exit Sub
lblErr:
MsgBox Err.Number & vbCrLf & Err.Description
End Sub
What should I change to have this code '64-bit Excel' compatible?
Thanks in advance. S.Br.