How do I call WTSOpenServer in VC++?

  • Thread starter Thread starter Adam
  • Start date Start date
A

Adam

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
 
Adam said:
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


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

Willy.
 
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/termserv/wtsopenserver.asp
The Requirements section clearly shows the header file and import library
needed.
 
Yes, that was the problem - I had neglected to include the .lib. Thank
you. I feel like an idiot.

Adam
 
Back
Top