473,511 Members | 16,864 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Marshaling

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 WTSEnumerateSessions, which returns a
WTS_SESSION_INFO 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 WTSEnumerateSessions 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_INFO
The WTS_SESSION_INFO structure contains information about a client session
on a terminal server.
typedef struct _WTS_SESSION_INFO { DWORD SessionId; LPTSTR
pWinStationName; WTS_CONNECTSTATE_CLASS State;
} WTS_SESSION_INFO, *PWTS_SESSION_INFO;

WTSEnumerateSessions

The WTSEnumerateSessions function retrieves a list of sessions on a
specified terminal server.
BOOL WTSEnumerateSessions(
HANDLE hServer,
DWORD Reserved,
DWORD Version,
PWTS_SESSION_INFO* ppSessionInfo,
DWORD* pCount
);

=====

And in my code
====
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Private Structure WTS_SESSION_INFO
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_CONNECTSTATE_CLASS
End Structure

<DllImport("wtsapi32.dll", _
bestfitmapping:=True, _
CallingConvention:=CallingConvention.StdCall, _
CharSet:=CharSet.Auto, _
EntryPoint:="WTSEnumerateSessions", _
SetLastError:=True, _
ThrowOnUnmappableChar:=True)> _
Private Shared Function WTSEnumerateSessions2( _
ByVal hServer As IntPtr, _
<MarshalAs(UnmanagedType.U4)> _
ByVal Reserved As Int32, _
<MarshalAs(UnmanagedType.U4)> _
ByVal Vesrion As Int32, _
ByRef ppSessionInfo As IntPtr, _
<MarshalAs(UnmanagedType.U4)> _
ByRef pCount As Int32) As Int32
End Function

TIA
Jul 21 '05 #1
3 2641
It is written from me ;-)
and as I've found it is working partially

"Gabriele G. Ponti" <ggponti.at.hotmail.com> wrote in message
news:eJ**************@tk2msftngp13.phx.gbl...
http://www.pinvoke.net/default.aspx/...merateSessions

Jul 21 '05 #3


"Nikolay Petrov" wrote:
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 WTSEnumerateSessions, which returns a
WTS_SESSION_INFO 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 WTSEnumerateSessions 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_INFO
The WTS_SESSION_INFO structure contains information about a client session
on a terminal server.
typedef struct _WTS_SESSION_INFO { DWORD SessionId; LPTSTR
pWinStationName; WTS_CONNECTSTATE_CLASS State;
} WTS_SESSION_INFO, *PWTS_SESSION_INFO;

WTSEnumerateSessions

The WTSEnumerateSessions function retrieves a list of sessions on a
specified terminal server.
BOOL WTSEnumerateSessions(
HANDLE hServer,
DWORD Reserved,
DWORD Version,
PWTS_SESSION_INFO* ppSessionInfo,
DWORD* pCount
);

=====

And in my code
====
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Private Structure WTS_SESSION_INFO
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_CONNECTSTATE_CLASS
End Structure

<DllImport("wtsapi32.dll", _
bestfitmapping:=True, _
CallingConvention:=CallingConvention.StdCall, _
CharSet:=CharSet.Auto, _
EntryPoint:="WTSEnumerateSessions", _
SetLastError:=True, _
ThrowOnUnmappableChar:=True)> _
Private Shared Function WTSEnumerateSessions2( _
ByVal hServer As IntPtr, _
<MarshalAs(UnmanagedType.U4)> _
ByVal Reserved As Int32, _
<MarshalAs(UnmanagedType.U4)> _
ByVal Vesrion As Int32, _
ByRef ppSessionInfo As IntPtr, _
<MarshalAs(UnmanagedType.U4)> _
ByRef pCount As Int32) As Int32
End Function

TIA

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1866
by: Ash | last post by:
Hi, Has anyone ever tried using "COM marshaling" for cross- process communication? In particular, I am interested in cross-process marshaling between Managed Server and Unmanaged Client. ...
4
11680
by: Vadym Stetsyak | last post by:
Hi there!!! I'm looking for any resources on the subject. Any help will be appreciated! -- Vadym Stetsyak ICQ 161730125 He, who commands the past - commands the future
3
1312
by: Stephen Gennard | last post by:
Hello, I having a problem dynamically invoking a static method that takes a reference to a SByte*. If I do it directly it works just fine. Anyone any ideas why? I have include a example...
5
96473
by: VM | last post by:
What's marshalling? I've had to use it extensively for a project but I don't know what it means. I tried to look for a definition in the Internet but I couldn't find anything that would explain...
3
3626
by: Rudy Velthuis | last post by:
Hello, Does anyone know how to create a struct that will marshal to the following C++ struct A, containing an array of the user defined String10 type: struct String10 { char SLen; char S;
1
2466
by: Nadav | last post by:
Hi I am about to write a performance crutial system, I am considering writing this system based on native COM or unmanaged C++ exposed as CLI, Now, I Wonder... does exposing a native code through...
4
3130
by: MSDousti | last post by:
Hi all, I read some Q&As in the Net, discussing Marshalization of nested structs in C# (or VB.NET). Some guys stated that .NET framework does not support this feature yet. Are they right? ...
1
2664
by: Bill Medland | last post by:
I am trying to do some P/Invoke custom marshaling and am looking for a little help on custom marshaling a value type. I am working based on Kate Gregory's "Arranging Custom Marshaling With...
0
1859
by: jpogorman | last post by:
Hello, I am trying to get c# custom marshaling working in a particular scenario but it does not appear to be working or not jumping into my marshaling class when I try to debug it. I am try to...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7355
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.