The MASM Forum

General => The Campus => Topic started by: bomz on February 11, 2022, 12:50:11 PM

Title: non-english windows clipboard problem
Post by: bomz on February 11, 2022, 12:50:11 PM
Hello to all!
I have put data to clip board problem with russian windows 7 x64.
Google say that is microsoft problem with 1250 1251 1252 code pages
found some advice but can't understand what to do.
windows patch - bad way.
void ToClipboard(char* text)
{
    if(OpenClipboard(0))
    {
        EmptyClipboard();
        char* clip_data = (char*)(GlobalAlloc(GMEM_FIXED, MAX_PATH));
        lstrcpy(clip_data, text);
        SetClipboardData(CF_TEXT, (HANDLE)(clip_data));
        LCID* lcid = (DWORD*)(GlobalAlloc(GMEM_FIXED, sizeof(DWORD)));
        *lcid = MAKELCID(MAKELANGID(LANG_RUSSIAN, SUBLANG_NEUTRAL), SORT_DEFAULT);
        SetClipboardData(CF_LOCALE, (HANDLE)(lcid));
        CloseClipboard();
    }
}

(http://b.radikal.ru/b07/2202/10/c3422b9ca780.png)
Title: Re: non-english windows clipboard problem
Post by: six_L on February 11, 2022, 05:21:25 PM
try to test as following.
local TestBuffer[256]:word

invoke MultiByteToWideChar,CP_ACP,0,clip_data,-1,addr TestBuffer,256
Title: Re: non-english windows clipboard problem
Post by: TimoVJL on February 11, 2022, 08:11:53 PM
Making an UNICODE application is also one option.
Title: Re: non-english windows clipboard problem
Post by: jj2007 on February 11, 2022, 08:22:38 PM
GuiParas equ "Hello World", x660, y50, w400, h300, m4, b LiteBlueGreen ; position, margins, background colour
GuiMenu equ @File, &Open, &Save, -, E&xit, @Edit, Undo, Copy, Paste
include \masm32\MasmBasic\Res\MbGui.asm
  GuiControl MyEdit, "edit", 'У меня проблема с "поместить данные в буфер обмена" в русской windows 7x64', font -18, bcol LiteBlueGreen
  GuiControl MyStatus, "statusbar", "Use 'Copy' in the menu to copy 'русской' into the clipboard"

Event Command
  Switch_ MenuID
  Case_ 4                       ; case Edit/Copy
        .if Instr_(Win$(hMyEdit), "русской")
                wSetClip$ wRec$(Left$(eax, 14))
                SetStatus$ "String 'русской' copied"
        .endif
  Case_ 2: invoke SendMessage, hGui, WM_CLOSE, 0, 0
  Endsw_
GuiEnd
Title: Re: non-english windows clipboard problem
Post by: bomz on February 11, 2022, 09:16:08 PM
great thanks.
obvious problem and no easy decision. I even don't understand essence of problem

clipboard not a memory, but a hide notebook window?
Title: Re: non-english windows clipboard problem
Post by: jj2007 on February 11, 2022, 10:22:56 PM
The essence of the problem is that you should use Unicode, UTF-16 and UTF-8. The old code pages are messy.
Title: Re: non-english windows clipboard problem
Post by: bomz on February 11, 2022, 10:34:13 PM
interesting the problem is to switch to RU language from ENG

shift ctrl or shit alt

(http://d.radikal.ru/d30/2202/f6/64c35d02382c.png)
Title: Re: non-english windows clipboard problem
Post by: nidud on February 11, 2022, 10:59:29 PM
deleted
Title: Re: non-english windows clipboard problem
Post by: bomz on February 11, 2022, 11:07:56 PM
LoadKeyboardLayout - must change locale of my pipe(?!)

invoke LoadKeyboardLayout,419, KLF_ACTIVATE
error

+-------------------------+-------------------------+
|     SubLanguage ID      |   Primary Language ID   |
+-------------------------+-------------------------+
15                    10  9                         0   bit


invoke GetKeyboardLayout,0 -> 67699721 = 100000010010000010000001001 it is english

Title: Re: non-english windows clipboard problem
Post by: jj2007 on February 11, 2022, 11:31:51 PM
Quote from: nidud on February 11, 2022, 10:59:29 PMThe problem is most likely that he do not have a Russian version of Windows but an English version with a language pack.

I have an Italian OS, and my code above works just fine with Russian. How many times do we have to discuss this?

Attached the Chinese version. I definitely don't have a Chinese language pack, this is just standard Windows 7.
Title: Re: non-english windows clipboard problem
Post by: bomz on February 11, 2022, 11:48:45 PM
.asc how open asc?
Title: Re: non-english windows clipboard problem
Post by: nidud on February 12, 2022, 12:49:44 AM
deleted
Title: Re: non-english windows clipboard problem
Post by: jj2007 on February 12, 2022, 04:01:41 AM
Quote from: bomz on February 11, 2022, 11:48:45 PM
.asc how open asc?

RichMasm (http://masm32.com/board/index.php?topic=5314.0), Wordpad, MS Word. It's a *.rtf file. Oops, I just realised it's called Chinese version but the text is Arabic - my bad :tongue:

Quote from: nidud on February 12, 2022, 12:49:44 AMNot sure what the angle is here and why you insist on promoting this bullshit (you get paid for this?). Russians should use a Russian version of Windows for the same reason you use an Italian version. The Windows API's wont work without language support as it forces the use of Unicode.

You are truly obsessed with this weird Norwegian point of view. Get over it, Utf-8 and Utf-16 have been around for a really long time.
Title: Re: non-english windows clipboard problem
Post by: nidud on February 12, 2022, 06:20:47 AM
deleted
Title: Re: non-english windows clipboard problem
Post by: hutch-- on February 12, 2022, 07:56:53 AM
This is google translate.

This is a test of English to Russian text done in Google translation.

Это тест англо-русского текста, выполненный в переводе Google.

I could paste it directly into my editor but if you save it as text, reopening it produce ?????????? text. It needs a UNICODE editor. Tested in the UNICODE editor it displays correctly.

Title: Re: non-english windows clipboard problem
Post by: nidud on February 12, 2022, 10:05:29 AM
deleted
Title: Re: non-english windows clipboard problem
Post by: jj2007 on February 12, 2022, 03:05:36 PM
Nidud, I am so sorry that your tools don't allow to work with all languages supported by Windows :tongue:

(http://www.jj2007.eu/pics/RussianOnItalianOS.png)

(http://www.jj2007.eu/pics/ChineseOnItalianOS.png)
Title: Re: non-english windows clipboard problem
Post by: bomz on February 12, 2022, 04:38:12 PM
Thanks. Why this don't work?
invoke LoadKeyboardLayout,0419h, KLF_ACTIVATE

http://d.radikal.ru/d34/2202/dd/bc95aced2e17.jpg
http://d.radikal.ru/d17/2202/11/ab7ada8b1edf.jpg
http://a.radikal.ru/a33/2202/87/64ad05119bf2.jpg


invoke ActivateKeyboardLayout,HKL_NEXT,0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
invoke ActivateKeyboardLayout,0419h,0 - RUS
invoke ActivateKeyboardLayout,0409h,0 - ENG

Title: Re: non-english windows clipboard problem
Post by: TimoVJL on February 12, 2022, 08:26:41 PM
Win32 have function MultiByteToWideChar(CP_UTF8, 0, ... and WideCharToMultiByte(CP_UTF8, 0, .. for UTF-8 strings.
Web pages are mostly UTF-8 and also MS help files.


EDIT:
The sad history of Unicode printf-style format specifiers in Visual C++ (https://devblogs.microsoft.com/oldnewthing/20190830-00/?p=102823)

Free Clipboard Viewer (https://freeclipboardviewer.com/)
Title: Re: non-english windows clipboard problem
Post by: jj2007 on February 12, 2022, 08:59:47 PM
Quote from: TimoVJL on February 12, 2022, 08:26:41 PM
Win32 have function MultiByteToWideChar(CP_UTF8, 0, ... and WideCharToMultiByte(CP_UTF8, 0, .. for UTF-8 strings.
Web pages are mostly UTF-8 and also MS help files.

Even Explorer, it seems (except in Norway). On the surface, at least - under the hood, it's surely UTF-16.
Title: Re: non-english windows clipboard problem
Post by: bomz on February 12, 2022, 09:39:14 PM
invoke GetClipboardData,CF_UNICODETEXT
invoke MessageBoxW,0,eax,addr mestitle,MB_ICONASTERISK
Title: Re: non-english windows clipboard problem
Post by: jj2007 on February 13, 2022, 06:03:19 AM
include \masm32\MasmBasic\MasmBasic.inc         ; download (http://masm32.com/board/index.php?topic=94.0)
$Data 你在胡说八道,我的朋友!
$Data Mluvíš nesmysly, příteli!
$Data Вы говорите глупости, мой друг!
$Data أنت تتحدث عن هراء يا صديقي!
$Data אתה מדבר שטויות, ידידי!
$Data あなたはナンセンスを話している、私の友人!
  Init
  Read my$()
  wMsgBox 0, wRec$(Join$(my$())), "Windows works fine everywhere in the World", MB_OK
EndOfCode


And guess what, friend from Norway, it doesn't even need MasmBasic - see attachment PureMasm32SDK :tongue:
Title: Re: non-english windows clipboard problem
Post by: hutch-- on February 13, 2022, 08:23:44 AM
I honestly don't know what the big deal is here, Windows has supported UNICODE since 1994 in NT4 and with UNICODE fonts, you can produce just about any language on the planet. Natural languages that can be represented with single byte character sets can use the old code page system but it was a pain to use where UNICODE easily handled entirely different language and character formats, Chinese, Japanese, Georgian, Russian etc .....

I am lazy in that as an English speaker, ASCII does the job in most instances where UNICODE requires storing string data in a different manner.
Title: Re: non-english windows clipboard problem
Post by: TimoVJL on February 13, 2022, 08:39:00 AM
Windows NT was born from start with UNICODE, like Windows NT 3.1
Title: Re: non-english windows clipboard problem
Post by: bomz on February 13, 2022, 02:46:14 PM
 :cool:
Title: Re: non-english windows clipboard problem
Post by: Greenhorn on February 13, 2022, 07:38:54 PM
Since NT, Windows is internally using Unicode only (since Windows 2000 this is UTF-16). All the ASCII functions of the win32 API are just Wrappers which allocate additional memory to convert the ASCII string and then call the Unicode version of the function and vice versa. They do only exist because of compatibility reasons with old applications.

"New applications"(sic!) should use Unicode in general.
Title: Re: non-english windows clipboard problem
Post by: six_L on February 14, 2022, 05:06:56 AM
Hi,bomz
the OS(non ansi) uses unicode API defaultly.
or use
LOCAL ansiBuf[2048]:BYTE

invoke OpenClipboard,NULL
invoke GetClipboardData,CF_UNICODETEXT ;CF_TEXT
mov hClipdata,rax
invoke GlobalLock,hClipdata
mov lpStr,rax
invoke SetDlgItemTextW,hWnd,IDC_OUTPUT2,lpStr
invoke RtlZeroMemory,addr ansiBuf,sizeof ansiBuf
invoke WideCharToMultiByte,CP_ACP,0,lpStr,-1,addr ansiBuf,2048,NULL,NULL
invoke SetDlgItemTextA,hWnd,IDC_OUTPUT1,addr ansiBuf
invoke GlobalUnlock,hClipdata
invoke EmptyClipboard
invoke CloseClipboard

Title: Re: non-english windows clipboard problem
Post by: bomz on February 14, 2022, 07:16:13 AM
invoke ActivateKeyboardLayout,0419h,0
interesting how use cf-text and cf_oemtext for input
Title: Re: non-english windows clipboard problem
Post by: bomz on February 15, 2022, 03:51:25 AM
can anybody say how works cf-locale?
;invoke ActivateKeyboardLayout,0419h,0
invoke OpenClipboard,NULL
;invoke GetClipboardData,CF_LOCALE
;invoke MessageBox,0,eax,0,MB_ICONASTERISK
;invoke wsprintf,ADDR buffer,ADDR form,dword ptr[eax]
;invoke MessageBox,0,ADDR buffer,ADDR mestitle,MB_ICONASTERISK
invoke SetClipboardData, CF_LOCALE, 0419h
invoke GetClipboardData,CF_OEMTEXT
invoke MessageBox,0,eax,0,MB_ICONASTERISK
invoke CloseClipboard
invoke ExitProcess,0
Title: Re: non-english windows clipboard problem
Post by: Greenhorn on February 15, 2022, 03:55:33 AM
Forget about CF_LOCAL, instead use CF_UNICODE and your problems fade away.
Title: Re: non-english windows clipboard problem
Post by: nidud on February 15, 2022, 05:15:11 AM
deleted
Title: Re: non-english windows clipboard problem
Post by: TimoVJL on February 15, 2022, 05:24:02 AM
Using Free Clipboard Viewer someone could look what formats are already there, if someone copy something from another application.
Title: Re: non-english windows clipboard problem
Post by: nidud on February 15, 2022, 05:38:50 AM
deleted
Title: Re: non-english windows clipboard problem
Post by: bomz on February 15, 2022, 06:20:40 AM
invoke OpenClipboard,NULL
invoke GetUserDefaultLCID
invoke SetClipboardData, CF_LOCALE, eax
invoke GetClipboardData,CF_UNICODETEXT
invoke MessageBoxW,0,eax,0,MB_ICONASTERISK
invoke CloseClipboard
invoke ExitProcess,0
Title: Re: non-english windows clipboard problem
Post by: nidud on February 24, 2022, 09:42:10 AM
deleted
Title: Re: non-english windows clipboard problem
Post by: jj2007 on February 24, 2022, 11:42:10 AM
deleted
Title: Re: non-english windows clipboard problem
Post by: nidud on February 24, 2022, 01:44:00 PM
deleted
Title: Re: non-english windows clipboard problem
Post by: hutch-- on February 24, 2022, 02:33:45 PM
Guys,

can we keep this squabling out of the campus ?
Title: Re: non-english windows clipboard problem
Post by: nidud on February 24, 2022, 03:08:49 PM
I did ask to keep the squabling out of the campus.