H
hjackman
Cany anybody please tell me what I am doing wrong?
The second time I call the GetTempPathW function the temporary path string
is returned; however, if you look at the string in the Autos window you can
see that the string is not Null terminated because there is no quotation
mark at the end of the string. This causes other API calls to screw up. I
can circumvent this by using a temporary variable in the second call and
then copy over the characters to a new variable but I would like to know why
the string isn't terminated.
I don't know if this helps but it did not matter the size of the buffer I
passed to the function. It still did not terminate the string.
Operating System: Windows 2000 Professional
<DllImport("kernel32")> _
Private Shared Function GetTempPathW(ByVal BufferLength As Integer,
<MarshalAs(UnmanagedType.LPWStr)> ByVal Buffer As String) As Integer
End Function
Public Function GetTempPath() As String
Dim RV As Integer
Dim Path As String
Dim Length As Integer
'Call the function the first time to determine the size of the buffer
needed.
RV = GetTempPathW(Length, Nothing)
If (RV = 0) Then Return ""
'Allocate the buffer and call again.
Path = Space(RV)
RV = GetTempPathW(Length, Path)
If (RV = 0) Then Return ""
Return Path
End Function
Thank You
The second time I call the GetTempPathW function the temporary path string
is returned; however, if you look at the string in the Autos window you can
see that the string is not Null terminated because there is no quotation
mark at the end of the string. This causes other API calls to screw up. I
can circumvent this by using a temporary variable in the second call and
then copy over the characters to a new variable but I would like to know why
the string isn't terminated.
I don't know if this helps but it did not matter the size of the buffer I
passed to the function. It still did not terminate the string.
Operating System: Windows 2000 Professional
<DllImport("kernel32")> _
Private Shared Function GetTempPathW(ByVal BufferLength As Integer,
<MarshalAs(UnmanagedType.LPWStr)> ByVal Buffer As String) As Integer
End Function
Public Function GetTempPath() As String
Dim RV As Integer
Dim Path As String
Dim Length As Integer
'Call the function the first time to determine the size of the buffer
needed.
RV = GetTempPathW(Length, Nothing)
If (RV = 0) Then Return ""
'Allocate the buffer and call again.
Path = Space(RV)
RV = GetTempPathW(Length, Path)
If (RV = 0) Then Return ""
Return Path
End Function
Thank You