Hallo,
kann man VB.NET und UNICODE vereinen?
Ich möchte, dass meine ganzen Strings und Chars als Unicode gespeichert werden.
Das ganze ist simpel die Umgehung eines BUG, der von Microsoft dokumentiert ist.
Ich habe hier mal einen Auszug des Codes:
<StructLayout(LayoutKind.Sequential)> Public Structure sDrvInfo
Dim cbSize As Long
Dim DriverType As Long
Dim Reserved As Long
<MarshalAs(UnmanagedType.LPWStr)> Dim Description As String
<MarshalAs(UnmanagedType.LPWStr)> Dim MfgName As String
<MarshalAs(UnmanagedType.LPWStr)> Dim ProviderName As String
Sub New(ByVal b As Boolean)
cbSize = Marshal.SizeOf(Me) : DriverType = 0 : Reserved = 0
End Sub
End Structure
...
<DllImport("setupapi.dll")> Private Shared Function _
SetupDiEnumDriverInfoW(ByVal DeviceInfoSet As IntPtr, ByRef _
DeviceInfoData As Devices.clsDeviceInfo.sDevInfo, ByVal DriverType As _
UInt32, ByVal MemberIndex As UInt32, ByRef DriverInfoData As _
sDrvInfo) As Boolean
End FunctionBeim Aufruf dieser Funktion erhalte ich den WindowsErrorCode 1784 (Not enough buffer space).
Dabei passe ich vor der Zuweisung von DrvInfo die cbSize mit dem sizeof() c++-äquivalent an. Microsoft sagt, man solle doch bitte UNICODE verwenden.
Allerdings weiß ich nichts damit anzufangen.
Hier der Link zur Deklaration der API:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/DevInst_r/hh/DevInst_r/di-rtns_8d84a225-9dac-4ab3-8c9a-5048284d82be.xml.asp
"If you do not properly initialize the cbSize member of the SP_DRVINFO_DATA structure that is supplied by the pointer DriverInfoData, the function will fail and log the error ERROR_INVALID_USER_BUFFER."
Was ich schon getan habe:
-LPWStr wird verwendet
-der W -Suffix wird verwendet (Unicode-Call)
-die Structure wird Sequenziell übergeben
Hier nochmal mein kompletter Sektions-Source:
Public Sub GetDriverList(ByVal mPointer As UInt32, ByVal mDevinfo As _
Devices.clsDeviceInfo.sDevInfo)
Dim res As Boolean = SetupDiBuildDriverInfoList(mPointer, mDevinfo, _
&H2)
Console.WriteLine(res & " " & mDevinfo.ClassGuid.ToString) 'TRUE,
' also OK
DrvInfo.cbSize = Marshal.SizeOf(DrvInfo) '40, also OK
res = SetupDiEnumDriverInfoW(mPointer, mDevinfo, &H2, 0, DrvInfo)
Console.WriteLine(res & " " & GetLastError()) 'FALSE 1784, NICHT OK
End Sub Ich versuche das nun schon vier Tage lang, bitte um Hilfe!
MfG.
Fabian Stern
-
info@smart-coding.com
http://www.smart-coding.com |