Dim sString As String Dim bBuf(1 To 10) As Byte Dim pVarPtr As Long Dim pStrPtr As Long Dim bTarget As Byte Dim lTarget As Long sString = "help" ' Print the BSTR's initial address and contents Debug.Print "VarPtr:" & VarPtr(sString) Debug.Print "StrPtr:" & StrPtr(sString) ' Call the external function Debug.Print "Function called. Return value:" & _ rpiBSTRToByteArray(sString, bBuf(1), pVarPtr, pStrPtr ' Print what the DLL sees, which is the temp ABSTR ' Its address and contents are: Debug.Print 'Address of temp ABSTR as DLL sees it: " & pVarPtr Debug.Print 'Contents of temp ABSTR as DLL sees it: " & pStrPtr ' Print the buffer pointed to by temp ABSTR Debug.Print 'Temp character array: "; For i = 1 To 10 Debug.Print bBuf(i); Next Debug.Print ' Now that we have returned from the DLL function call ' check status of the passed string buffer -- it has been deallocated VBGetTarget lTarget, pVarPtr, 4 Debug.Print 'Contents of temp ABSTR after DLL returns: " & lTarget ' Check the string for altered character Debug.Print 'BSTR is now: " & sString End Sub |