Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / December 2004

Tip: Looking for answers? Try searching our database.

Terminal Server API

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nikolay Petrov - 29 Dec 2004 08:29 GMT
I am makeing an app which uses WTS API function.

I have done most of it, except a little part where I should marshal a
structure from pointer.

I have found some code in newsgroups, but it is in C# and I use VB .NET.
I've tried to convert it by my own, but it gives me some errors in IDE.

Please someone take a look:

 WTS_SESSION_INFO[] sessionInfo = new WTS_SESSION_INFO[count];

  for (int index = 0; index < count; index++)
      sessionInfo[index] = Marshal.PtrToStructure(buffer +
(sizeof(WTS_SESSION_INFO) * index), typeof(WTS_SESSION_INFO));

I get an error at  - sizeof(WTS_SESSION_INFO) - 'WTS_SESSION_INFO' is a type
and cannot be used as an expression.

Can someone help
Mattias Sj?gren - 29 Dec 2004 11:04 GMT
Nikolay,

>I get an error at  - sizeof(WTS_SESSION_INFO) - 'WTS_SESSION_INFO' is a type
>and cannot be used as an expression.

Replace sizeof(WTS_SESSION_INFO) with
Marshal.SizeOf(GetType(WTS_SESSION_INFO)).

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nikolay Petrov - 29 Dec 2004 11:41 GMT
Thanks Mattias

however a new error has occured:
Operator '+' is not defined for types 'System.IntPtr' and 'Integer'.
at -  buffer + (sizeof(GetType(WTS_SESSION_INFO)) * index
I can see why this happend, but how to fix it? In sample it was given this
way.
My guess is that with every itteration in for statement the code tryes to
increment the pointer, it fails because it is done by adding an integer.
What should be added to the pointer to find the new pointer of next
WTS_SESSION_INFO structure?

> Nikolay,
>
[quoted text clipped - 6 lines]
>
> Mattias
Mattias Sj?gren - 29 Dec 2004 12:17 GMT
>I can see why this happend, but how to fix it?

You can convert the IntPtr to an Integer with its ToInt32 method. You
can go the other way with the IntPtr constructor taking an Integer.
Since you can't do arithmetic directly on IntPtrs you have to do this
roundtripping. Something like

Dim ptr As Integer = buffer.ToIn32()
Dim wtssiSize As Integer = Marshal.SizeOf(GetType(WTS_SESSION_INFO))
For ...
 sessionInfo(index) = Marshal.PtrToStructure(New IntPtr(ptr),
GetType(WTS_SESSION_INFO));
 ptr += wtssiSize
Next

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nikolay Petrov - 29 Dec 2004 12:57 GMT
Tnanks Mattias, that works perfectly.

I'll going to post my code in web, once it's done, because i'vs searched
half an year of way to use terminal services APIs.

thanks again

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.