Re: NativeCall C++ structure question
On 11/21/22 05:01, ToddAndMargo via perl6-users wrote: Hi All, Windows ChromeBook Edition (W11-22H2). I have been doing a lot of head scratching here. I have a project were I need to use BOOL WTSEnumerateSessionsA( [in] HANDLE hServer, # WTS_CURRENT_SERVER_HANDLE to use the RD Session Host server that hosts your application. [in] DWORD Reserved, [in] DWORD Version, [out] PWTS_SESSION_INFOA *ppSessionInfo, [out] DWORD *pCount ); to dig out a pointer (*ppSessionInfo) to a C++ OOP data structure, which is repeated pCount times. (No problem coding the above.) The data structure is C++ typedef struct _WTS_SESSION_INFOA { DWORD SessionId; # 4 bytes LPSTR pWinStationName; # 4 or 8 or 12 bytes WTS_CONNECTSTATE_CLASS State; # 4 or 8 bytes maybe } WTS_SESSION_INFOA, *PWTS_SESSION_INFOA; "_WTS_SESSION_INFOA" is 12 bytes in x86 and 24 bytes in x64: int nSize1 = sizeof WTS_SESSION_INFOA; // 12 in x86, 24 in x64 What I need to do is shown in C++ WTSEnumerateSessionsA(WTS_CURRENT_SERVER, 0, 1, , ) for (DWORD i = 0; i < dwCount; i++) { if (pwsi[i].State == WTSActive) { dwSession = pwsi[i].SessionId; break; } } Basically, I need to walk though the C++ structure looking for State == WTSActive (0), read the value of SessionId, exit the loop, and return the value of SessionId. How in the world do I use NativeCall to read "_WTS_SESSION_INFOA"'s structure? I will only be operating in 64 bit, so I take it I have to create a Buf of 24 bytes. Then take the buffer apart using little endian. And the [i] in the C++ code will be me incrementing *pCount by 24 bytes each successive read. Is there an easier way to do this? Many thanks, -T I have to do the above becasue the "SessionID" is reported incorrectly by M$'s other API's if you are running your program from the Task Scheduler Oh and I almost forgot: A H ! Another question: Is there a way to use the returned pointer and the pCount to to read the data into a Raku Buf or similar?
NativeCall C++ structure question
Hi All, Windows ChromeBook Edition (W11-22H2). I have been doing a lot of head scratching here. I have a project were I need to use BOOL WTSEnumerateSessionsA( [in] HANDLE hServer, # WTS_CURRENT_SERVER_HANDLE to use the RD Session Host server that hosts your application. [in] DWORD Reserved, [in] DWORD Version, [out] PWTS_SESSION_INFOA *ppSessionInfo, [out] DWORD *pCount ); to dig out a pointer (*ppSessionInfo) to a C++ OOP data structure, which is repeated pCount times. (No problem coding the above.) The data structure is C++ typedef struct _WTS_SESSION_INFOA { DWORDSessionId;# 4 bytes LPSTRpWinStationName; # 4 or 8 or 12 bytes WTS_CONNECTSTATE_CLASS State; # 4 or 8 bytes maybe } WTS_SESSION_INFOA, *PWTS_SESSION_INFOA; "_WTS_SESSION_INFOA" is 12 bytes in x86 and 24 bytes in x64: int nSize1 = sizeof WTS_SESSION_INFOA; // 12 in x86, 24 in x64 What I need to do is shown in C++ WTSEnumerateSessionsA(WTS_CURRENT_SERVER, 0, 1, , ) for (DWORD i = 0; i < dwCount; i++) { if (pwsi[i].State == WTSActive) { dwSession = pwsi[i].SessionId; break; } } Basically, I need to walk though the C++ structure looking for State == WTSActive (0), read the value of SessionId, exit the loop, and return the value of SessionId. How in the world do I use NativeCall to read "_WTS_SESSION_INFOA"'s structure? I will only be operating in 64 bit, so I take it I have to create a Buf of 24 bytes. Then take the buffer apart using little endian. And the [i] in the C++ code will be me incrementing *pCount by 24 bytes each successive read. Is there an easier way to do this? Many thanks, -T I have to do the above becasue the "SessionID" is reported incorrectly by M$'s other API's if you are running your program from the Task Scheduler Oh and I almost forgot: A H ! -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~
Re: What is this handle?
On Sat, Nov 19, 2022 at 10:13 PM, ToddAndMargo via perl6-users mailto:perl6-users@perl.org>> wrote: Hi All, Any of you familiar with native call? In the following C++ HANDLE WTSOpenServerA( [in] LPSTR pServerName ); Is HANDLE a DWORD (32 bit integer)? I just noticed I have HANDLE defined in Raku as constant HANDLE = Pointer[void]; I do believe most C++ pointers are 32 bit cardinals (unsigned integers) Many thanks, -T On 11/21/22 04:36, yary wrote: Handle is a pointer and you can treat it as such. A handle is a pointer to another pointer! it has different uses but basically it is a pointer. Most pointers are a memory address of a value like a number or string, a handle is a memory address of a pointer (another address) to one of those. Thank you! I am being forced to learn C++. AAA Interesting that they use the term HANDLE interchangeably with **pXXX (pointer to a pointer pointer).
Re: What is this handle?
Handle is a pointer and you can treat it as such. A handle is a pointer to another pointer! it has different uses but basically it is a pointer. Most pointers are a memory address of a value like a number or string, a handle is a memory address of a pointer (another address) to one of those. On Sat, Nov 19, 2022 at 10:13 PM, ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: > Hi All, > > Any of you familiar with native call? > > In the following > >C++ >HANDLE WTSOpenServerA( > [in] LPSTR pServerName >); > > Is HANDLE a DWORD (32 bit integer)? > > I just noticed I have HANDLE defined in Raku as > > constant HANDLE = Pointer[void]; > > I do believe most C++ pointers are 32 bit > cardinals (unsigned integers) > > Many thanks, > -T > > -- -y