According to the 
[docs](https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getmodulebasenamew),
 `GetModuleBaseNameW` needs the rights `PROCESS_QUERY_INFORMATION` and 
`PROCESS_VM_READ`. Plus, as @araq mentionned, you should preallocate the string.

Assuming you use winim, this code should work (works on my machine™)

̀
    
    
    proc test() =
      var hNDL = OpenProcess(cast[DWORD](PROCESS_QUERY_INFORMATION or 
PROCESS_VM_READ), FALSE, cast[DWORD](PID))
      defer: CloseHandle(hNDL)
      
      var pName = newWString(260)
      
      if GetModuleBaseNameW(hNDL, 0, pName, 260) == 0:
        echo GetLastError()
      else:
        echo pName
    
    when isMainModule:
      test()
    
    
    Run

How the go version works (in particular the `var pName uint16` followed by 
`&pname` bit) eludes me completely.

Reply via email to