1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| Private Declare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As Long
Private Declare Function GetProcessHeap Lib "kernel32" () As Long
Private Declare Sub CopyMemoryWrite Lib "kernel32" Alias "RtlMoveMemory" (Destination As Long, ByVal Source As String, ByVal Length As Long)
Private Declare Sub ShowArrayString Lib "TheDll.dll" (ByRef ArrayPtr As ArrayStruct)
Private Sub Form_Load()
Dim TheArray(10) As String
Dim ArrayString As ArrayStruct
Dim ArrayLen As Integer
Dim OffsetPtr As Long
Dim hHeap As Long
Dim ArrayAscii As String
ChDir App.Path
CurDir Left(App.Path, 3)
For i = 1 To UBound(TheArray())
TheArray(i) = "Sentence n° " + Str(i)
ArrayLen = ArrayLen + Len("Sentence n° " + Str(i))
Next
ArrayString.Size = UBound(TheArray())
hHeap = GetProcessHeap()
ArrayString.Ptr = HeapAlloc(hHeap, 0, ArrayLen)
OffsetPtr = ArrayString.Ptr
For i = 1 To UBound(TheArray())
ArrayAscii = StrConv(TheArray(i), vbFromUnicode)
CopyMemoryWrite OffsetPtr, ArrayAscii, LenB(ArrayAscii)
OffsetPtr = OffsetPtr + LenB(ArrayAscii)
Next
ShowArrayString ArrayString
HeapFree GetProcessHeap(), 0, ArrayString.Ptr
End Sub |
Partager