473,395 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 2630
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.