A
Ajak
Hello,
I'm converting a VB6 app to VB2005 which uses a third party API dll.
The API function accepts structure as its parameter (byRef).
Below is the struct (shortened for clarity):-
<StructLayout(LayoutKind.Sequential)> _
Public Structure MCPBusType
Public OutBuffer As String <-- the API function will
fill result here: Initialised to String of 4096 characters
Public OutBufferSize As Integer <-- the length/size of outBuffer
(=4096 of course)
Public ResponseLen As Integer
End Structure
And I declare the Api function as follows:-
<DllImport("MCPAPI.DLL", EntryPoint:="McpEnum")> _
Public Shared Function McpEnum(ByRef MCPBus As MCPBusType) As Integer
End Function
My problem is the API function returns result in OutBuffer and it's not
necessarily at the start of it. What I meant is the result in OutBuffer
could be Chr(0) & Chr(0) & "RESULT" & Chr(0) & .... but the expected result
is that "RESULT". If I take a look in OutBuffer, I couldn't get the "RESULT"
but instead it will return zero-length string ("") since there is a null
termination char at the begining of OutBuffer. I couldn't use Mid(OutBuffer,
2, 5) cos that will throw ArgOutOfRangeException.
In VB6, taking the OutBuffer gives me everything including null chars, up to
the length of the string (4096).
So, please, is there a way for me to read the whole 4096 chars in OutBuffer,
including the null chars?
Or is there any way I can change the struct and change OutBuffer to array of
bytes, and pass them to the API function and it will take it as if it was
string variable?
Please help....
I'm converting a VB6 app to VB2005 which uses a third party API dll.
The API function accepts structure as its parameter (byRef).
Below is the struct (shortened for clarity):-
<StructLayout(LayoutKind.Sequential)> _
Public Structure MCPBusType
Public OutBuffer As String <-- the API function will
fill result here: Initialised to String of 4096 characters
Public OutBufferSize As Integer <-- the length/size of outBuffer
(=4096 of course)
Public ResponseLen As Integer
End Structure
And I declare the Api function as follows:-
<DllImport("MCPAPI.DLL", EntryPoint:="McpEnum")> _
Public Shared Function McpEnum(ByRef MCPBus As MCPBusType) As Integer
End Function
My problem is the API function returns result in OutBuffer and it's not
necessarily at the start of it. What I meant is the result in OutBuffer
could be Chr(0) & Chr(0) & "RESULT" & Chr(0) & .... but the expected result
is that "RESULT". If I take a look in OutBuffer, I couldn't get the "RESULT"
but instead it will return zero-length string ("") since there is a null
termination char at the begining of OutBuffer. I couldn't use Mid(OutBuffer,
2, 5) cos that will throw ArgOutOfRangeException.
In VB6, taking the OutBuffer gives me everything including null chars, up to
the length of the string (4096).
So, please, is there a way for me to read the whole 4096 chars in OutBuffer,
including the null chars?
Or is there any way I can change the struct and change OutBuffer to array of
bytes, and pass them to the API function and it will take it as if it was
string variable?
Please help....