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 / Languages / Managed C++ / December 2006

Tip: Looking for answers? Try searching our database.

How do I call WTSOpenServer in VC++?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Adam - 07 Dec 2006 20:59 GMT
This is my first attempt at using the Terminal Services API, and I'm
stumped.  I can't get WTSOpenServer to work for the life of me (this is
in VS2005, by the way).  Specifically, the argument has me baffled.
It's my understanding that it wants a LPWSTR (at least on this machine,
where UNICODE is defined).  My first attempt was:

HANDLE hnd = WTSOpenServer("asdf");

Which yielded:
error C2664: 'WTSOpenServerW' : cannot convert parameter 1 from 'const
char [5]' to 'LPWSTR'

Fine.  So I tried:

HANDLE hnd = WTSOpenServer(A2T("asdf"));

Which pukes up:
error LNK2028: unresolved token (0A000415) "extern "C" void * __stdcall
WTSOpenServerW(wchar_t *)" (?WTSOpenServerW@@$$J14YGPAXPA_W@Z)
referenced in function "private: void __clrcall
test::Form1::Form1_Load(class System::Object ^,class System::EventArgs
^)"
(?Form1_Load@Form1@test@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
    test.obj

error LNK2019: unresolved external symbol "extern "C" void * __stdcall
WTSOpenServerW(wchar_t *)" (?WTSOpenServerW@@$$J14YGPAXPA_W@Z)
referenced in function "private: void __clrcall
test::Form1::Form1_Load(class System::Object ^,class System::EventArgs
^)"
(?Form1_Load@Form1@test@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
    test.obj

HANDLE hnd = WTSOpenServer(A2W("asdf")); gave the same results.

Can anyone tell me what on earth I'm doing wrong?  I've been googling
for days, and I'm sure it can't be this difficult.  Any help is
appreciated.  And if I'm in the wrong group, please accept my
apologies.

Adam
Willy Denoyette [MVP] - 08 Dec 2006 09:56 GMT
> This is my first attempt at using the Terminal Services API, and I'm
> stumped.  I can't get WTSOpenServer to work for the life of me (this is
[quoted text clipped - 37 lines]
>
> Adam

.... WTSOpenServer(L"asdf");

Willy.
Ben Voigt - 11 Dec 2006 18:24 GMT
> Can anyone tell me what on earth I'm doing wrong?  I've been googling
> for days, and I'm sure it can't be this difficult.  Any help is
> appreciated.  And if I'm in the wrong group, please accept my
> apologies.

As Willy says, you can directly use L"string" to get a unicode string
literal, no point in converting from ANSI at runtime.

But your linker error will only be resolved when you add WtsApi32.lib to
your project properties under "Linker -> Inputs".

See the doc page:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/termserv/termse
rv/wtsopenserver.asp

The Requirements section clearly shows the header file and import library
needed.

> Adam
Adam - 12 Dec 2006 19:35 GMT
Yes, that was the problem - I had neglected to include the .lib.  Thank
you.  I feel like an idiot.

Adam

> > Can anyone tell me what on earth I'm doing wrong?  I've been googling
> > for days, and I'm sure it can't be this difficult.  Any help is
[quoted text clipped - 13 lines]
>
> > Adam

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.