IMA read at address 0
Verfasst: 11.05.2009 12:40
Warum produziert folgender Code mit dem 'Flag' #UseDLL = 0 einen IMA
[line: 39] IMA (read error at address 0)
jedoch mit #UseDLL = 1 nicht obwohl beide Varianten Prinzipiell das gleiche tun?
test.data
Ferner kann ich in die Variante #UseDLL nicht zweimal hintereinander auf rufen sprich:
[line: 39] IMA (read error at address 0)
jedoch mit #UseDLL = 1 nicht obwohl beide Varianten Prinzipiell das gleiche tun?
test.data
Code: Alles auswählen
Enumeration
#Window
#File
#Library
#String_0
#String_1
#String_2
#Font
EndEnumeration
LoadFont (#Font, "SimSun", 40)
If ReadFile(#File, "X:\test.data")
input.s = ReadString(#File, #PB_Unicode)
CloseFile(#File)
EndIf
#UseDLL = 0 ; 1 use transformation via c_g18030.dll
; 0 use transformation via MultiByteToWideChar_ / WideCharToMultiByte_
output.s = Space(Len(input))
If #UseDLL
pcchLeftOverBytes.s = Space(Len(input)) ; UINT that contains GB18030 bytes at the end of the buffer
; that cannot be converted. These bytes could be the leading
; bytes of valid GB18030 bytes in the Next incoming GB18030 bytes.
OpenLibrary(#Library, "c_g18030.dll")
CallFunction(#Library, "BytesToUnicode", @input, Len(input)*2, @pcchLeftOverBytes, @output, Len(output)*2)
; Transforms Unicode (GB2212) to GB18030
output2.s = Space(Len(output))
CallFunction(#Library, "UnicodeToBytes", @output, Len(output), @output2, Len(output2) * 2)
; Transforms GB18030 to Unicode (GB2212)
Else
CodePage = 54936 ; CodePage of GB18030
dwFlags = 0 ; Otherwise, the function fails with ERROR_INVALID_FLAGS
MultiByteToWideChar_(CodePage, dwFlags, @input, Len(input)*2, @output, Len(output)*2)
; Transforms Unicode (GB2212) to GB18030
output2.s = Space(Len(output))
WideCharToMultiByte_(CodePage, dwFlags, @output, Len(output)*2, @output2, Len(output2) * 2, 0, 0)
; Transforms GB18030 to Unicode (GB2212)
EndIf
If OpenWindow(#Window, 100, 200, 750, 200, "GB18030 transformation demo")
If CreateGadgetList(WindowID(0))
StringGadget(#String_0, 10, 10, 730, 60, "Unicode (GB2212)")
StringGadget(#String_1, 10, 70, 730, 60, "Unicode (GB2212) -> GB18030")
StringGadget(#String_2, 10, 130, 730, 60, "GB18030 -> Unicode (GB2212)")
EndIf
SetGadgetFont(#String_0, FontID(#Font))
SetGadgetFont(#String_1, FontID(#Font))
SetGadgetFont(#String_2, FontID(#Font))
SetGadgetText(#String_0, input)
SetGadgetText(#String_1, output)
SetGadgetText(#String_2, output2)
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_CloseWindow
quit = 1
EndIf
Until quit = 1
EndIf
End
Code: Alles auswählen
!!! PSEUDOCODE !!!
input = ReadString(#File, #PB_Unicode)
output = Space(Len(input))
CallFunction(#Library, "BytesToUnicode", @input, Len(input)*2, @Space(Len(input)), @output, Len(output)*2)
input = ReadString(#File, #PB_Unicode)
output = Space(Len(input)) <= IMA (read error at address 0)
CallFunction(#Library, "BytesToUnicode", @input, Len(input)*2, @Space(Len(input)), @output, Len(output)*2)