Passing String To DLL Function - String Not Returned Properly
Posted on 2010-09-22
I'm trying to call a DLL function, passing it a string, expecting it to modify the string and return it.
Declare Function GetLastError Lib "DBAPI2.dll" (ByRef msg As StringBuilder) As Integer
<MarshalAs(UnmanagedType.LPStr)> Public tmsg As New StringBuilder("Default" & Chr(0), 4096)
According to documentation, the function should expect to be passed a string of size 4096.
Result = GetLastError(tmsg)
Calling GetLastError should return an error message placed in tmsg. Whenever I call GetLastError though, I'm either returned an empty string, or 1 weird character.
Am I doing something wrong in my implementation here? Any insight?