Clipboard OEMText is confusing

  • Thread starter Thread starter **Developer**
  • Start date Start date
D

**Developer**

If I open a Command Prompt window and with the Alt key enter 222 then 223
then 224 so the window shows ???

If I then copy that to the clipboard and in my program do

Case DataFormats.OemText
Dim bDataO As DataObject = Clipboard.GetDataObject()
If bDataO.GetDataPresent(DataFormats.OemText, False) Then
Editor1.Text = CType(bDataO.GetData(DataFormats.OemText, False), String)
End If

I get some symbol I don't know followed by a beta followed by an "a" with a
dot over it.

I'd expect to get the same symbols that show in the Command window.
I don't know why I expect that except that I thought the Command wondow was
like DOS and DOS used OEM?

I'd appreciate a few works of enlightment.

Would you expect to see what I see or what I expected to see?

Why?



Thanks in advance for any helpful rempl.
 
**Developer** said:
If I open a Command Prompt window and with the Alt key enter 222 then 223
then 224 so the window shows ???

If I then copy that to the clipboard and in my program do

Case DataFormats.OemText
Dim bDataO As DataObject = Clipboard.GetDataObject()
If bDataO.GetDataPresent(DataFormats.OemText, False) Then
Editor1.Text = CType(bDataO.GetData(DataFormats.OemText, False), String)
End If

I get some symbol I don't know followed by a beta followed by an "a" with
a dot over it.

I'd expect to get the same symbols that show in the Command window.
I don't know why I expect that except that I thought the Command wondow
was like DOS and DOS used OEM?

Maybe an auto-conversion from DOS-OEM to Unicode is done and characters are
interpreted the wrong way. Untested:

\\\
Imports System.Globalization
Imports System.Text
..
..
..

''' <summary>
''' Konvertiert den Text in <paramref name="Text"/> von der DOS-
''' Codepage (OEM) in die Windows-Codepage (ANSI).
''' </summary>
''' <param name="Text">Text, der konvertiert werden soll.</param>
''' <returns>
''' Der Text aus <paramref name="Text"/> in der aktuellen Windows-
''' Codepage.
''' </returns>
Private Function ConvertFromOem(ByVal Text As String) As String
Return _
Encoding.GetEncoding( _
CultureInfo.InstalledUICulture.TextInfo.OEMCodePage _
).GetString(Encoding.Default.GetBytes(Text))
End Function
///
 
Maybe an auto-conversion from DOS-OEM to Unicode is done and characters
are interpreted the wrong way. Untested:
Guess it's tested now - works for me - Thanks

This is what I tried but it didn't work.
Do you see what is wrong with it?
Called with 437

Public Shared Function GetCodePageString(ByVal str As String, ByVal codePage
As Integer) As String

Dim OutEncoding As Encoding = Encoding.GetEncoding(codePage)

Dim InEncoding As Encoding = Encoding.Unicode

Dim StrAsBytes As Byte() = InEncoding.GetBytes(str)

Dim OutEncodingBytes As Byte() = Encoding.Convert(InEncoding, OutEncoding,
StrAsBytes)

Dim OutEncodingChars(lOutEncoding.GetCharCount(OutEncodingBytes, 0,
OutEncodingBytes.Length)) As Char

GetCodePageString = New String(OutEncodingChars)

End Function
 
I also interchanged the definition of OutEncoding and InEncoding
Still did not work
 
Back
Top