Windows PSAPI

sleek cslush at gmail.com
Sun Sep 7 11:15:02 PDT 2008


Sergey,

Thanks for the response. Lucky for me, I actually fixed those first couple 
bugs you mentioned after looking at the code a bit more. Unluckily for me, 
it still sounds like I'm somewhat screwed. Does anyone else out there have 
any info as to how I can use PSAPI from D?

"Sergey Gromov" <snake.scaly at gmail.com> wrote in message 
news:MPG.232e39d36d5254929896bb at news.digitalmars.com...
> sleek <cslush at gmail.com> wrote:
>> Hi, I'm trying to get a list of all processes running on my machine and 
>> the
>> dlls that are in use by those processes. Windows provides the PSAPI to
>> perform these tasks. However, the code I'm trying to run isn't working as
>> expected. I can get the PIDs of the processes, but beyond that, weird 
>> things
>> occur.
>>
>> Can anyone offer some assistance? I have attached the code in question.
>
> Firstly, there are some obvious bugs:
>
>    DWORD count;
>    if (!EnumProcessModules(hProcess, hMods.ptr,
>        hMods.sizeof, &count))
>    {
>        return;
>    }
>
>    hMods.length = count / DWORD.sizeof;
>
> must be
>
>    DWORD count;
>    if (!EnumProcessModules(hProcess, hMods.ptr,
>        hMods.length * HMODULE.sizeof, &count))
>    {
>        return;
>    }
>
>    hMods.length = count / HMODULE.sizeof;
>
> But there is one more important and crucial.
>
> The call to GetModuleFileNameExA() messes up stack.  As far as I can
> tell this happens because PSAPI functions are declared extern(C) in
> psapi.d bindings, but in fact are __stdcall.  The problem is, it's not
> possible to replace extern(C) with extern(Windows) because the psapi.dll
> functions have unmangled names, while extern(Windows) mangles them with
> argument stack size.  I don't have a slightest idea of how to specify
> mangling convention and calling convention separately in D. In C
> declaration looks like:
>
> extern "C"
> DWORD
> WINAPI
> GetModuleFileNameExA(
>    HANDLE hProcess,
>    HMODULE hModule,
>    LPSTR lpFilename,
>    DWORD nSize
>    ); 




More information about the Digitalmars-d-learn mailing list