News:

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

Access Violation??

Started by Shooter, December 28, 2010, 06:48:59 PM

Previous topic - Next topic

jj2007

Quote from: Shooter on December 28, 2010, 07:50:22 PM
As I am making a call to a macro that makes another call to another macro that invokes szmulticat, I have no idea how to set those parameters.

Study the macros you are using. Or forget the M in Masm and code like in the 1980ies.

include \masm32\include\masm32rt.inc
.data
My$ dd txMyString
txMyString db "Good morning, this is Masm32!", 0

.data?
buffer db 1024 dup(?)

.code
start:
inkey cat$(offset buffer, "This is a cat$: [", My$, "]")
exit
end start


There are also more advanced macros around:
   Print CrLf$, "Hello, it is now roughly ", Left$(Time$, 5), " on ", Date$, CrLf$, "time to go to bed", 13, 10
   MsgBox 0, Cat$("Hello, it is now roughly "+Left$(Time$, 5)+" on "+Date$+CrLf$+"time to go to bed"), "Hi", MB_OK
:wink

dedndave

Quote   Print...
   ..., MB_OK
huh ?   :eek
j/k Jochen   :P

Shooter - JJ is the man when it comes to macros, around here   :U

Shooter

Quote from: Gunner on December 28, 2010, 08:27:21 PM
Fixed it for you
I made the buffers oversized, you can fix all that

Right you wanted to display the time?  It does, I commented out other stuff, you can fix all that yourself  :bg

Rob, I seriously appreciate that of you. I inserted your changes in place of my code's section and gave it a try... it works, but there's some gibberish being displayed at the beginning of TimeStr2. I'm trying to track down why right now.

-Shooter
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

Gunner

I will tell you why.... the buffers are declared on the stack, you have to zero them, I did not do that

lookup memfill in the masm library help file
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

Shooter

Quote from: dedndave on December 28, 2010, 08:41:14 PM
Quote   Print...
   ..., MB_OK
huh ?   :eek
j/k Jochen   :P

Shooter - JJ is the man when it comes to macros, around here   :U

It has been a very long time since I've even seen a macro for assembler, let alone how to use one. Adding dialog boxes to the mix really can strain one's own sanity when they don't have the memory they once used to.  :dazzled:

I appreciate all the input.

The funny thing was, I just simply forgot to convert the "seconds" to text before calling cat$. Ooops, my bad. ;)

-Shooter
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

Shooter

Rob,
I used memfill as you suggested and it works beautifully. Problem though, perhaps this isn't the method of getting the time I really want. I'd like for the clock to be updated on a regular basis so that the seconds and minutes are current. How would I do that?

-Shooter
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

jj2007

Quote from: Gunner on December 28, 2010, 08:45:33 PM
I will tell you why.... the buffers are declared on the stack, you have to zero them, I did not do that

lookup memfill in the masm library help file

For use with cat$, it's sufficient to zero the first byte
include \masm32\include\masm32rt.inc

.code
AppName db "Masm32 is great!", 0
Hello db "A message:", 0

MyTest proc uses esi edi arg1:DWORD, arg2:DWORD
LOCAL locbuf[260]:BYTE
  lea edi, locbuf
  mov byte ptr [edi], 0
  mov esi, cat$(edi, "This is the text: [", arg1, "]")
  MsgBox 0, esi, arg2, MB_OK
  ret
MyTest endp

start: invoke MyTest, offset AppName, addr Hello
exit

end start


Gunner

That is cool to know jj  :U ....  personally I don't use macros (maybe one day I will get around to trying to create and use em)  But he changed to using szMultCat, so I told him how to clear the garbage out of the buffer  :wink

Shooter, search the board for WM_TIMER and SetTimer

Basically, you would create a timer with settimer with an interval of 1000 (for 1 second) and in your window proc you will get a WM_TIMER message every second (or whatever you set the interval for) and in WM_TIMER you would update the time...
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

jj2007

Just for fun....
include \masm32\include\masm32rt.inc

.code
start: .Repeat
print "Current time is "
print time$(), 13
invoke Sleep, 500
invoke GetKeyState, VK_SHIFT
test ax, ax
.Until Sign?
print chr$(13, 10, "bye")
invoke Sleep, 1000
exit
end start

Shooter

Quote from: Gunner on December 28, 2010, 10:48:37 PM
Basically, you would create a timer with settimer with an interval of 1000 (for 1 second) and in your window proc you will get a WM_TIMER message every second (or whatever you set the interval for) and in WM_TIMER you would update the time...

Rob,
I got it to work using SetTimer and WM_TIMER, but I noticed two things about it.
1) The text doesn't display immediately when the dialog appears (takes about a second), which is OK for now,
2) I noticed that if the minutes and / or seconds are less than 10, there isn't a leading zero. I'm not sure how to ensure there is.

-Shooter
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

dedndave

you'll have to give us the EXE   :P
we don't have E:\radasm - lol
also, we DO have
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\Comctl32.inc
include \masm32\include\shell32.inc
include \masm32\include\gdi32.inc
include \masm32\include\advapi32.inc
include \masm32\include\wsock32.inc
include \masm32\include\msvcrt.inc
include \masm32\include\MASM32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\Comctl32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\advapi32.lib
includelib \masm32\lib\wsock32.lib
includelib \masm32\lib\msvcrt.lib
includelib \masm32\lib\MASM32.lib

i know - there are environment variables
but the "forum standard" is not to use them

dedndave

i guess, to make it update immediately, you can use SendMessage when the event occurs to force an update
well - that's one way to do it



<<<<<--------------------------- also a n00b   :bg

Gunner

I'm not gonna do it all for you  :toothy

In WM_INITDIALOG, you should get and show the time so it displays when the dialog loads, to update it you do what you are doing already in WM_TIMER...  What would you do with code that you are going to call from multiple places?  The answer.... next month  :bg No, put the code you get and format the date/time and stick it in a proc and call that proc in WM_TIMER and in WM_INITDIALOG  or just copy the code you have in WM_TIMER and paste it into WM_INITDIALOG,  :bg
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

Gunner

The time updates every second for me, BUT if for somereason it does not on another OS, you could do:
invoke GetDlgItem, hWin, 108
invoke InvalidateRgn, eax, NULL, TRUE


BTW, for readability and ease of code maintenance, you should NOT use the resource ID's you should use equates, STC_TIME equ 108 .... you can export the names in RadASM
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

Gunner

I missed one of you questions Shooter, about a leading zero?  Look up GetTimeFormat  :bg

Instead of the code you where using just use the following:
;invoke GetLocalTime,ADDR LocalTime
invoke GetTimeFormat,LOCALE_USER_DEFAULT, NULL, NULL, offset TimeFormat, addr TimeStr2, 72
;     movzx ecx, LocalTime.wHour
;     invoke dwtoa, ecx, addr lpszHour
;     movzx ecx, LocalTime.wMinute
;     invoke dwtoa, ecx, addr lpszMinute
;     movzx ecx, LocalTime.wSecond
;     invoke dwtoa, ecx, addr lpszSecond
;     invoke szMultiCat, 5, addr TimeStr2, addr lpszHour, offset szColon, \
;     addr lpszMinute, offset szColon, addr lpszSecond
INVOKE SendDlgItemMessage,hWin,108,WM_SETTEXT, 0, addr TimeStr2
invoke GetDlgItem, hWin, 108
invoke InvalidateRgn, eax, NULL, TRUE
  :U
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com