Guys, please help. I am trying to make this work from at least 4 months.
I am new to programming and some things are difficult to me, but I really
need to make my project work.
I can't find anything helpfull in internet for 4 months ;-( .
Please someone who is more expirenced help me.
I am trying to use the Terminal Server APIs
There is as an API function WTSEnumerateSes sions, which returns a
WTS_SESSION_INF O custom structure n times.
Actually it returns pointer to it.
I just can't get it working in VB .NET
While searching through MSDN I've found something, but I need an opinion
from someone more experienced.
The text is:
======
Formatted Non-Blittable Classes
Formatted non-blittable classes have fixed layout (formatted) but the data
representation is different in managed and unmanaged memory. The data can
require transformation under the following conditions:
If a non-blittable class is marshaled by value, the callee receives a
pointer to a copy of the data structure.
If a non-blittable class is marshaled by reference, the callee receives
a pointer to a pointer to a copy of the data structure.
If the InAttribute attribute is set, this copy is always initialized
with the instance's state, marshaling as necessary.
If the OutAttribute attribute is set, the state is always copied back to
the instance on return, marshaling as necessary.
If both InAttribute and OutAttribute are set, both copies are required.
If either attribute is omitted, the marshaler can optimize by eliminating
either copy.
Found at:
(http://msdn.microsoft.com/library/de...lfunctions.asp)
======
According to this the date returned from WTSEnumerateSes sions function is a
pointer to a pointer a copy of the data structure.
Or I am wrong?
If I am right, how to get this second pointer from VB .NET?
Here are the API Function and structure, by definition and how I've defined
them in my app
API
=====
WTS_SESSION_INF O
The WTS_SESSION_INF O structure contains information about a client session
on a terminal server.
typedef struct _WTS_SESSION_IN FO { DWORD SessionId; LPTSTR
pWinStationName ; WTS_CONNECTSTAT E_CLASS State;
} WTS_SESSION_INF O, *PWTS_SESSION_I NFO;
WTSEnumerateSes sions
The WTSEnumerateSes sions function retrieves a list of sessions on a
specified terminal server.
BOOL WTSEnumerateSes sions(
HANDLE hServer,
DWORD Reserved,
DWORD Version,
PWTS_SESSION_IN FO* ppSessionInfo,
DWORD* pCount
);
=====
And in my code
====
<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Auto)> _
Private Structure WTS_SESSION_INF O
Dim SessionID As Int32 'DWORD integer
Dim pWinStationName As String ' integer LPTSTR - Pointer to a
null-terminated string containing the name of the WinStation for this
session
Dim State As WTS_CONNECTSTAT E_CLASS
End Structure
<DllImport("wts api32.dll", _
bestfitmapping: =True, _
CallingConventi on:=CallingConv ention.StdCall, _
CharSet:=CharSe t.Auto, _
EntryPoint:="WT SEnumerateSessi ons", _
SetLastError:=T rue, _
ThrowOnUnmappab leChar:=True)> _
Private Shared Function WTSEnumerateSes sions2( _
ByVal hServer As IntPtr, _
<MarshalAs(Unma nagedType.U4)> _
ByVal Reserved As Int32, _
<MarshalAs(Unma nagedType.U4)> _
ByVal Vesrion As Int32, _
ByRef ppSessionInfo As IntPtr, _
<MarshalAs(Unma nagedType.U4)> _
ByRef pCount As Int32) As Int32
End Function
TIA