Author Topic: Stretchblt and unicode  (Read 573 times)

clamicun

  • Member
  • **
  • Posts: 240
Stretchblt and unicode
« on: May 18, 2017, 07:42:43 AM »
I am playing with a prog which displays "mini images" - made from a file.jpg
When you click on the mini the originalsized jpg opens.
I made it out of various examples for bitblt and stretchblt.
Works fine.

Only problem is that I absolutely don't understand what the proc "UnicodeStr" is doing and
I hate not understanding part of my program.
Could someone give me information on this proc,please ?


.IF uMsg==WM_CREATE
mov     eax,OFFSET StartupInfo
mov     GdiplusStartupInput.GdiplusVersion[eax],1
INVOKE  GdiplusStartup,ADDR token,ADDR StartupInfo,0
INVOKE  UnicodeStr,ADDR image_name,ADDR UnicodeFileName               ;ascii to unicode I suppose
INVOKE  GdipCreateBitmapFromFile,ADDR UnicodeFileName,ADDR BmpImage
INVOKE  GdipCreateHBITMAPFromBitmap,BmpImage,ADDR hBitmap,0

;BITMAP.bmWidth[edx]   height and width of the selected picture
;BITMAP.bmHeight[edx]


.ELSEIF uMsg==WM_PAINT
INVOKE  BeginPaint,hWnd,ADDR ps
mov     hdc,eax
INVOKE  CreateCompatibleDC,hdc
mov     hMemDC,eax
INVOKE  SelectObject,eax,hBitmap
INVOKE  GetObject,hBitmap,sizeof(BITMAP),ADDR bm
lea     edx,bm

mov     eax,iCurrentMode
INVOKE  SetStretchBltMode,hdc,eax
INVOKE StretchBlt,hdc,460,235,150,113,hMemDC,0,0,BITMAP.bmWidth[edx],BITMAP.bmHeight[edx],SRCCOPY
;150 x 113 is provisorial - works only with pictures in 4 x 3 relation 800x600  1024x68   3648x236
           
INVOKE  DeleteDC,hMemDC
INVOKE  EndPaint,hWnd,ADDR ps

;====================
;Changes the ascii image stringto a unicode string I suppose
UnicodeStr  PROC USES esi ebx Source:DWORD,Dest:DWORD

    mov     ebx,1
    mov     esi,Source
    mov     edx,Dest
    xor      eax,eax
    sub      eax,ebx     ; ?? eax is -1 in any case this moment
     
    @@:
    add     eax,ebx     ; I don't see that ebx has changed
       
    movzx   ecx,BYTE PTR [esi+eax]   ;??
    mov     WORD PTR [edx+eax*2],cx  ;??
    test    ecx,ecx
    jnz     @b
   
ret

UnicodeStr  ENDP
;====================
   

Siekmanski

  • Member
  • *****
  • Posts: 1089
Re: Stretchblt and unicode
« Reply #1 on: May 18, 2017, 08:04:43 AM »
I have never heard of the UnicodeStr function ?
But you can replace it with "MultiByteToWideChar", below is a link to msdn

.data?
UnicodeFileName           dw  MAX_PATH dup (?)

.data
imagestring db "beautiful.jpg",0

.code
; skip this line:
    INVOKE  UnicodeStr,ADDR image_name,ADDR UnicodeFileName               ;ascii to unicode I suppose
; replace it by this line:
    invoke  MultiByteToWideChar,CP_ACP,0,ADDR imagestring,-1,ADDR UnicodeFileName,MAX_PATH-1

    invoke  GdipCreateBitmapFromFile,ADDR UnicodeFileName,ADDR BmpImage

https://msdn.microsoft.com/en-us/library/windows/desktop/dd319072(v=vs.85).aspx

jj2007

  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
Re: Stretchblt and unicode
« Reply #2 on: May 18, 2017, 08:15:23 AM »
As a macro:
Code: [Select]
include \masm32\include\masm32rt.inc

.data
txImageAnsi db "SomeImage.jpg", 0
txTitle dw "H", "E", "L", "L", "O", 0 ; the clumsy way of defining a Unicode string

.data?
txImageUnicode dw sizeof txImageAnsi dup(?)

UnicodeString MACRO ansiArg, ucArg
  pushad
  mov esi, ansiArg
  mov edi, ucArg
  xor eax, eax
  .Repeat
lodsb
stosw
  .Until !eax
  popad
  EXITM <ucArg>
ENDM

.code
start:
invoke MessageBoxW, 0, UnicodeString(offset txImageAnsi, offset txImageUnicode), offset txTitle, MB_OK
  exit

end start

Insert an int 3 after mov edi, ucArg to see in Olly how it works. I have written that macro from scratch, but this is basically how wChr$() works. No rocket science, just a simple lodsb+stosw algo.

Siekmanski

  • Member
  • *****
  • Posts: 1089
Re: Stretchblt and unicode
« Reply #3 on: May 18, 2017, 08:20:00 AM »
Ahhh, it's from masm32rt.inc  :biggrin:

I should have a look into that file...

jj2007

  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
Re: Stretchblt and unicode
« Reply #4 on: May 18, 2017, 08:29:13 AM »
Sure? I can't find UnicodeStr in masm32rt.inc or m32lib ::)

Siekmanski

  • Member
  • *****
  • Posts: 1089
Re: Stretchblt and unicode
« Reply #5 on: May 18, 2017, 08:35:51 AM »
Me neither, I just looked at his code. ( I have to go to sleep, I can't read posts that well anymore  :icon_redface: )

jj2007

  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
Re: Stretchblt and unicode
« Reply #6 on: May 18, 2017, 09:13:45 AM »
There is a suite of pretty useless functions, e.g. RtlAnsiStringToUnicodeString

aw27

  • Member
  • ****
  • Posts: 697
Re: Stretchblt and unicode
« Reply #7 on: May 18, 2017, 12:05:03 PM »
There is a suite of pretty useless functions, e.g. RtlAnsiStringToUnicodeString
This is for another thing called "Unicode_String" which is not the same as Unicode UTF16 Strings which are encoded by double bytes  (WCHAR). :icon_rolleyes:

The problem with the UnicodeStr from clamicum as well with the UnicodeString macro is that they only work reliably for converting 7-bit ASCII characters. :icon_rolleyes:

clamicun

  • Member
  • **
  • Posts: 240
Re: Stretchblt and unicode
« Reply #8 on: May 19, 2017, 12:12:38 AM »
btw.
UnicodeStr isn't a Windows function
It is declared together with the others you need (WinMain and more)
 
UnicodeStr  PROTO :DWORD,:DWORD

Downloaded from this forum  "GdipCreateBitmapFromFile.zip"

Thanks, I check out the  possibilities

Siekmanski

  • Member
  • *****
  • Posts: 1089
Re: Stretchblt and unicode
« Reply #9 on: May 19, 2017, 12:32:23 AM »
My mistake, I didn't spot the "UnicodeStr" routine in your source code.

clamicun

  • Member
  • **
  • Posts: 240
Re: Stretchblt and unicode
« Reply #10 on: May 19, 2017, 12:45:49 AM »
Siekmanski,

yes
invoke  MultiByteToWideChar,CP_ACP,0,ADDR image_name,-1,ADDR UnicodeFileName,MAX_PATH-1
works

The buffer for the unicodename has to be at least twice the size of len image_name

So, of course I don't understand the "MultiBytetoWideChar function" , but it is MS (and not some unknown programmer) and we all have the hightest trust into its functions ...

clamicun

  • Member
  • **
  • Posts: 240
Re: Stretchblt and unicode
« Reply #11 on: May 19, 2017, 12:55:27 AM »
Here is the zip
Don't know where I found it, but in this forum somewhere

 

jj2007

  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
Re: Stretchblt and unicode
« Reply #12 on: May 19, 2017, 02:01:51 AM »
not some unknown programmer) and we all have the hightest trust into its functions ...

The unknown programmer is most probably Erol (and I have the highest trust into his functions :P)

clamicun

  • Member
  • **
  • Posts: 240
Re: Stretchblt and unicode
« Reply #13 on: May 20, 2017, 07:19:18 AM »
jj,
of course I was referring to MS when I used the expression "highest trust"   

jj2007

  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
Re: Stretchblt and unicode
« Reply #14 on: May 20, 2017, 08:03:00 AM »
Here is the zip
Don't know where I found it, but in this forum somewhere

UnicodeStr.asm is in the attachment to the post where the Erol link above points to.