The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: xandaz on May 22, 2012, 11:18:54 AM

Title: process32first/next problem....should be easy...
Post by: xandaz on May 22, 2012, 11:18:54 AM
    Can someone tell me why this doesn't work? thanks
Title: Re: process32first/next problem....should be easy...
Post by: xandaz on May 22, 2012, 11:22:57 AM
   there's a problem in dwSize. wrong size but also it works with masm10 but not masm11. I've seen some strange things happening with structures in masm version 11. Does anyone know how to fix it?
Title: Re: process32first/next problem....should be easy...
Post by: Force on May 22, 2012, 04:08:01 PM
Hi
xandaz

We talked about Process32  problem earlier
http://www.masm32.com/board/index.php?topic=18850.0   (http://www.masm32.com/board/index.php?topic=18850.0 )
Title: Re: process32first/next problem....should be easy...
Post by: dedndave on May 22, 2012, 04:53:53 PM
i don't think that's his problem - at least not his only one (he could have the prototype/lib issue, as well)

his problem is related to the size of the PROCESSENTRY32 structure, which has not changed from v10 to v11
so - i don't know why one works and one doesn't - if that is the case

but - i do know that this is wrong...
process32       PROCESSENTRY32      <36+256,<>>
the correct size of the structure is 296 bytes - not 292 bytes
the reason for this is that MAX_PATH is 260 - not 256

in any event, i would not hard-wire the size of the structure with a numeric expression
if you want to do it, do it with the SIZEOF directive
process32       PROCESSENTRY32      <sizeof PROCESSENTRY32,<>>

i wouldn't do it that way, either   :bg

the size of the structure is 296 bytes
if you define it in the .DATA section, it adds 296 bytes (or more) to the size of the EXE

however, if you define it in the .DATA? section, and fill in the size with code, the EXE will be at least 287 bytes smaller
(assuming it takes ~9 bytes to fill in the structure size with code)
        .DATA?

process32       PROCESSENTRY32      <>

        .CODE

        mov     process32.dwSize,sizeof PROCESSENTRY32


in fact, i would use register base-index addressing because you can use the register twice, like so...
        invoke  CreateToolhelp32Snapshot,TH32CS_SNAPPROCESS+TH32CS_SNAPMODULE,0
        mov     hSnap,eax
        mov     edx,offset process32
        mov     [edx].PROCESSENTRY32.dwSize,sizeof PROCESSENTRY32
        invoke  Process32First,eax,edx

as it happens, the index is for the first member is 0, so it's really register base addressing   :bg
Title: Re: process32first/next problem....should be easy...
Post by: xandaz on May 22, 2012, 05:03:49 PM
   i know dave.... i forgot to clear that when i submitted the file. I was just counting size by myself thinking had miscalculated it. Wrong count tho.
Title: Re: process32first/next problem....should be easy...
Post by: xandaz on May 22, 2012, 05:04:25 PM
 [TYPO]....thinking Masm had miscalculated...
Title: Re: process32first/next problem....should be easy...
Post by: dedndave on May 22, 2012, 05:06:16 PM
then - you probably want to look through the thread that Force linked and use Erol's tools to rebuild the lib
Title: Re: process32first/next problem....should be easy...
Post by: dedndave on May 22, 2012, 05:08:42 PM
while you're at it, the same problem exists in 2 include\lib pairs; kernel32 and kernl32p
and 4 functions; Module32First, Module32Next, Process32First, Process32Next
for a total of 8 fixes   :bg
Title: Re: process32first/next problem....should be easy...
Post by: xandaz on May 22, 2012, 05:17:19 PM
    I already made the changes for process32first/next but still doesn't enumerate. Only does so when i make that change in PROCESSENTRY32. The szExeFile from DB to DW. Can you garantee it works for you?
Title: Re: process32first/next problem....should be easy...
Post by: dedndave on May 22, 2012, 05:30:31 PM
that works - in the ANSI form

i added a structure definition for the UNICODE version

it works also...
Title: Re: process32first/next problem....should be easy...
Post by: MichaelW on May 24, 2012, 11:50:27 AM
A good way to check structure sizes is with a Microsoft C compiler and the structure definitions from the Microsoft header files.

This should be happening in the new forum, where it has a future.