News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Stretchblt and unicode

Started by clamicun, May 18, 2017, 07:42:43 AM

Previous topic - Next topic

clamicun

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

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
Creative coders use backward thinking techniques as a strategy.

jj2007

As a macro: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

Ahhh, it's from masm32rt.inc  :biggrin:

I should have a look into that file...
Creative coders use backward thinking techniques as a strategy.

jj2007

Sure? I can't find UnicodeStr in masm32rt.inc or m32lib ::)

Siekmanski

Me neither, I just looked at his code. ( I have to go to sleep, I can't read posts that well anymore  :icon_redface: )
Creative coders use backward thinking techniques as a strategy.

jj2007

There is a suite of pretty useless functions, e.g. RtlAnsiStringToUnicodeString

aw27

Quote from: jj2007 on May 18, 2017, 09:13:45 AM
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

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

My mistake, I didn't spot the "UnicodeStr" routine in your source code.
Creative coders use backward thinking techniques as a strategy.

clamicun

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

Here is the zip
Don't know where I found it, but in this forum somewhere


jj2007

Quote from: clamicun on May 19, 2017, 12:45:49 AMnot 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

jj,
of course I was referring to MS when I used the expression "highest trust"   

jj2007

Quote from: clamicun on May 19, 2017, 12:55:27 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.