I ask before how free memory from library which no more use. As I see this way to do this
icmp db "icmp.dll",0
icmpcreate db "IcmpCreateFile",0
invoke inet_addr, ADDR address
mov ebx, eax
invoke LoadLibrary, ADDR icmp
mov ebp, eax
invoke GetProcAddress, eax, ADDR icmpcreate
call eax ; IcmpCreateFile
mov edi, eax
invoke FreeLibrary, ebp
but what is this
INT 3h here?
http://www.masm32.com/board/index.php?PHPSESSID=1fba624f0f2404ac83e75becf8fb6c7b&topic=1056;prev_next=next
Quote03h CPU: The lowest non-reserved interrupt, it is used exclusively for debugging, and the INT 03 handler is always implemented by a debugging program
comdlg32 db 'comdlg32.dll',0
getopenfilename db 'GetOpenFileName',0
invoke LoadLibrary, addr comdlg32
mov ebp, eax
invoke GetProcAddress, eax, addr getopenfilename
push offset ofn
call eax
invoke FreeLibrary, ebp
Is that wright? what happen's with ebp???
- Insert the opcode int 3 somewhere in your code
- install Olly (http://www.ollydbg.de/version2.html)
- open your executable in Olly
- press F9
The rest is learning by doing and reading the manual if you can find one.
Quote
but what is this INT 3h here?
It is a break point for the debugger.
With windows,it is recommended to use
QuoteInvoke debugbreak
instead.
OK. Thanks
why I can't get procaddress???
Quotejmp ec
comdlg32 db 'comdlg32.dll',0
getopenfilename db 'GetOpenFileName',0
ec:
invoke LoadLibrary, addr comdlg32
.if eax!=0
mov ebx, eax
invoke GetProcAddress, eax, addr getopenfilename
.if eax!=0
push offset ofn
call eax
.else
invoke MessageBox,0,0,0,0 (http://smiles.kolobok.us/standart/this.gif)
.endif
invoke FreeLibrary, ebx
.else
invoke MessageBox,0,0,0,0
.endif
Quote
why I can't get procaddress???
GetProcAddress is in the kernel32.lib (dll),this one must be loaded before the call to the function.
You need also the kernel32.inc (masm32 package) or winbase.h (.sdk) for declarations.
this only part of code which I replaced
invoke GetOpenFileName, addr ofn
of cource
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
stay on the very beginning
invoke GetOpenFileName, addr ofn - this use 3 mb of memory of 7 my application use, so I want free it after file choose
Quotejmp ec
comdlg32 db 'comdlg32.dll',0
getopenfilename db 'GetOpenFileNameA',0 (http://smiles.kolobok.us/standart/dance3.gif)
ec:
invoke LoadLibrary, addr comdlg32
.if eax!=0
mov ebx, eax
invoke GetProcAddress, ebx, addr getopenfilename
.if eax!=0
push offset ofn
call eax
.else
invoke MessageBox,0,0,0,0
.endif
invoke FreeLibrary, ebx
.else
invoke MessageBox,0,0,0,0
.endif
To avoid this mistakes,the use of declarations files is prefered.
Quote
include comdlg32.inc
includeliib comdlg32.lib
...and you can used GetOpenFileName without problems.
I use it without priblems. I want free memory.
In this way memory not be free (http://smiles.kolobok.us/standart/beee.gif)
To free memory (if it is a real problem ?),you can
Quote
put the OPENFILENAME structure in stack and free it when the called proc is ended.
truc proc
LOCAL machin:OPENFILENAME
;don't forget to initilialise the structure with zero
.....
unload the dll , but this is not granted to free memory.Another program can have loded it and in this case,only the count of the dll is decreased by one.
(http://smiles.kolobok.us/standart/scratch_one-s_head.gif)
this won't fly :P
invoke MessageBox,0,0,0,0
here is some code that i use to get a Save filename
it is very similar to Open
FileTypeStrs db 'Text Files',0,'*.txt',0,'All Files',0,'*.*',0,0
;OPENFILENAME STRUCT
; lStructSize dd ?
; hwndOwner dd ?
; hInstance dd ?
; lpstrFilter dd ?
; lpstrCustomFilter dd ?
; nMaxCustFilter dd ?
; nFilterIndex dd ?
; lpstrFile dd ?
; nMaxFile dd ?
; lpstrFileTitle dd ?
; nMaxFileTitle dd ?
; lpstrInitialDir dd ?
; lpstrTitle dd ?
; Flags dd ?
; nFileOffset dw ?
; nFileExtension dw ?
; lpstrDefExt dd ?
; lCustData dd ?
; lpfnHook dd ?
; lpTemplateName dd ?
call FnAlloc
;EAX = allocated address
;ECX = 0
;EDX = size of allocated block
push eax ;HFree:hBlck
push edx
push eax
push ecx ;lpTemplateName
dec edx
push ecx ;lpfnHook
push ecx ;lCustData
push offset FileTypeStrs+13 ;lpstrDefExt
push ecx ;nFileOffset/nFileExtension
push OFN_LONGNAMES or OFN_HIDEREADONLY or OFN_OVERWRITEPROMPT ;Flags or OFN_ENABLEHOOK or OFN_EXPLORER
push offset szSaveAs ;lpstrTitle
push ecx ;lpstrInitialDir
push ecx ;nMaxFileTitle
push ecx ;lpstrFileTitle
push edx ;nMaxFile
push eax ;lpstrFile
push 1 ;nFilterIndex
push ecx ;nMaxCustFilter
push ecx ;lpstrCustomFilter
push offset FileTypeStrs ;lpstrFilter
push hInstance ;hInstance
push ecx ;hwndOwner
push 76 ;lStructSize
INVOKE GetSaveFileName,esp
add esp,76 ;sizeof OPENFILENAME
xor eax,eax
pop edx
pop ecx
cmp al,[edx]
jz no_filename
;file save code here
no_filename:
CALL HFree
;************************************************************
FnAlloc PROC
mov edx,4096
push edx
INVOKE HeapAlloc,hHeap,HEAP_ZERO_MEMORY,edx
xor ecx,ecx
pop edx
ret
FnAlloc ENDP
;************************************************************
OPTION PROLOGUE:None
OPTION EPILOGUE:None
HFree PROC hBlck:DWORD
INVOKE HeapFree,hHeap,NULL,[esp+4]
ret 4
HFree ENDP
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef
;************************************************************
How free memory from libraries no more useQuoteinclude \MASM32\INCLUDE\psapi.inc
includelib \MASM32\LIB\psapi.lib
invoke GetCurrentProcess
invoke EmptyWorkingSet, eax
(http://s2.ipicture.ru/uploads/20111217/CzMfGLTm.png)(http://smiles.kolobok.us/artists/connie/connie_crazyperson.gif)
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682606%28v=vs.85%29.aspx
This more universal
SetProcessWorkingSetSize Minimum supported client - Windows 2000 Professional
http://msdn.microsoft.com/en-us/library/windows/desktop/ms686234%28v=vs.85%29.aspx
Quoteinvoke GetCurrentProcess
invoke SetProcessWorkingSetSize, eax, -1, -1
Quote;===============================================================
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
invoke GetCurrentProcess
invoke SetProcessWorkingSetSize, eax, -1, -1
xor eax,eax
ret
WndProc endp
(http://s1.ipicture.ru/uploads/20111217/FCs0iYID.gif)
CoFreeUnusedLibraries function
http://msdn.microsoft.com/en-us/library/windows/desktop/ms679712%28v=vs.85%29.aspx