Good Day
and Happy New Year to all of you!
I was wondering if we should trust the auto-marshalling done by the CLR or
not ?
i mean this works very fine :
'***
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Private Shared Function GetPrivateProfileString( _
ByVal lpAppName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As StringBuilder, _
ByVal nSize As Int32, _
ByVal lpFileName As String) As Int32
'
End Function
'***
is there any advantage to hardcode the marshaling type like this (except for
the fact that we got self-documented code) ?
'***
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Private Shared Function GetPrivateProfileString( _
<MarshalAs(UnmanagedType.LPTStr)> ByVal lpAppName As String, _
<MarshalAs(UnmanagedType.LPTStr)> ByVal lpKeyName As String, _
<MarshalAs(UnmanagedType.LPTStr)> ByVal lpDefault As String, _
<MarshalAs(UnmanagedType.LPTStr)> ByVal lpReturnedString As
StringBuilder, _
<MarshalAs(UnmanagedType.U2)> ByVal nSize As Int32, _
<MarshalAs(UnmanagedType.LPTStr)> ByVal lpFileName As String) As Int32
'
End Function
'***
also is there any garantee that the defaults auto-marshalling made by the
CLR changes over the next versions and makes our actual
non-explicitly-marshalled API declaration crash in the future ?
thanks a lot !
--
Best Regards
Yanick