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

Shooter

I'm trying to show the current time in my little proggy, so after finding a few examples to refer to, in this case "GetTime.asm", I added the following line to my code, which appears to be the source of my program crashing all of the time.

mov str1, cat$(str1,hour,":",minute,":",second)

(Included is my entire project as it stands now. Note: I had to include the entire path to the macros as I have yet to figure out how to point to them during assembly... I'm using RadASM 3.x as my IDE. Any help on this would also be greatly appreciated.)

As near as I can tell, calling szMultiCat is the culprit, but I'm not sure why. OllyDbg reports
Quote"Access Violation when reading [00000000]"

Can someone steer me in the right direction on this one?

Spare us the " (Solved) " title, this forum is not a paid help desk.
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

szmulticat WILL always bomb out on you if you don't tell it the correct number of items you are pushing on the stack...  can't look at code i am out rescuing people with my snowblower
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

dedndave

DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL str1:DWORD
LOCAL hour:DWORD
LOCAL minute:DWORD
LOCAL second:DWORD
invoke GetLocalTime,ADDR LocalTime
    movzx eax, LocalTime.wHour
    mov hour, ustr$(eax)
    movzx eax, LocalTime.wMinute
    mov minute, ustr$(eax)
    movzx eax, LocalTime.wSecond
    mov str1, cat$(str1,hour,":",minute,":",second)

when you call cat$, str1 is some undefined value (maybe 0)
try this
    mov str1, cat$(hour,":",minute,":",second)
not sure if it's right - i don't use cat$   :P

qWord

it is also a good idea to read the documentation:
QuoteIf the source buffer does not already have string data in it, the first byte MUST be set to a zero byte so it is seen as a zero length string.
FPU in a trice: SmplMath
It's that simple!

Shooter

Quote from: dedndave on December 28, 2010, 07:04:14 PM
not sure if it's right - i don't use cat$   :P
Dave,
What is your method for doing something like this?

(BTW, I erased that 'str1' and tried that; still crashes.)


Gunner,
I'm not calling szmulticat directly... cat$ (from macros.asm) uses it like this:
txt equ <invoke szMultiCat,>
I have no idea how it works either (this is a new way to code to me).

qWord,
Where did you find that quote?

-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.

qWord

Quote from: Shooter on December 28, 2010, 07:16:38 PMWhere did you find that quote?
look at \masm32\help\hlhelp.chm

qWord
FPU in a trice: SmplMath
It's that simple!

Shooter

Quote from: qWord on December 28, 2010, 07:20:43 PM
look at \masm32\help\hlhelp.chm

#1) It sure would've been nice for me to have known that before,
#2) I changed my code to this, but it still crashes:
TimeStr DD 16 Dup (0)

    mov TimeStr, cat$(TimeStr,hour,":",minute,":",second)
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

Your first para needs to be a ptr to a buffer that is big enough to hold the string.

szMulticat:
1. pcount is the number of zero terminated strings to append.
2. lpBuffer is the address of the buffer to appends the strings to.
3. args is the comma seperated parameter list.

Shooter

Quote from: jj2007 on December 28, 2010, 07:40:29 PM
Your first para needs to be a ptr to a buffer that is big enough to hold the string.

szMulticat:
1. pcount is the number of zero terminated strings to append.
2. lpBuffer is the address of the buffer to appends the strings to.
3. args is the comma seperated parameter list.

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. I used this bit of code like it was written in GetTime.asm (except I deleted a few strings), an example file in the MASM32 directory.

The point being: I'm just trying to add the current time to my dialog so I can tell if the clock set up to local time or UTC. This was the only approach I found using "SYSTEMTIME" that had a dialog to display in, albeit MESSAGBOX, but still a dialog.

-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

   INVOKE SendDlgItemMessage,hWin,103,WM_SETTEXT, 0, OFFSET lpbData+NULL
   INVOKE SendDlgItemMessage,hWin,105,WM_SETTEXT, 0, DWORD PTR [lpbIP]+NULL
   INVOKE SendDlgItemMessage,hWin,107,WM_SETTEXT, 0, DWORD PTR [str1]+NULL

ok - NULL is an EQUate
someplace in windows.inc, you'll find something like
NULL EQU 0
so, "OFFSET lpbData+NULL" is the address of lpbData, plus 0
"DWORD PTR [lpbIP]+NULL" is the dword value at address lpbIP
"DWORD PTR [str1]+NULL" is the dword value at address str1
you can't tack a null string terminator onto the end of data that way

these make more sense...
   INVOKE SendDlgItemMessage,hWin,103,WM_SETTEXT, 0, lpbData
   INVOKE SendDlgItemMessage,hWin,105,WM_SETTEXT, 0,lpbIP
   INVOKE SendDlgItemMessage,hWin,107,WM_SETTEXT, 0, str1

although, i didn't disect the code to see
you are using GoAsm i think - i don't have it installed

i think this line could go away altogether
   mov str1, cat$(str1,hour,":",minute,":",second)
as well as the str1 variable
   INVOKE SendDlgItemMessage,hWin,107,WM_SETTEXT, 0,Cat$(hour,":",minute,":",second)
looks like it might work   :bg
if i want to concatonate strings, i usually write my own code to do it
that is because i haven't played with all the macros, yet
and because i have done it that way for 25 years   :P
that doesn't mean that my way is the right way

Shooter

Dave,
I'm using masm32.

Also, if I comment out the line that contains "cat$", the program works, even with these lines:
   INVOKE SendDlgItemMessage,hWin,103,WM_SETTEXT, 0, OFFSET lpbData+NULL
   INVOKE SendDlgItemMessage,hWin,105,WM_SETTEXT, 0, DWORD PTR [lpbIP]+NULL
   INVOKE SendDlgItemMessage,hWin,107,WM_SETTEXT, 0, DWORD PTR [str1]+NULL


Also, until I can get "str1" setup correctly, I've commented out that last 'INVOKE' that contains "str1" (you must've un-commented it out in your quote).

I guess I'm just going to have to do this old fashion way and build my own subroutine.

Thanks,
-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

It is very simple to use szMultiCat:
invoke szMultiCat, NumberOfStringsToAppend, BufferForStrings, Addr String1, Addr String2, Addr String3 etc...

So for NumberOfStringsToAppend in the above sample you would put 3 because you are pushing 3 items on the stack..

BufferForString is a pointer to a buffer to hold the strings
So, off the top of my head for 3 string you might do:

invoke szLen, addr String1
mov ebx, eax

invoke szLen, addr String2
add ebx, eax

invoke szLen, addr String3
add ebx, eax

invoke HeapAlloc, hMainHeap, HEAP_ZERO_MEMORY, ebx
mov lpszTempMem, eax

invoke szMultiCat, 3, lpszTempMem, Addr String1, Addr String2, Addr String3
PrintStringByAddr lpszTempMem ; <----- handy debug macro that will print the string in a debug window

invoke HeapFree, hMainHeap, 0, lpszTempMem
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

Shooter

DOH!!!!!!!

It might help if I added
    mov second, ustr$(eax)
to my code. :red :red :red
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

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 (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

dedndave

Shooter,
i might mention - Dr Watson and c0000005
when you see this, you can't help but being a little disappointed
but - get used to it
warm up to it
make it your friend   :bg
sometimes, it can give you an offset or a stack value that helps you debug your code
and - it's better than the BSOD alternative

when i first started out in here, i considered changing my nic to c0000005   :lol