Author Topic: Process32FirstW problem  (Read 11773 times)

ragdog

  • Member
  • ****
  • Posts: 610
Process32FirstW problem
« on: September 23, 2012, 07:45:24 PM »
Hi @all

I have a problem with Process32FirstW it returns ervery 0
with Process32FirstA have i no problems why?


I have google about it and not anything found

Code: [Select]
LOCAL ProcessInformation:PROCESSENTRY32
LOCAL hSnapShot:DWORD


    mov ProcessInformation.dwSize,sizeof PROCESSENTRY32
invoke CreateToolhelp32Snapshot,TH32CS_SNAPALL,NULL
mov hSnapShot,eax
invoke Process32FirstW,hSnapShot,addr ProcessInformation

.if eax==TRUE
invoke MessageBox,0,CTEXT ("TRUE"),0,MB_OK
.endif


ragdog

  • Member
  • ****
  • Posts: 610
Re: Process32FirstW problem
« Reply #2 on: September 23, 2012, 09:05:56 PM »
I have solved it i must use Unicode structur

Code: [Select]
IFDEF __UNICODE__
MODULEENTRY32 equ MODULEENTRY32W
PROCESSENTRY32 equ PROCESSENTRY32W
ELSE
MODULEENTRY32 equ MODULEENTRY32A
PROCESSENTRY32 equ PROCESSENTRY32A
ENDIF ; !UNICODE



PROCESSENTRY32W STRUCT
dwSize DWORD ?
cntUsage DWORD ?
th32ProcessID DWORD ? ; this process
th32DefaultHeapID DWORD ?
th32ModuleID DWORD ? ; associated exe
cntThreads DWORD ?
th32ParentProcessID DWORD ? ; this process's parent process
pcPriClassBase DWORD ? ; Base priority of process's threads
dwFlags DWORD ?
szExeFile dw MAX_PATH dup (?)
PROCESSENTRY32W ENDS

PROCESSENTRY32A STRUCT
    dwSize              DWORD ?
    cntUsage            DWORD ?
    th32ProcessID       DWORD ?
    th32DefaultHeapID   DWORD ?
    th32ModuleID        DWORD ?
    cntThreads          DWORD ?
    th32ParentProcessID DWORD ?
    pcPriClassBase      DWORD ?
    dwFlags             DWORD ?
    szExeFile           db MAX_PATH dup(?)
PROCESSENTRY32A ENDS

MODULEENTRY32W STRUCT
dwSize DWORD ?
th32ModuleID DWORD ? ; This module
th32ProcessID DWORD ? ; owning process
GlblcntUsage DWORD ? ; Global usage count on the module
ProccntUsage DWORD ? ; Module usage count in th32ProcessID's context
modBaseAddr DWORD ? ; Base address of module in th32ProcessID's context
modBaseSize DWORD ? ; Size in bytes of module starting at modBaseAddr
hModule DWORD ? ; The hModule of this module in th32ProcessID's context
szModule dw MAX_MODULE_NAME32+1 dup (?)
szExePath dw MAX_PATH dup (?)
MODULEENTRY32W ENDS

MODULEENTRY32A STRUCT
    dwSize          DWORD ?
    th32ModuleID    DWORD ?
    th32ProcessID   DWORD ?
    GlblcntUsage    DWORD ?
    ProccntUsage    DWORD ?
    modBaseAddr     DWORD ?
    modBaseSize     DWORD ?
    hModule         DWORD ?
    szModule        db MAX_MODULE_NAME32+1 dup(?)
    szExePath       db MAX_PATH dup(?)
MODULEENTRY32A ENDS

To Hutch can you this add to the windows.inc?




hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7060
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Process32FirstW problem
« Reply #3 on: September 24, 2012, 12:00:10 AM »
Try reading Ramon Sala's post in the MASM32 sub forum, he has addressed it with replacements.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

ragdog

  • Member
  • ****
  • Posts: 610
Re: Process32FirstW problem
« Reply #4 on: September 24, 2012, 12:15:15 AM »
What for a sub forum from ramon?

I have it figured out to use Process32 and Module32 apis and structs for Ansii and unicode build

And works perfect :t

Code: [Select]
IFDEF __UNICODE__
  Process32First equ <Process32FirstW>
ENDIF

IFDEF __UNICODE__
  Process32Next  equ <Process32NextW>
ENDIF
Process32First PROTO :DWORD,:DWORD
Process32FirstW PROTO :DWORD,:DWORD
Process32Next PROTO :DWORD,:DWORD
Process32NextW PROTO :DWORD,:DWORD


IFDEF __UNICODE__
  Module32First equ <Module32FirstW>
ENDIF

IFDEF __UNICODE__
  Module32Next  equ <Module32NextW>
ENDIF
Module32First PROTO STDCALL :DWORD,:DWORD
Module32FirstW PROTO STDCALL :DWORD,:DWORD

Module32Next PROTO STDCALL :DWORD,:DWORD
Module32NextW PROTO STDCALL :DWORD,:DWORD

IFDEF __UNICODE__
PROCESSENTRY32 equ PROCESSENTRY32W
ELSE
PROCESSENTRY32 equ PROCESSENTRY32A
ENDIF ; !UNICODE

IFDEF __UNICODE__
MODULEENTRY32 equ MODULEENTRY32W
ELSE
MODULEENTRY32 equ MODULEENTRY32A
ENDIF ; !UNICODE

PROCESSENTRY32W STRUCT
dwSize DWORD ?
cntUsage DWORD ?
th32ProcessID DWORD ? ; this process
th32DefaultHeapID DWORD ?
th32ModuleID DWORD ? ; associated exe
cntThreads DWORD ?
th32ParentProcessID DWORD ? ; this process's parent process
pcPriClassBase DWORD ? ; Base priority of process's threads
dwFlags DWORD ?
szExeFile dw MAX_PATH dup (?)
PROCESSENTRY32W ENDS

PROCESSENTRY32A STRUCT
    dwSize              DWORD ?
    cntUsage            DWORD ?
    th32ProcessID       DWORD ?
    th32DefaultHeapID   DWORD ?
    th32ModuleID        DWORD ?
    cntThreads          DWORD ?
    th32ParentProcessID DWORD ?
    pcPriClassBase      DWORD ?
    dwFlags             DWORD ?
    szExeFile           db MAX_PATH dup(?)
PROCESSENTRY32A ENDS

MODULEENTRY32W STRUCT
dwSize DWORD ?
th32ModuleID DWORD ? ; This module
th32ProcessID DWORD ? ; owning process
GlblcntUsage DWORD ? ; Global usage count on the module
ProccntUsage DWORD ? ; Module usage count in th32ProcessID's context
modBaseAddr DWORD ? ; Base address of module in th32ProcessID's context
modBaseSize DWORD ? ; Size in bytes of module starting at modBaseAddr
hModule DWORD ? ; The hModule of this module in th32ProcessID's context
szModule dw MAX_MODULE_NAME32+1 dup (?)
szExePath dw MAX_PATH dup (?)
MODULEENTRY32W ENDS

MODULEENTRY32A STRUCT
    dwSize          DWORD ?
    th32ModuleID    DWORD ?
    th32ProcessID   DWORD ?
    GlblcntUsage    DWORD ?
    ProccntUsage    DWORD ?
    modBaseAddr     DWORD ?
    modBaseSize     DWORD ?
    hModule         DWORD ?
    szModule        db MAX_MODULE_NAME32+1 dup(?)
    szExePath       db MAX_PATH dup(?)
MODULEENTRY32A ENDS


Vortex

  • Member
  • *****
  • Posts: 2109
Re: Process32FirstW problem
« Reply #5 on: September 24, 2012, 05:08:49 AM »
Hi ragdog,

You can check this thread :

A pair of bugs in Kernel32.lib and kernlp.lib

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: Process32FirstW problem
« Reply #6 on: September 24, 2012, 04:08:44 PM »
Not a bug but a problem of define with masm.
The usual way to define ansi and unicode function is to add a A or a W at the end of the function.
Here it's not the case,there is only Process32First and Process32FirstW.
Like that There is a problem with masm.

Quote
Process32NextW PROTO :DWORD ,:DWORD
Process32First PROTO :DWORD ,:DWORD
IFDEF UNICODE
Process32First   equ   < Process32FirstW>
ENDIF
When use of unicode you got error "A2005:symbol redefinition Process32First "
This don't happen with the c++.
To avoid this:
Quote
Process32NextW PROTO :DWORD ,:DWORD
IFDEF UNICODE
Process32First   equ   < Process32FirstW>
ELSE
Process32First PROTO :DWORD ,:DWORD
ENDIF
The Process32First prototype is only define in ansi version.
As this , there is no more problem and you can switch from ansi to unicode,the both work.
Later:
The masm32 lib haven't _Process32First@8
Quote
                  _Process32First@8      ;only in sdk windows lib kernel32.lib
                  _Process32FirstW@8
                  _Process32Next@8
                  _Process32NextW@8


« Last Edit: September 24, 2012, 06:28:54 PM by ToutEnMasm »
Fa is a musical note to play with CL

dedndave

  • Member
  • *****
  • Posts: 8825
  • Still using Abacus 2.0
    • DednDave

ragdog

  • Member
  • ****
  • Posts: 610
Re: Process32FirstW problem
« Reply #8 on: September 28, 2012, 03:02:17 AM »
@Dave

My last post Definition works fine to build ansi and unicode  :t
http://masm32.com/board/index.php?topic=716.msg5998#msg5998

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7060
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Process32FirstW problem
« Reply #9 on: September 28, 2012, 03:52:08 AM »
I still fail to see what all the noise is about, Ramon Sala reported the problem some time ago then subsequently posted a solution to rebuilding the library. All of this noise is something like re-inventing the wheel, its already been done.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

rsala

  • Member
  • ***
  • Posts: 312
    • Easy Code
Re: Process32FirstW problem
« Reply #10 on: September 28, 2012, 05:01:42 AM »
Hi all,

(Hutch: Thanks)

In the link below there is a downloadable zip (kernel32.zip) fixing the problem. Just replace the kernel32.inc and kernel32.lib from Masm32 corresponding folders with those coming in the mentioned zip file.

http://masm32.com/board/index.php?topic=506.0

Regards,

Ramon
EC coder

ragdog

  • Member
  • ****
  • Posts: 610
Re: Process32FirstW problem
« Reply #11 on: September 28, 2012, 11:03:00 PM »
Thanks to all

But now have i the next question why have Module32FirstW
MODULEENTRY32W.szModule not a russian file name

Here is my Project

Start "Тест Программа.exe" and run bdrt.exe for list processes

it print only  "C:\Radasm3\Masm\Projects\bdrt\???? ?????????.exe"

Why?

Greets,

jj2007

  • Member
  • *****
  • Posts: 10116
  • Assembler is fun ;-)
    • MasmBasic
Re: Process32FirstW problem
« Reply #12 on: September 28, 2012, 11:21:02 PM »
Start "Тест Программа.exe" and run bdrt.exe for list processes

it print only  "C:\Radasm3\Masm\Projects\bdrt\???? ?????????.exe"

Looks like you are printing an ANSI string that once was a Unicode string. Check at which point the "wrong" conversion took place. Or write it to a file, zip it and post it here.

ragdog

  • Member
  • ****
  • Posts: 610
Re: Process32FirstW problem
« Reply #13 on: September 28, 2012, 11:37:50 PM »
Sorry i forgot to upload my project :badgrin:


jj2007

  • Member
  • *****
  • Posts: 10116
  • Assembler is fun ;-)
    • MasmBasic
Re: Process32FirstW problem
« Reply #14 on: September 28, 2012, 11:59:33 PM »
Olly says this:


0012F950  3F 00 3F 00|3F 00 3F 00|3F 00 20 00|3F 00 3F 00| ? ? ? ? ?   ? ?
0012F960  3F 00 3F 00|3F 00 3F 00|3F 00 3F 00|3F 00 3F 00| ? ? ? ? ? ? ? ?
0012F970  2E 00 65 00|78 00 65 00|00 00 00 00|00 00 00 00| . e x e


So Module32FirstW creates crippled Unicode.