Hi all, I recently got Windows 7, I wrote a program to create and display an empty window I used the include32.lib. the program compiles but when I try run it I get an error that says its not a valid win32 program, it Won't run in the "virtual pc" is there a chance it could be the functions in the include32, is there a fix
11 replies to this topic
#1
Posted 11 June 2011 - 02:09 PM
|
|
|
#2
Posted 11 June 2011 - 03:53 PM
Sure there is a fix... BUT, we are not psychics :P Post your code... Wait.... are you trying to use interupts? 16bit code? if so, DOS programs won't run on Win7 AFAIK... if not, just post your code.
#3
Posted 12 June 2011 - 01:40 AM
ok well, when i try run my program it shows the error then says 'access dienied' in the cmd( hope my english is ok :lol: )
here is the code( be warned it's long ) and like i said it compile ok..i recently started window programming in assembly, but i fully understand assembly itself and window programing in C so i understand wots happeing in the code( at least hope i do )
here is the code( be warned it's long ) and like i said it compile ok..i recently started window programming in assembly, but i fully understand assembly itself and window programing in C so i understand wots happeing in the code( at least hope i do )
.586p .model flat, stdcall ;----------------------------------------------------------------------------------------- ;constants ;----------------------------------------------------------------------------------------- WM_DESTROY equ 2 ;message arrives when window is closed WM_CREATE equ 1 ;message arrives when the window is created WM_LBUTTONDOWN equ 201h ;message when left-clicked the mouse in the window area WM_RBUTTONDOWN equ 204h ;message when right clicking the mouse in the window area ;------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------ ;window properties ;------------------------------------------------------------------------------------------ CS_VREDRAW equ 1h CS_HREDRAW equ 2h CS_GLOBALCLASS equ 4000h WS_OVERLAPPEDWINDOW equ 000cf0000h style equ CS_HREDRAW + CS_HREDRAW + CS_GLOBALCLASS IDI_APPLICATION equ 32512 ;identifier of the standard icon IDC_CROSS equ 32515 ;cursor identifier SW_SHOWNORMAL equ 1 ;normal display mode ;-------------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------------- ;prototypes of external functions ;-------------------------------------------------------------------------------------------- extern MessageBoxA : near extern CreateWindowExA : near extern DefWindowProcA : near extern DispatchMessageA : near extern ExitProcess : near extern GetMessageA : near extern GetModuleHandleA : near extern LoadCursorA : near extern LoadIconA : near extern PostQuitMessage : near extern RegisterClassA : near extern ShowWindow : near extern TranslateMessage : near extern UpdateWindow : near includelib import32.lib ;instruction to linker to link libraries ;---------------------------------------------------------------------------------------------- ;---------------------------------------------------------------------------------------------- ;structures ;---------------------------------------------------------------------------------------------- ;message structure MSGSTRUCT struct MSHWND dd ? ;identifier of the window that recieved the message MSMESSAGE dd ? ;message identifier MSWPARAM dd ? ;auxiliary information about the message MSLPARAM dd ? ;auxiliary information about the message MSTIME dd ? ;time when the message was sent MSPT dd ? ;cursor position at the time of sending the message MSGSTRUCT ends ;window class structure WNDCLASS struct CLSSTYLE dd ? ;wondow style CLWNDPROC dd ? ;pointer to the window structure CLSCSEXTRA dd ? ;info on the auxiliary bytes for this structure CLWNDEXTRA dd ? ;info on the auxiliary bytes for the window CLSHINSTANCE dd ? ;application descriptor CLSHICON dd ? ;window icon identifier CLBKGROUND dd ? ;window brush identifier CLSHCURSOR dd ? ;window cursor identifier CLMENUNAME dd ? ;menu identifier CLNAME dd ? ;specifies the window class name WNDCLASS ends ;---------------------------------------------------------------------------------------------- ;---------------------------------------------------------------------------------------------- ;data segment ;---------------------------------------------------------------------------------------------- _data segment newhwnd dd 0 msg MSGSTRUCT<?> wc WNDCLASS<?> HINST dd 0 ;application descriptor is stored title_name db 'Window made in assembly', 0 class_name db 'CLASS32', 0 caption db 'message', 0 mes_1 db 'You have clicked the left mouse button', 0 mes_2 db 'Exit. bye', 0 _data ends ;----------------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------------- ;code segment ;------------------------------------------------------------------------------------------------ _code segment start: ;get application descriptor push 0 call GetModuleHandleA mov [HINST], eax ;initialize window structure reg_class: mov [wc.CLSSTYLE], style ;---message-handling procedure----- mov [wc.CLWNDPROC], offset WNDPROC mov [wc.CLSCSEXTRA], 0 mov [wc.CLWNDEXTRA], 0 mov eax, [HINST] mov [wc.CLSHINSTANCE], eax ;-------------------------------- ;--window icon----------------- push IDI_APPLICATION push 0 call LoadIconA mov [wc.CLSHCURSOR], eax ;------------------------------- ;---window cursor--------------- push IDC_CROSS push 0 call LoadCursorA mov [wc.CLSHCURSOR], eax ;-------------------------------- ;---initialize remaining members of WNDCLASS--- mov [wc.CLBKGROUND], 17 ;window color mov dword ptr [wc.CLMENUNAME], 0 mov dword ptr [wc.CLNAME], offset class_name push offset wc call RegisterClassA ;---------------------------------------------- ;---create the window of the registered class--- push 0 push [HINST] push 0 push 0 push 400 ;window height push 400 ;window width push 100 ;co-ordinate of the windows top left corner push 100 ;co-ordinate of the windows top left corner push WS_OVERLAPPEDWINDOW push offset title_name ;window name push offset class_name ;window class push 0 call CreateWindowExA cmp eax, 0 ;check for errors jz _err ;------------------------------------------------------------------------- ;---prepare to show window--- mov [newhwnd], eax push SW_SHOWNORMAL push [newhwnd] call ShowWindow ;show new window push [newhwnd] call UpdateWindow ;redraw the visible part of the window ---> WM_PAINT message ;--------------------------------------------------------------------------------- ;---message handling loop--- msg_loop: push 0 push 0 push 0 push offset msg call GetMessageA cmp eax, 0 je end_loop push offset msg call TranslateMessage push offset msg call DispatchMessageA jmp msg_loop ;unconditional jump end_loop: push [msg.MSWPARAM] call ExitProcess ;exit process _err: jmp end_loop ;--------------------------------------------------------------------------------- ;Window procedure ;---------------------------------------------------------------------------------- ;position of the parameters in the stack ;LPARAM [ebp+14h] ;WAPARAM [ebp + 10h] ;MES [ebp+0ch] ;hwnd [ebp+8] WNDPROC proc ;---preserve current register values push ebp mov ebp, esp push ebx push esi push edi ;determine signal cmp dword ptr [ebp+0ch], WM_DESTROY ; je WMDESTROY cmp dword ptr [ebp+0ch], WM_CREATE je WMCREATE cmp dword ptr [ebp+0ch], WM_LBUTTONDOWN ;left click je LBUTTON cmp dword ptr [ebp+0ch], WM_RBUTTONDOWN ;right click je RBUTTON ;all else fails jump here jmp DEFWNDPROC ;right click closes window RBUTTON: jmp WMDESTROY ;left click displays message LBUTTON: push 0 ;mb_ok push offset caption push offset mes_1 push dword ptr [ebp+08h] ;window descriptor call MessageBoxA mov eax, 0 jmp finish WMCREATE: mov eax, 0 jmp finish DEFWNDPROC: push dword ptr [ebp+14h] push dword ptr [ebp+10h] push dword ptr [ebp+0ch] push dword ptr [ebp+08h] call DefWindowProcA jmp finish WMDESTROY: push 0 ;mb_ok push offset caption push offset mes_2 push dword ptr [ebp+08h] call MessageBoxA push 0 call PostQuitMessage ;WM_QUIT mov eax, 0 finish: pop edi pop esi pop ebx pop ebp ret 16 WNDPROC endp _code ends end start
Edited by Alexander, 12 June 2011 - 04:23 AM.
(bb formatting)
#4
Posted 12 June 2011 - 09:50 AM
This is from TASM\EXAMPLES\WAP32 and modifed with your code.
If you are just starting with Assembly, I suggest you not use manual stack frames (using ebp) and manual pushing of ebp, ebx, esi, edi etc... use proc and uses. Once you learn Asm, you can always use manual stack frames.
Yes I use Win7, I use an IDE so the command lines use are a little different
If you are just starting with Assembly, I suggest you not use manual stack frames (using ebp) and manual pushing of ebp, ebx, esi, edi etc... use proc and uses. Once you learn Asm, you can always use manual stack frames.
Yes I use Win7, I use an IDE so the command lines use are a little different
.386 locals jumps .model flat,STDCALL include TasmTes.inc includelib G:\TASM\LIB\import32.lib L equ <LARGE> extrn CreateWindowExA:PROC extrn DefWindowProcA:PROC extrn DispatchMessageA:PROC extrn ExitProcess:PROC extrn GetMessageA:PROC extrn GetModuleHandleA:PROC extrn LoadCursorA:PROC extrn LoadIconA:PROC extrn MessageBoxA:PROC extrn PostQuitMessage:PROC extrn RegisterClassA:PROC extrn ShowWindow:PROC extrn TranslateMessage:PROC extrn UpdateWindow:PROC CreateWindowEx equ <CreateWindowExA> DefWindowProc equ <DefWindowProcA> DispatchMessage equ <DispatchMessageA> GetMessage equ <GetMessageA> GetModuleHandle equ <GetModuleHandleA> LoadCursor equ <LoadCursorA> LoadIcon equ <LoadIconA> MessageBox equ <MessageBoxA> RegisterClass equ <RegisterClassA> NULL equ 0 .data newhwnd dd 0 msg MSGSTRUCT <?> wc WNDCLASS <?> hInst dd 0 title_name db 'Window made in assembly', 0 class_name db 'CLASS32', 0 caption db 'message', 0 mes_1 db 'You have clicked the left mouse button', 0 szSure DB "Are you sure?", 0 .code start: push L 0 call GetModuleHandle ; get hmod (in eax) mov [hInst], eax ; hInstance is same as HMODULE ; in the Win32 world reg_class: mov [wc.clsStyle], CS_HREDRAW + CS_VREDRAW + CS_GLOBALCLASS mov [wc.clsLpfnWndProc], offset WndProc mov [wc.clsCbClsExtra], 0 mov [wc.clsCbWndExtra], 0 mov eax, [hInst] mov [wc.clsHInstance], eax push L IDI_APPLICATION push L 0 call LoadIcon mov [wc.clsHIcon], eax push L IDC_ARROW push L 0 call LoadCursor mov [wc.clsHCursor], eax mov [wc.clsHbrBackground], COLOR_WINDOW + 1 mov dword ptr [wc.clsLpszMenuName], 0 mov dword ptr [wc.clsLpszClassName], offset class_name push offset wc call RegisterClass push L 0 ; lpParam push [hInst] ; hInstance push L 0 ; menu push L 0 ; parent hwnd push L CW_USEDEFAULT ; height push L CW_USEDEFAULT ; width push L CW_USEDEFAULT ; y push L CW_USEDEFAULT ; x push L WS_OVERLAPPEDWINDOW ; Style push offset title_name ; Title string push offset class_name ; Class name push L 0 ; extra style call CreateWindowEx mov [newhwnd], eax push L SW_SHOWNORMAL push [newhwnd] call ShowWindow push [newhwnd] call UpdateWindow msg_loop: push L 0 push L 0 push L 0 push offset msg call GetMessage cmp ax, 0 je end_loop push offset msg call TranslateMessage push offset msg call DispatchMessage jmp msg_loop end_loop: push [msg.msWPARAM] call ExitProcess WndProc proc uses ebx edi esi, hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD cmp [wmsg], WM_DESTROY je wmdestroy cmp [wmsg], WM_RBUTTONDOWN je wmrbuttondown cmp [wmsg], WM_CREATE je wmcreate cmp [wmsg], WM_LBUTTONDOWN je wmlbuttondown jmp defwndproc wmcreate: xor eax, eax ret defwndproc: push [lparam] push [wparam] push [wmsg] push [hwnd] call DefWindowProc ret wmdestroy: push L 0 call PostQuitMessage xor eax, eax ret wmlbuttondown: push 0 ;mb_ok push offset caption push offset mes_1 push [hwnd] ;window descriptor call MessageBox xor eax, eax ret wmrbuttondown: call MessageBox, [hwnd], offset szSure, NULL, MB_YESNO or MB_ICONHAND cmp eax, IDYES je wmdestroy xor eax, eax ret WndProc endp public WndProc ends end start
#5
Posted 18 February 2012 - 08:31 PM
Gunner said:
This is from TASM\EXAMPLES\WAP32 and modifed with your code.
If you are just starting with Assembly, I suggest you not use manual stack frames (using ebp) and manual pushing of ebp, ebx, esi, edi etc... use proc and uses. Once you learn Asm, you can always use manual stack frames.
Yes I use Win7, I use an IDE so the command lines use are a little different
If you are just starting with Assembly, I suggest you not use manual stack frames (using ebp) and manual pushing of ebp, ebx, esi, edi etc... use proc and uses. Once you learn Asm, you can always use manual stack frames.
Yes I use Win7, I use an IDE so the command lines use are a little different
What IDE do you use?? I have heard of masm.. Is it good.. I am also a beginner in asm.. i just know C but overall i am very weak in electronics.. I am a windows 7 32bit user!!
#6
Posted 20 February 2012 - 02:27 AM
NASM is better in my opinion. The preprocessor is far more powerful, the command options less complicated, good optimization, etc. It's free and well-documented too.
sudo rm -rf /
#7
Posted 20 February 2012 - 06:29 AM
dargueta said:
NASM is better in my opinion. The preprocessor is far more powerful, the command options less complicated, good optimization, etc. It's free and well-documented too.
#8
Posted 20 February 2012 - 03:57 PM
NASM, MASM, YASM, FASM, A386 are all for x86 Assembly
#9
Posted 20 February 2012 - 06:34 PM
dargueta said:
... good optimization, etc. ...
What? I though assembly language doesn't have optimization; assembly language is for directly programming the processor.
* * *
NASM can do 8086; it can do a lot of Intel-based (ie not ARM or MIPS, etc.) stuff, including the support for a lot of common output formats.
#10
Posted 20 February 2012 - 11:04 PM
Some instructions can be encoded more than one way, such as jumps. The assembler will pick the best option (unless you override it) depending on whether you're looking for size or performance, as specified by the flags you pass it. Check the man pages.
sudo rm -rf /
#11
Posted 20 February 2012 - 11:41 PM
Jumps? Like this?:
(It's probably wrong system call convention, though.)
my_code: mov eax, dword [my_var] cmp eax, 65 jz .this_is_A jmp .this_is_B .this_is_A: xor eax, eax int 0x21 jmp .this_is_cont .this_is_B: inc eax int 0x80 jmp .this_is_cont .this_is_cont: ...
(It's probably wrong system call convention, though.)
#12
Posted 20 February 2012 - 11:44 PM
It's more to do with the encoding of the jump instruction rather than its placement; that onus is primarily on you. At this level, the optimizer can only do so much while respecting your code.
sudo rm -rf /
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









