C to VB .NET

N

Nikolay Petrov

Can anyone convert some C code to VB .NET for me?
Thanks in advance!!


#define LOGONID_CURRENT ((ULONG)-1)
#define SERVERNAME_CURRENT ((HANDLE)NULL)


typedef enum _WINSTATIONINFOCLASS {
WinStationInformation = 8



} WINSTATIONINFOCLASS;


typedef struct _WINSTATIONINFORMATIONW {
BYTE Reserved1[72];
ULONG SessionId;
BYTE Reserved2[4];
FILETIME ConnectTime;
FILETIME DisconnectTime;
FILETIME LastInputTime;
FILETIME LoginTime;
BYTE Reserved3[1096];
FILETIME CurrentTime;


} WINSTATIONINFORMATIONW, * PWINSTATIONINFORMATIONW;


typedef BOOLEAN (WINAPI * PWINSTATIONQUERYINFORMATIONW)(
HANDLE, ULONG, WINSTATIONINFOCLASS, PVOID, ULONG, PULONG );

BOOL Result;
HANDLE hServer = NULL;
HANDLE hWinSta = NULL;
ULONG SessId;
ULONG BufLen;
ULONG RetLen;
WINSTATIONINFORMATION Buf;
PWINSTATIONQUERYINFORMATIONW WinStationQueryInformationW = NULL;


hWinSta = LoadLibrary("WINSTA.DLL");


WinStatonQueryInformationW =
GetProcAddress(hWinSta,"WinStationQueryInformatoinW");


BufLen = sizeof(Buf);


// Assume that hServer is a valid server handle previously obtained
from
// WTSOpenServer().
//
// Assume that SessId has been set to the desired session id value.
The
// term "logon id" is synonymous with "session id".


Result =
WinStationQueryInformationW(hServer,SessId,WinStationInformation,&Buf,BufLe­n,&RetLen);



if (Result)
{
// Use the SYSTEMTIME structure and the FileTimeToSystemTime()
function
// to convert from FILETIME to SYSTEMTIME format. Remember, these
time
// values are GMT values; they don't have the local time zone
offset
// applied to them.


}


{
// handle the error


}
 
G

Guest

typedef enum _WINSTATIONINFOCLASS {
WinStationInformation = 8
} WINSTATIONINFOCLASS;

Enum WINSTATIONINFOCLASS
WinStationInformation = 8
End Enum
typedef struct _WINSTATIONINFORMATIONW {
BYTE Reserved1[72];
ULONG SessionId;
BYTE Reserved2[4];
FILETIME ConnectTime;
FILETIME DisconnectTime;
FILETIME LastInputTime;
FILETIME LoginTime;
BYTE Reserved3[1096];
FILETIME CurrentTime;
} WINSTATIONINFORMATIONW, * PWINSTATIONINFORMATIONW;

That doesn't look anything like what I have in my header file, which is


typedef struct _WINSTATIONINFORMATIONW {
BYTE Reserved2[70];
ULONG LogonId;
BYTE Reserved3[1140];
} WINSTATIONINFORMATIONW, * PWINSTATIONINFORMATIONW;

That translates to

Structure WINSTATIONINFORMATIONW
<MarshalAs(UnmanagedType.ByValArray, SizeConst=70)> _
Public Reserved2() As Byte
Public LogonId As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst=1140)> _
Public Reserved3() As byte
End Strucure

And finally the Declare

Declare Unicode Function WinStationQueryInformationW(hServer As IntPtr,
LogonId As Integer, WinStationInformationClass As WINSTATIONINFOCLASS, ByRef
pWinStationInformation As WINSTATIONINFORMATIONW, WinStationInformationLength
As Integer, ByRef pReturnLength As Integer) As <MarshalAs(UnmanagedType.I1)>
Boolean


Mattias
 
N

Nikolay Petrov

thanks Mattias
it is an undocumented function, a guess the structure too.

thanks
 
N

Nikolay Petrov

I am searching the idle times of Terminal Server sessions. And the only
code i found was this:
http://groups.google.com/group/micr...rosoft.public.*&rnum=1&hl=en#3cf53e12a3246e25

I am having troubles converting struct _WINSTATIONINFORMATIONW. You
have converted it in VB, but it's different from the source. I really
need those 'FILETIME' type variebles, that you have let through. What
is the corespondent .NET type for them? I guess 'Date', but I'm not
quite sure.
 
N

Nikolay Petrov

Mattias, when you marshal struct _WINSTATIONINFORMATIONW, you put
parameter to SizeConst, different from ones in the C example, why? Any
special reason?
typedef struct _WINSTATIONINFORMATIONW {
BYTE Reserved1[72];
ULONG SessionId;
BYTE Reserved2[4];
FILETIME ConnectTime;
FILETIME DisconnectTime;
FILETIME LastInputTime;
FILETIME LoginTime;
BYTE Reserved3[1096];
FILETIME CurrentTime;
} WINSTATIONINFORMATIONW, * PWINSTATIONINFORMATIONW;



Structure WINSTATIONINFORMATIONW
<MarshalAs(UnmanagedType.ByValArray, SizeConst=70)> _
Public Reserved2() As Byte
Public LogonId As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst=1140)> _
Public Reserved3() As byte
End Strucure
 
M

Mattias Sjögren

What is the corespondent .NET type for them?

FILETIME is available in the System.Runtime.InteropServices namespace.

Mattias, when you marshal struct _WINSTATIONINFORMATIONW, you put
parameter to SizeConst, different from ones in the C example, why?

I translated the definition the way it is in the Platform SDK header
file.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top