473,651 Members | 2,485 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 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
Jul 21 '05 #1
3 2659
It is written from me ;-)
and as I've found it is working partially

"Gabriele G. Ponti" <ggponti.at.hot mail.com> wrote in message
news:eJ******** ******@tk2msftn gp13.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 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

Jul 21 '05 #4

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

Similar topics

0
1883
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. There seems to be very little documentation/examples on this. I have a "Service" that needs to have a COM
4
11692
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 below... --
5
96482
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 what it is. Is converting a C-style struct to a C# class (or struct) marshalling? And what about the function exports? Are those Marshalling too? Thanks for your help and thanks for helping me with the Dll exports (the several messages I posted in...
3
3637
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
2473
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 CLI ( using a mixed mode DLL ) have any performance penalty? consider one Native C++ CLI assembly calling a methos od another CLI Native C++ Assembly, will there be any marshaling penalty, will there be any penelty at-all? is it possible to pass a...
4
3138
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? BTW, by nested structs I mean structures such as this:
1
2672
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 P/Invoke", which is unfortunately in C++ with managed extensions; I am working in C#. As with Kate's example I want to marshal from a System.DateTime to a proprietary format. However I cannot figure out how to tell the system to box the DateTime. ...
0
1871
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 implement a performance improvement in the transfer of thousands of objects (ClientInfoDescriptor) over a remote call. The objects all have a model object (IDataDrivenModel) to describe them but there may only two or three model objects in total. These...
0
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8697
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8465
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8579
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5612
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1587
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.