Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using WTSAPI32.DLL on Windows 2000

173 views
Skip to first unread message

a.aka

unread,
Feb 2, 2007, 6:16:00 AM2/2/07
to
Hello all,
this sample code using WTSAPI32.DLL in visual c++ works perfectly on Win XP
but display an error message on Windows 2000. The error I get is
ERROR_APP_WRONG_OS (The specified program is not a Windows or MS-DOS
program.) What does this mean ? What are the diffrences between Win2K and Win
2003 for WTSQuerySessionInformation.

Thank you for your help.

/**************************************************/
CString GetTSClientAddress( DWORD sessionID /* = (DWORD) -1*/ )
{
LPTSTR ppBuffer = NULL;
DWORD pBytesReturned = 0;
PWTS_CLIENT_ADDRESS pWTSCA = NULL;
if (sessionID == (DWORD) -1) sessionID = WTS_CURRENT_SESSION;

CString clientFamilyAndAddress; clientFamilyAndAddress.Empty();

LPWTSQuerySessionInformation pWTSQuerySessionInformation = NULL;
LPWTSFreeMemory pWTSFreeMemory = NULL;

HINSTANCE WTSApiDll = LoadLibrary("WTSAPI32.DLL");
if (WTSApiDll)
{
pWTSQuerySessionInformation =
(LPWTSQuerySessionInformation) GetProcAddress(WTSApiDll,
"WTSQuerySessionInformationA");
pWTSFreeMemory = (LPWTSFreeMemory) GetProcAddress(WTSApiDll,
"WTSFreeMemory");

}
if (WTSApiDll == NULL || pWTSQuerySessionInformation == NULL ||
pWTSFreeMemory == NULL)
{
if (WTSApiDll != NULL) FreeLibrary(WTSApiDll);
if (IsSystemTerminalServer())
{
AfxMessageBox("Unable to load WTSAPI32.DLL.\r\nPlease contact support");
}
return clientFamilyAndAddress;
}

BOOL b = (*pWTSQuerySessionInformation)( WTS_CURRENT_SERVER_HANDLE,
sessionID,
WTSClientAddress,
&ppBuffer,
&pBytesReturned);

if (b) {
/* other instructions */

(*pWTSFreeMemory)( ppBuffer );
}
else
{
if (IsSystemTerminalServer()){
DWORD dwError = GetLastError();
CString csError;
ErrorToString(dwError, csError);

csError.Insert(0,"Query TSE client info failed.\r\n");

AfxMessageBox(csError, MB_ICONINFORMATION);
}

}

if (WTSApiDll != NULL) FreeLibrary(WTSApiDll);
return clientFamilyAndAddress;
}

Soo Kuan Teo [MSFT]

unread,
Feb 7, 2007, 12:56:57 AM2/7/07
to
Just curious, did you recompile a different executable for Win2000?


--
This posting is provided "AS IS" with no warranties, and confers no rights.
"a.aka" <aa...@discussions.microsoft.com> wrote in message
news:851F0502-D29E-4530...@microsoft.com...

a.aka

unread,
Feb 8, 2007, 4:20:01 AM2/8/07
to
No, I use the same EXE for all platforms. Why this question ?

Soo Kuan Teo [MSFT]

unread,
Feb 8, 2007, 12:59:51 PM2/8/07
to
Just my speculation, it may be that your application is build for XP/Win2003
OS (assuming it is x86 32bit platform), and you try to run it on Windows
2000.

Thanks
Soo Kuan


--
This posting is provided "AS IS" with no warranties, and confers no rights.
"a.aka" <aa...@discussions.microsoft.com> wrote in message

news:7404053F-3969-447B...@microsoft.com...

a.aka

unread,
Feb 9, 2007, 5:01:01 AM2/9/07
to
Hello Soo Kuan,

My application supports all windows platform since Windows 95. And to make
sure that using WTSAPI32.DLL will not cause trouble, I make a LoadLibrary and
if this call fails, I suppose that the platform doesn't support Terminal
services API. The problem I describe is that : on some Windows 2000 Server
machine, the LoadLibrary succeeded but when I call the
"WTSQuerySessionInformation" function (after having done a GetProcAddress),
it returns a curious error : ERROR_APP_WRONG_OS. I was able to make my
application run on another Windows 2000 Server. I'd like to know if there is
a minimum requirement to have WTSAPI32.DLL work on Windows 2000 (like service
pack or other thing).
Thank you.
A.AKA

Soo Kuan Teo [MSFT]

unread,
Feb 15, 2007, 12:59:21 PM2/15/07
to
Interesting. that's a very impressive work that you can create a single
binary that works from 16-bit win95 all the way to 32/64 bit XP.
To rule out any compatibility issues, if possible, I would suggest to build
a native win2000 binary to see if you still encounter this issue.
Just quickly scanning your code, you're using LPTSTR and calling the Ansi
function of WTSWTSQuerySessionInformation (WTSQuerySessionInformationA). Did
you explicitly build your binary as non-unicode?
Thanks
Soo Kuan

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"a.aka" <aa...@discussions.microsoft.com> wrote in message

news:1D9DFEBA-4DF6-4025...@microsoft.com...

a.aka

unread,
Feb 16, 2007, 3:28:00 AM2/16/07
to
My application is built with Visual Studio 2003. And I use MFC which is
supported by Win95 to XP. Am I wrong if I say Win 95 is 32-bit ? I did not
test it on XP 64-bits platform.
I had the same doubt about UNICODE and NON-UNICODE and I already checked
whether I use the right version of WTSWTSQuerySessionInformation. The answer
is YES : my binary is non-unicode.
And, as I have already pointed out, the application runs perfectly on a PC
with Win 2000 SP3. Unfortunately, I cannot give you at the moment the SP
number on the wrong machine.
0 new messages