News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Need "heap" of help

Started by Magnum, February 13, 2011, 11:25:48 PM

Previous topic - Next topic

Magnum

.code

;Trying to fix "Error_Io_Pending" error message. Fixed on 2/9/11
; Error is back.....????

start:

; Simply create your own heap (HeapCreate) and allocate your
; "application allocated OVERLAPPED structure" from this new heap

invoke HeapCreate, HEAP_GENERATE_EXCEPTIONS, 0, 0   ;;make heap
mov heapHandle, eax                 ;save handle, check success

.IF eax == NULL
invoke  MessageBox, NULL, addr Failed1, addr AppName, MB_OK

.ELSE
                    ; allocate 30,000 bytes of memory
invoke HeapAlloc, heapHandle, HEAP_GENERATE_EXCEPTIONS or HEAP_ZERO_MEMORY, 30000   
mov heapPointer, eax                ; save pointer, check success

.ENDIF

.IF eax == NULL
invoke  MessageBox, NULL, addr Failed2, addr AppName, MB_OK

.ENDIF

invoke RegisterEventSource,NULL,offset Provider_Name
mov     [hEventLog], eax ; copy handle for storage


.IF eax == NULL
invoke  MessageBox, NULL, addr Failed, addr AppName, MB_OK
invoke ExitProcess, NULL

.ENDIF

; BOOL ReportEvent(
;     HANDLE hEventLog,   // handle returned by RegisterEventSource
;     WORD wType,   // event type to log
;     WORD wCategory,   // event category
;     DWORD dwEventID,   // event identifier
;     PSID lpUserSid,   // user security identifier (optional)
;     WORD wNumStrings,   // number of strings to merge with message 
;     DWORD dwDataSize,   // size of binary data, in bytes
;     LPCTSTR *lpStrings,   // array of strings to merge with message
;     LPVOID lpRawData    // address of binary data

invoke ReportEvent,hEventLog,EVENTLOG_INFORMATION_TYPE,1,02h, 
NULL,1,sizeof string1,addr stringpointers,NULL

.IF eax == NULL
invoke  MessageBox, NULL, addr Failed4, addr AppName, MB_OK

.ENDIF

invoke DeregisterEventSource,hEventLog  ; Close the handle returned by the RegisterEventSource

.IF eax == NULL
invoke  MessageBox, NULL, addr Failed3, addr AppName, MB_OK

.ENDIF

invoke   HeapFree, heapHandle, 0, heapPointer

.IF eax == NULL
invoke  MessageBox, NULL, addr Failed5, addr AppName, MB_OK

.ENDIF

invoke ExitProcess, NULL
Have a great day,
                         Andy

dedndave

i don't quite understand all of what you are doing
but perhaps you need to use HeapLock/HeapUnlock to acquire a stable pointer

Magnum

I am creating an Event Log entry.

The documentation is all over the place for ReportEvent, etc.

Could you provide some more specifics?

Have a great day,
                         Andy

dedndave

you implied that it was a heap problem - or had been in the past
your use of the allocated block reminded me of copying to the clipboard, where they use GlobalLock

HeapLock:
QuoteIf the function succeeds, the calling thread owns the heap lock. Only the calling thread will be able to
allocate or release memory from the heap. The execution of any other thread of the calling process will
be blocked if that thread attempts to allocate or release memory from the heap. Such threads will
remain blocked until the thread that owns the heap lock calls the HeapUnlock function.

http://msdn.microsoft.com/en-us/library/aa366702%28v=vs.85%29.aspx

you might look at the examples at msdn for copy to clipboard to get some ideas

http://msdn.microsoft.com/en-us/library/ms649016%28v=vs.85%29.aspx#_win32_Copying_Information_to_the_Clipboard

Magnum

Getting undefined symbol for this ?

invoke     HeapUnLock,heapHandle

invoke HeapLock, heapHandle worked fine.


Have a great day,
                         Andy

Ghandi

Quote
HeapUnlock Function

Releases ownership of the critical section object, or lock, that is associated with a specified heap. It reverses the action of the HeapLock function.


BOOL WINAPI HeapUnlock(
  __in          HANDLE hHeap
);

Parameters
hHeap
A handle to the heap to be unlocked. This handle is returned by either the HeapCreate or GetProcessHeap function.

Return Value
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
The HeapLock function is primarily useful for preventing the allocation and release of heap memory by other threads while the calling thread uses the HeapWalk function. The HeapUnlock function is the inverse of HeapLock.

Each call to HeapLock must be matched by a corresponding call to the HeapUnlock function. Failure to call HeapUnlock will block the execution of any other threads of the calling process that attempt to access the heap.



Possibly because you've given "HeapUnLock" instead of "HeapUnlock"? If you have incorrect case, then MASM will fail to find the correct lib to link to.

HR,
Ghandi