Home > Software engineering >  PTR DWORD in nim lang
PTR DWORD in nim lang

Time:03-02

what is the problem of This Code:

import winim


let CurrentProcessID = GetCurrentProcessId()
var SessionID :DWORD
let result1 = ProcessIdToSessionId(CurrentProcessID,cast [ptr DWORD](SessionID))
echo SessionID

Compile Command:

nim c -d=danger -d=mingw -d=strip --passc=-flto --passl=-flto --opt=size --app=console --cpu=amd64 --out=test.exe test.nim

OutPut in Windows10:

0

but the Correct answer is:

1

CodePudding user response:

ProcessIdToSessionId needs a pointer to the variable to write to, but you're passing the value of the variable itself as a pointer, that's why it fails.

Correct code would be like this (untested):

import winim

let CurrentProcessID = GetCurrentProcessId()
var SessionID: DWORD
let result1 = ProcessIdToSessionId(CurrentProcessID, addr SessionID)
echo SessionID
  • Related