[11-22] masm32 programming to obtain the file language and version information v3

Source: Internet
Author: User
; <<
; Filename: verinfo3.asm
; Function: Demo the way to get file's version information and language
; Author: Purple endurer
;
; Log
; Timeout ;----------------------------------------------------------------------------------------
; 2006-11-22 can display in CN
; 2006-11-20 added comments!
; 2006-09-14 created!
; <<

. 386
. Model flat, stdcall
Option Casemap: None
Include/masm32/include/Windows. inc

Include/masm32/include/kernel32.inc
Includelib/masm32/lib/kernel32.lib
Include/masm32/include/user32.inc
Includelib/masm32/lib/user32.lib
Include/masm32/include/shell32.inc
Includelib/masm32/lib/shell32.lib
Include/masm32/include/comdlg32.inc
Includelib/masm32/lib/comdlg32.lib
Include/masm32/include/version. inc
Includelib/masm32/lib/version. Lib

Winmain proto: DWORD,: DWORD
Resizeconctrol proto
Showverinfo proto: lpstr
Btnshow_click proto
Btnbrowse_click proto

;. Const
Idc_btnbrowse equ 101
Idc_btnshow equ 103
Idc_edtfilespec equ 105
Idc_edtverinfo equ 107
C_buflen equ max_path

C_editfilespecleft equ 2
C_editfilespectop equ 5
C_editfilespecwidth equ 300
C_editfilespecheight equ 20

C_btnbrowsetop equ c_editfilespectop
C_btnbrowseleft equ (c_editfilespecleft + c_editfilespecwidth + 10)
C_btnbrowsewidth equ 70
C_btnbrowseheight equ c_editfilespecheight

C_btnshowtop equ c_editfilespectop
C_btnshowleft equ (c_btnbrowseleft + c_btnbrowsewidth + 10)
C_btnshowwidth equ 70
C_btnshowheight equ c_btnbrowseheight

C_edtverinfoleft equ 2
C_edtverinfotop equ 30
C_edtverinfowidth equ c_btnshowleft + c_btnshowwidth + 2
C_edtverinfoheight equ165

C_winwidth equ c_edtverinfoleft + c_edtverinfowidth + 10
C_winheight equ c_edtverinfotop + c_edtverinfoheight + 30

M_catstr macro szstr: req
Invoke sendmessage, g_heditverinfo, em_replacesel, false, ADDR szstr
Endm

M_gonextline macro
Invoke sendmessage, g_heditverinfo, em_replacesel, false, ADDR g_szcr
Endm

. Data
G_szclsname DB "fileverinfocls", 0
G_szappname DB "file version information", 0
G_szeditcls DB "edit", 0
G_szbtncls DB "button", 0
G_szbtnbrowsetext DB "& B ", 0
G_szbtnshowtext DB "& S display", 0
G_szenterfileerr DB "Enter the file description first", 0
G_szfailgetversize DB "An error occurred while obtaining the file version information! ", 0
G_szfailallocmem DB "memory application failed! ", 0
G_szfailgetverinfo DB "An error occurred while obtaining the file version information! ", 0
G_szfailfailgetlangpage DB "An error occurred while obtaining the language and code page! ", 0
G_szcr dB 0dh, 0ah, 0
G_szop DB "properties", 0
G_szpefilefilter DB "*. EXE; *. dll", 0, "*. EXE; *. dll", 0, 0

. Data?
G_hinstance hinstance?
G_hwndmain handle?
G_heditfilespec handle?
G_hbtnshow handle?
G_hbtnbrowse handle?
G_heditverinfo handle?
G_szfilespec dB c_buflen DUP (?)
G_ofn openfilename <?>
G_shlexecinfo shellexecuteinfo <?>

. Code
Start:
Invoke getmodulehandle, null
MoV g_hinstance, eax
Invoke winmain, g_hinstance, null, null, sw_showdefault
Invoke exitprocess, eax

Winmain proc hinst: DWORD, hprevinst: DWORD, cmdline: DWORD, cmdshow: DWORD
Local WC: wndclassex
Local MSG: msg
Local hwnd: hwnd

MoV WC. cbsize, sizeof wndclassex
MoV WC. style, cs_hredraw or cs_vredraw
MoV WC. lpfnwndproc, offset wndproc
MoV WC. cbclsextra, null
MoV WC. cbwndextra, null
MoV eax, g_hinstance
MoV WC. hinstance, eax
MoV WC. hbrbackground, color_appworkspace
MoV WC. lpszmenuname, null
MoV WC. lpszclassname, offset g_szclsname
Invoke loadicon, null, idi_application
MoV WC. hicon, eax
MoV WC. hiconsm, eax
Invoke loadcursor, null, idc_arrow
MoV WC. hcursor, eax
Invoke registerclassex, ADDR WC
Invoke createappswex, ws_ex_topmost, ADDR g_szclsname ,/
ADDR g_szappname, ws_overlappedwindow + ws_visible ,/
Cw_usedefault, cw_usedefault, c_winwidth, c_winheight ,/
Null, null, hinst, null
MoV hwnd, eax
. While true
Invoke getmessage, addr msg, null, 0, 0
. Break. If (! Eax)

; --- Process keystrokes directly in the message loop
. If MSG. Message = wm_syskeyup
. If msg. wparam = vk_ B; Alt + B
Invoke postmessage, hwnd, wm_command, idc_btnbrowse, bm_click
. Elseif msg. wparam = vk_s; Alt + S
Invoke postmessage, hwnd, wm_command, idc_btnshow, bm_click
. Endif
. Endif
;------------------------------------------------
Invoke translatemessage, ADDR msg
Invoke dispatchmessage, ADDR msg
. Endw
MoV eax, MSG. wparam
RET
Winmain endp

Wndproc proc hwnd: hwnd, umsg: uint, wparam: wparam, lparam: lparam
Local rect: rect
Local HDC: DWORD

. If umsg = wm_create
MoV eax, hwnd
MoV g_hwndmain, eax

; --- Create file spec editbox
Invoke createmediawex, null, offset g_szeditcls, null,
Ws_child + ws_visible + es_autohscroll + ws_border ,/
C_editfilespecleft, c_editfilespectop, c_editfilespecwidth, c_editfilespecheight ,/
Hwnd, idc_edtfilespec, g_hinstance, null
MoV g_heditfilespec, eax

; --- Create Browse button
Invoke createcontactwex, null, offset g_szbtncls, offset g_szbtnbrowsetext ,/
Ws_child + ws_visible, c_btnbrowseleft, c_btnbrowsetop, c_btnbrowsewidth, c_btnbrowseheight ,/
Hwnd, idc_btnbrowse, g_hinstance, null
MoV g_hbtnbrowse, eax

; --- Create Show button
Invoke createjavaswex, null, offset g_szbtncls, offset g_szbtnshowtext ,/
Ws_child + ws_visible, c_btnshowleft, c_btnshowtop, c_btnshowwidth, c_btnshowheight ,/
G_hwndmain, idc_btnshow, g_hinstance, null
MoV g_hbtnshow, eax

; --- Create file ver info editbox
Invoke createappswex, null, ADDR g_szeditcls, null ,/
Ws_child + ws_visible + es_multiline + ws_hscroll + ws_vscroll + ws_border ,/
C_edtverinfoleft, c_edtverinfotop, c_edtverinfowidth, c_edtverinfoheight ,/
G_hwndmain, idc_edtverinfo, g_hinstance, null
MoV g_heditverinfo, eax

; --- Initialize openfilename Structure
Invoke rtlzeromemory, offset g_ofn, sizeof g_ofn
MoV g_ofn.lstructsize, sizeof openfilename
MoV eax, g_hinstance
MoV g_ofn.hinstance, eax
MoV g_ofn.nmaxfile, c_buflen
MoV g_ofn.flags, ofn_hidereadonly + ofn_filemustexist + ofn_pathmustexist + ofn_explorer
MoV g_ofn.lpstrfilter, offset g_szpefilefilter
MoV g_ofn.lpstrfile, offset g_szfilespec
MoV eax, g_hwndmain
MoV g_ofn.hwndowner, eax

; --- Initialize shellexecuteinfo Structure
Invoke rtlzeromemory, offset g_shlexecinfo, sizeof shellexecuteinfo
MoV g_shlexecinfo.cbsize, sizeof g_shlexecinfo
MoV g_shlexecinfo.fmask, see_mask_invokeidlist
MoV g_shlexecinfo.lpverb, offset g_szop
MoV g_shlexecinfo.lpfile, offset g_szfilespec

. Elseif umsg = wm_command
. If lparam
MoV edX, wparam
MoV eax, EDX
SHR edX, 16
. If dx = bn_clicked
. If AX = idc_btnshow
Invoke btnshow_click
. Else
Invoke btnbrowse_click
. Endif
. Endif
. Endif
. Elseif umsg = wm_destroy
Invoke postquitmessage, null
. Elseif umsg = wm_size
Invoke resizeconctrol
XOR eax, eax
JZ @ F
. Else
@@:
Invoke defwindowproc, hwnd, umsg, wparam, lparam
RET
. Endif
XOR eax, eax
RET
Wndproc endp

Btnshow_click proc
Invoke getwindowtext, g_heditfilespec, ADDR g_szfilespec, sizeof g_szfilespec
. If eax = 0
Invoke MessageBox, g_hwndmain, offset g_szenterfileerr, offset g_szappname, mb_iconerror + mb_ OK
. Else
; --- Clear the file ver info box
Invoke sendmessage, g_heditverinfo, wm_settext, 0, null
Invoke showverinfo, offset g_szfilespec
. If eax> 0
. If eax = 1
MoV eax, offset g_szfailgetversize
. Elseif eax = 2
MoV eax, offset g_szfailallocmem
. Elseif eax = 3
MoV eax, offset g_szfailgetverinfo
. Elseif eax = 4
MoV eax, offset g_szfailfailgetlangpage
. Endif
Invoke MessageBox, g_hwndmain, eax, offset g_szappname, mb_iconerror + mb_ OK
. Else
Invoke shellexecuteex, offset g_shlexecinfo
. Endif
. Endif
RET
Btnshow_click endp

Btnbrowse_click proc
Invoke getopenfilename, ADDR g_ofn
. If eax! = 0
Invoke sendmessage, g_heditfilespec, wm_settext, 0, offset g_szfilespec
. Endif
RET
Btnbrowse_click endp

Resizeconctrol proc
Local st_rect: rect

Invoke getclientrect, g_hwndmain, ADDR st_rect

; --- Resize the Show button
MoV eax, st_rect.right
Sub eax, 5 + c_btnshowwidth
Push eax
Invoke movewindow, g_hbtnshow, eax, c_btnshowtop, c_btnshowwidth, c_btnshowheight, true

; --- Resize the Show button
Pop eax
Sub eax, 5 + c_btnshowwidth
Push eax
Invoke movewindow, g_hbtnbrowse, eax, c_btnbrowsetop, c_btnbrowsewidth, c_btnbrowseheight, true

; --- Resize the file spec editbox
Pop eax
Sub eax, 10
Invoke movewindow, g_heditfilespec, c_editfilespecleft, c_editfilespectop, eax, c_editfilespecheight, true

; --- Resize the ver info editbox
MoV eax, st_rect.right
Sub eax, 5

MoV EDI, st_rect.bottom
Sub EDI, 30

Invoke movewindow, g_heditverinfo, c_edtverinfoleft, c_edtverinfotop, eax, EDI, true

RET
Resizeconctrol endp

;/////////////////////////////////
; Result:
; Eax = 0 sucess
; Eax = 1 fail to get file ver info size
; Eax = 2 fail to alloc global memory
; Eax = 3 fail to get file ver info
; Eax = 4 fail to get the language ID and code page
;/////////////////////////////////
Showverinfo proc lpszfilespec: lpstr
Local dwbufsize: DWORD
Local hmem: handle
Local binfostr [max_path]: byte
Local lpszvalue: lpstr
Local blangcharset [9]: byte

Invoke getfileversioninfosize, lpszfilespec, ADDR dwbufsize
Or eax, eax
Jnz @ F
MoV eax, 1
RET
@@:
MoV dwbufsize, eax
Invoke globalalloc, gmem_zeroinit, eax
CMP eax, null
Jnz @ F
MoV eax, 2
RET
@@:
MoV hmem, eax
; Bool getfileversioninfo (
; Lptstr lptstrfilename, // pointer to filename string
; DWORD dwhandle, // ignored
; DWORD dwlen, // size of Buffer
; Lpvoid lpdata // pointer to buffer to receive file-version info.
;);
 
Invoke getfileversioninfo, lpszfilespec, 0, dwbufsize, hmem
Or eax, eax
Jnz @ F
Invoke globalfree, hmem
MoV eax, 3
RET
G_sztranslation DB "/varfileinfo/translation", 0
@@:
; Bool verqueryvalue (
; Const lpvoid pblock, // address of buffer for version Resource
; Lptstr lpsubblock, // address of value to retrieve
; Lpvoid * lplpbuffer, // address of buffer for version pointer
; Puint pulen // address of version-value Length Buffer
;);

Invoke verqueryvalue, hmem, offset g_sztranslation, ADDR lpszvalue, ADDR dwbufsize
Or eax, eax
Jnz @ F
Invoke globalfree, hmem
MoV eax, 4
RET
G_szproductname dB 'productname ', 0
G_szproductversion dB 'productversion', 0
G_szfiledescription dB 'filedescription', 0
G_szlegalcopyright dB 'galcopyright', 0
G_szfileversion dB 'fileversion', 0
G_szcompanyname dB 'companyname', 0
G_szlegaltrademarks dB 'legaltrademarks ', 0
G_szinternalname dB 'internalname', 0
G_szoriginalfilename dB 'ininalfilename', 0
G_szcomments DB "Comments", 0

G_lpszinfo label DWORD
DWORD offset g_szfileversion
DWORD offset g_szfiledescription
DWORD offset g_szlegalcopyright
DWORD offset g_szcomments
DWORD offset g_szproductversion
DWORD offset g_szproductname
DWORD offset g_szcompanyname
DWORD offset g_szlegaltrademarks
DWORD offset g_szinternalname
DWORD offset g_szoriginalfilename
C_lpszinfolen equ ($-g_lpszinfo)/4

C_1_age_cn equ 1
If c_1_age_cn EQ 1
G_szproductname_cn dB 'product name', 0
G_szproductversion_cn dB 'product version', 0
G_szfiledescription_cn dB 'description', 0
G_szlegalcopyright_cn dB 'copyright ', 0
G_szfileversion_cn dB 'file version', 0
G_szcompanyname_cn dB 'Company name', 0
G_szlegaltrademarks_cn dB 'legal trademark ', 0
G_szinternalname_cn dB 'internal name', 0
G_szoriginalfilename_cn dB 'source file name', 0
G_szcomments_cn DB "Remarks", 0

G_lpszinfo_cn label DWORD
DWORD offset g_szfileversion_cn
DWORD offset g_szfiledescription_cn
DWORD offset g_szlegalcopyright_cn
DWORD offset g_szcomments_cn
DWORD offset g_szproductversion_cn
DWORD offset g_szproductname_cn
DWORD offset g_szcompanyname_cn
DWORD offset g_szlegaltrademarks_cn
DWORD offset g_szinternalname_cn
DWORD offset g_szoriginalfilename_cn
C_lpszinfo_cn_len equ ($-g_lpszinfo_cn)/4
G_szlang_cn DB "language"
G_szblkcolonblk DB ":", 0
Else
G_szlang DB "langeage"
G_szblkcolonblk DB ":", 0
Endif
G_szpre dB 'stringfileinfo/', 0; 080404b0
G_szinfofmt DB "% S/% s", 0
G_szhexfmt DB "% 08x", 0

@@:
; --- Now, lpszvalue is a pointer to four 4 bytes of hex number,
; First two bytes are language ID, and last two bytes are code page.
; However, lang_charset_string needs a string of 4 hex digits,
; The first two characters correspond to the language ID
; And last two the last two character correspond to the code page ID.

If c_1_age_cn EQ 1
M_catstr g_szlang_cn
Else
M_catstr g_szlang
Endif
MoV eax, lpszvalue
MoV eax, [eax]
Push eax

; --- Get the description string
; DWORD verlanguagename (
; DWORD wlang, // Microsoft language identifier
; Lptstr szlang, // pointer to buffer for language description string
; DWORD nsize // size of Buffer
;);
Movzx eax, ax
MoV dwbufsize, eax
Invoke verlanguagename, dwbufsize, ADDR binfostr, max_path
Or eax, eax
JZ @ F
M_catstr binfostr
@@:
M_gonextline
Pop eax

; --- Change the order of the language ID and code page
Rol eax, 16

; --- Convert the language ID and code page into a 8 bytes hex string representation
Invoke wsprintf, ADDR blangcharset, ADDR g_szhexfmt, eax

; --- For example, the language ID and code page may look like 040904e4
; Or to pull it all apart:
; 04 ------ = sublang_english_usa
; -- 09 ---- = lang_english
; ---- 04e4 = 1252 = codePage for Windows: Multilingual

C_showtranslation equ 0
If c_showtranslation EQ 1
; --- Show the language ID and code page in editbox
M_catstr g_sztranslation

M_catstr g_szblkcolonblk
M_catstr blangcharset
M_gonextline
Endif

XOR eax, eax
. While eax <c_lpszinfolen
Push eax
Or eax, eax
JZ @ F
SHL eax, 2; eax <-- eax * 4
@@:
Push eax

If c_1_age_cn EQ 1
Invoke sendmessage, g_heditverinfo, em_replacesel, false, [eax + g_lpszinfo_cn]
Else
Invoke sendmessage, g_heditverinfo, em_replacesel, false, [eax + g_lpszinfo]
Endif

M_catstr g_szblkcolonblk
Pop eax
Invoke wsprintf, ADDR binfostr, ADDR g_szinfofmt, offset g_szpre, ADDR blangcharset, [eax + g_lpszinfo]
Invoke verqueryvalue, hmem, ADDR binfostr, ADDR lpszvalue, ADDR dwbufsize
Or eax, eax
JZ @ F
Invoke sendmessage, g_heditverinfo, em_replacesel, false, lpszvalue
@@:
M_gonextline
Pop eax
INC eax
. Endw
Invoke globalfree, hmem
XOR eax, eax
RET
Showverinfo endp

End start

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.