nice one ts
Das man irgendwie mit der API auch die Länge rausbekommen soll kann war mir bekannt, allerdings durch meine verkappte aktion mit dem
hab ich bei
Code: Alles auswählen
Debug MultiByteToWideChar_(CodePage, dwFlags, @input, StringByteLength(input), @output, 0)
immer 0 bekommen *shy*
Ferner hab ich festgestellt das es, wenn man die Konvertierung mehrfach hintereinander ausführen will
Code: Alles auswählen
result = MultiByteToWideChar_(54936, 0, *mem, size, 0, 0)
heißen muss weil sonst result beim 2ten Durchlauf 0 wird und bleibt
Code: Alles auswählen
EnableExplicit
Define.l FF, size, *mem, result, *unistring, result2, *utfstring
Define.s text, text2
*unistring = AllocateMemory(1000)
*utfstring = AllocateMemory(1000)
FF = ReadFile(#PB_Any, "X:\test.data")
If FF
size = Lof(FF)
*mem = AllocateMemory(size)
If *mem
ReadData(FF, *mem, size)
result = MultiByteToWideChar_(54936, 0, *mem, size, 0, 0)
Debug result
If result
*unistring = ReAllocateMemory(*unistring, result + 2)
If *unistring
If MultiByteToWideChar_(54936, 0, *mem, size, *unistring, result)
text = PeekS(*unistring, result, #PB_Unicode)
EndIf
EndIf
EndIf
result2 = WideCharToMultiByte_(54936, 0, *unistring, result, 0, 0, 0, 0)
Debug result2
If result2
*utfstring = ReAllocateMemory(*utfstring, result2 + 2)
If *utfstring
If WideCharToMultiByte_(54936, 0, *unistring, result, *utfstring, result2, 0, 0)
text2 = PeekS(*utfstring, result2, #PB_Unicode)
EndIf
EndIf
EndIf
Else
CloseFile(FF)
EndIf
EndIf
OpenWindow(0, #PB_Ignore, #PB_Ignore, 850, 120, "", #PB_Window_SystemMenu)
If CreateGadgetList(WindowID(0))
StringGadget(0, 10, 10, 830, 40, "")
StringGadget(1, 10, 60, 830, 40, "")
SetGadgetFont(0, FontID(LoadFont(#PB_Any, "SimSun", 24)))
SetGadgetText(0, text)
SetGadgetFont(1, FontID(LoadFont(#PB_Any, "SimSun", 24)))
SetGadgetText(1, text2)
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Also wenn ich den Speicher vorher alloziiere funktioniert das ganze allerdings nicht wenn ich versuche das ganze zur Laufzeit zu machen, was ich aber eigtl unbedingt können muss, sprich wenn ich statt
Code: Alles auswählen
*utfstring = AllocateMemory(1000)
*utfstring = ReAllocateMemory(*utfstring, result2 + 2)
nur
verwende bekomm ich wieder nen IMA, das ist doch nicht normal oder?!
Oder bin ich einfach nicht in der Lage zu verstehen wie man die Memory-Funktion von PB richtig verwendet?! T_T