Thread View: borland.public.cppbuilder.nativeapi
13 messages
13 total messages
Started by Mike Collins
Thu, 17 Apr 2008 14:13
using WTSGetActiveConsoleSessionId()
Author: Mike Collins
Date: Thu, 17 Apr 2008 14:13
Date: Thu, 17 Apr 2008 14:13
16 lines
1512 bytes
1512 bytes
Hay guys, hope everyone is well. Can anyone point me in the right direction here. I'm trying to launch an application on the active users desktop from a service. I'm looking at a code snippet from MSDN that uses WTSQueryUserToken / WTSGetActiveConsoleSessionId to determine the active UI session. Problem is that the compiler keeps telling me that WTSGetActiveConsoleSessionId() is an undefined function. It's declared in winbase.h and i've included both windows.h and winbase.h but to no avail. I'm using BCB 6 Enterprise... many thanks in advance, Mike
Re: using WTSGetActiveConsoleSessionId()
Author: Ed Mulroy [TeamB]
Date: Thu, 17 Apr 2008 13:43
Date: Thu, 17 Apr 2008 13:43
41 lines
2721 bytes
2721 bytes
Go to the compiler's LIB directory and give this command
tlib /C import32.LIB , import32.LST
The list of exported items provided by import32.lib will be found in the
list file. Pull the list file up in the editor. Verify that among those
items is WTSGetActiveConsoleSessionId and that it is listed as being
provided by kernel32.dll, a Windows DLL.
It is possible that an option setting in the IDE could alter the expected
public name for WTSGetActiveConsoleSessionId. Try using tdump on the object
file and looking at the exact text for WTSGetActiveConsoleSessionId. If it
has added leading or trailing characters or the case is different then it
will not match. The solution is to restore the IDE options because
different naming implies different calling conventions, something which can
cause the program to fail.
If the symbol is correct you could try to provide your own import library.
Go to the command line and change to the project directory.
Give this command:
implib -c kernel32.LIB c:\windows\system32\kernel32.DLL
Go back into the IDE and add kernel32.lib to the project file.
. Ed
> Mike Collins wrote in message
> news:48074a72@newsgroups.borland.com...
>
> Hay guys, hope everyone is well.
>
> Can anyone point me in the right direction here. I'm trying to launch an
> application on the active users desktop from a service.
>
> I'm looking at a code snippet from MSDN that uses WTSQueryUserToken /
> WTSGetActiveConsoleSessionId to determine the active UI session. Problem
> is that the compiler keeps telling me that WTSGetActiveConsoleSessionId()
> is an undefined function. It's declared in winbase.h and i've included
> both windows.h and winbase.h but to no avail.
>
> I'm using BCB 6 Enterprise...
Re: using WTSGetActiveConsoleSessionId()
Author: Mike Collins
Date: Thu, 17 Apr 2008 14:35
Date: Thu, 17 Apr 2008 14:35
7 lines
1117 bytes
1117 bytes
Just to follow up, I can't use WTSQueryUserToken either. I've included the WtsApi32 header but now it's complaining about unresolved external WTSQueryUserToken. Again, any ideas or pointers would be helpful... Mike C
Re: using WTSGetActiveConsoleSessionId()
Author: Mike Collins
Date: Thu, 17 Apr 2008 15:15
Date: Thu, 17 Apr 2008 15:15
66 lines
3737 bytes
3737 bytes
Hay Ed thanks for the pointer, I actually resolved it by dynamically loading
it, like this:
typedef DWORD (WINAPI *WTSGETACTIVECONSOLESESSIONID)(VOID);
WTSGETACTIVECONSOLESESSIONID lpfnWTSGetActiveConsoleSessionId = NULL;
lpfnWTSGetActiveConsoleSessionId =
(WTSGETACTIVECONSOLESESSIONID)GetProcAddress(GetModuleHandle("kernel32.dll"),
"WTSGetActiveConsoleSessionId");
The project that i'm calling it from is a gina and i had to do some playing
around to get the dll to export the named functions correctly i.e.
extern "C"
{
#include <winwlx.h>
};
otherwise winlogon would not load it correctly - maybe this is the cause.
However, I still stuck with the WTSQueryUserToken issue. Any thoughts?
"Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> wrote in message
news:48075419$1@newsgroups.borland.com...
> Go to the compiler's LIB directory and give this command
>
> tlib /C import32.LIB , import32.LST
>
> The list of exported items provided by import32.lib will be found in the
> list file. Pull the list file up in the editor. Verify that among those
> items is WTSGetActiveConsoleSessionId and that it is listed as being
> provided by kernel32.dll, a Windows DLL.
>
> It is possible that an option setting in the IDE could alter the expected
> public name for WTSGetActiveConsoleSessionId. Try using tdump on the
> object file and looking at the exact text for
> WTSGetActiveConsoleSessionId. If it has added leading or trailing
> characters or the case is different then it will not match. The solution
> is to restore the IDE options because different naming implies different
> calling conventions, something which can cause the program to fail.
>
> If the symbol is correct you could try to provide your own import library.
>
> Go to the command line and change to the project directory.
> Give this command:
> implib -c kernel32.LIB c:\windows\system32\kernel32.DLL
> Go back into the IDE and add kernel32.lib to the project file.
>
> . Ed
>
>> Mike Collins wrote in message
>> news:48074a72@newsgroups.borland.com...
>>
>> Hay guys, hope everyone is well.
>>
>> Can anyone point me in the right direction here. I'm trying to launch an
>> application on the active users desktop from a service.
>>
>> I'm looking at a code snippet from MSDN that uses WTSQueryUserToken /
>> WTSGetActiveConsoleSessionId to determine the active UI session. Problem
>> is that the compiler keeps telling me that WTSGetActiveConsoleSessionId()
>> is an undefined function. It's declared in winbase.h and i've included
>> both windows.h and winbase.h but to no avail.
>>
>> I'm using BCB 6 Enterprise...
>
>
Re: using WTSGetActiveConsoleSessionId()
Author: Ed Mulroy [TeamB]
Date: Thu, 17 Apr 2008 15:50
Date: Thu, 17 Apr 2008 15:50
42 lines
2381 bytes
2381 bytes
From MSDN, http://msdn2.microsoft.com/en-us/library/aa383840.aspx,
WTSQueryUserToken is in wtsapi32.dll You need an import library for that
dll. BCB verision 6 is old and I think the wtsapi32.lib in the compiler's
LIB\PSDK directory is out of date.
Screen capture:
=========================
C:\Program Files\Borland\CBuilder6\Lib
>implib -c wtsapi32.LIB \windows\system32\wtsapi32.dll
Borland Implib Version 3.0.22 Copyright (c) 1991, 2000 Inprise Corporation
C:\Program Files\Borland\CBuilder6\Lib
>tlib /C wtsapi32.LIB , wtsapi32.LST
TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation
C:\Program Files\Borland\CBuilder6\Lib
>grep WTSQueryUserToken wtsapi32.lst
File wtsapi32.lst:
WTSQueryUserToken size = 0
WTSQueryUserToken
C:\Program Files\Borland\CBuilder6\Lib
>
=========================
So make the import library and add it to the project. Do not be reluctant
to do this. When you do this you are not adding something odd and not
maintainable. You are adding an item which is from Windows itself. Heck,
even the MSDN docs say to use that import library.
. Ed
> Mike Collins wrote in message
> news:48074fc0@newsgroups.borland.com...
>
> Just to follow up, I can't use WTSQueryUserToken either. I've included
> the WtsApi32 header but now it's complaining about unresolved external
> WTSQueryUserToken.
>
> Again, any ideas or pointers would be helpful...
Re: using WTSGetActiveConsoleSessionId()
Author: Ed Mulroy [TeamB]
Date: Thu, 17 Apr 2008 16:06
Date: Thu, 17 Apr 2008 16:06
43 lines
3016 bytes
3016 bytes
WTSQueryUserToken is dealt with in another reply.
As you most likely already know, most of the Windows headers are
modifications of ones provided by Microsoft (they copyrighted the API and
have sued companies who independently developed their own headers). I can
confirm what you found from what is on my machine. The winwlx.h header does
not have an extern "C" guard. However the wtsapi32.h header does have it.
WTSGetActiveConsoleSessionId is, as mentioned before, found in import32.lib,
a library which the IDE includes by default in a build. If you are building
from the command line then check that import32.lib is included in the list
of libraries used in the link phase.
There is nothing odd, questionable or wrong with your explicit linking of
WTSGetActiveConsoleSessionId. What you did merely duplicates what the
Windows loader does when implicitly linking via an import library. In fact
it might actually speed loading of your gina dll if the function is called a
lot because the loader doesn't have to fix up the function address at each
point where WTSGetActiveConsoleSessionId is called.
. Ed
> Mike Collins wrote in message
> news:480758e5@newsgroups.borland.com...
>
> Hay Ed thanks for the pointer, I actually resolved it by dynamically
> loading it, like this:
>
> typedef DWORD (WINAPI *WTSGETACTIVECONSOLESESSIONID)(VOID);
> WTSGETACTIVECONSOLESESSIONID lpfnWTSGetActiveConsoleSessionId = NULL;
> lpfnWTSGetActiveConsoleSessionId =
> (WTSGETACTIVECONSOLESESSIONID)GetProcAddress(GetModuleHandle("kernel32.dll"),
> "WTSGetActiveConsoleSessionId");
>
> The project that i'm calling it from is a gina and i had to do some
> playing around to get the dll to export the named functions correctly i.e.
> extern "C"
> {
> #include <winwlx.h>
> };
>
> otherwise winlogon would not load it correctly - maybe this is the cause.
> However, I still stuck with the WTSQueryUserToken issue. Any thoughts?
Re: using WTSGetActiveConsoleSessionId()
Author: Ed Mulroy [TeamB]
Date: Thu, 17 Apr 2008 16:08
Date: Thu, 17 Apr 2008 16:08
37 lines
2636 bytes
2636 bytes
> When you said, use tdump on the object file, which object file did you > mean? The object file whose code calls the function in question. The idea is to use tdump to learn the exact text of the symbol associated with the call to the function. That means -m should be on the tdump command line so that you can also see if there is any C++ style name mangling of the public symbol. . Ed > Mike Collins wrote in message > news:480766b2$1@newsgroups.borland.com... > > Hay Ed, just a quick follow up, I've done as you suggested - becuase i now > have three functions that aren't linking. > > WTSGetActiveConsoleSessionId is listed under kernal32.dll from the tlib > dump > WTSQueryUserToken is not listed > CreateEnvironmentBlock is not listed (the 3rd funciton that is not > linking) > > When you said, use tdump on the object file, which object file did you > mean? > > I'm disinclined to to create a lib file and use it in the project becuase > it AFAIK ties the program in to those funciton (sorry if this sounds > stupid lol) and the WTSQueryUserToken is not avalible on Win 2k so i > suspect that it will cause problems (I'll have to work out an alternative > route for win 2k anyway). > > I can't track down what IDE option might be causing this issue. The only > define that i have is the NO_WIN32_LEAN_AND_MEAN and i've tried removing > that but it doesn't have any affect. > > Any other thoughts? I can dyncamically load the three functions but it's > a bit concerning that i can't use them...
Re: using WTSGetActiveConsoleSessionId()
Author: Mike Collins
Date: Thu, 17 Apr 2008 16:13
Date: Thu, 17 Apr 2008 16:13
30 lines
2139 bytes
2139 bytes
Hay Ed, just a quick follow up, I've done as you suggested - becuase i now have three functions that aren't linking. WTSGetActiveConsoleSessionId is listed under kernal32.dll from the tlib dump WTSQueryUserToken is not listed CreateEnvironmentBlock is not listed (the 3rd funciton that is not linking) When you said, use tdump on the object file, which object file did you mean? I'm disinclined to to create a lib file and use it in the project becuase it AFAIK ties the program in to those funciton (sorry if this sounds stupid lol) and the WTSQueryUserToken is not avalible on Win 2k so i suspect that it will cause problems (I'll have to work out an alternative route for win 2k anyway). I can't track down what IDE option might be causing this issue. The only define that i have is the NO_WIN32_LEAN_AND_MEAN and i've tried removing that but it doesn't have any affect. Any other thoughts? I can dyncamically load the three functions but it's a bit concerning that i can't use them... Thanks again, Mike "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> wrote in message news:48075419$1@newsgroups.borland.com...
Re: using WTSGetActiveConsoleSessionId()
Author: Remy Lebeau (TeamB)
Date: Thu, 17 Apr 2008 16:48
Date: Thu, 17 Apr 2008 16:48
15 lines
1375 bytes
1375 bytes
"Mike Collins" <its@TheBottomOfThePost> wrote in message news:48074a72@newsgroups.borland.com... > Problem is that the compiler keeps telling me that > WTSGetActiveConsoleSessionId() is an undefined > function. <snip> > I'm using BCB 6 Enterprise... You have to re-define _WIN32_WINNT to be 0x0501 or higher. It is set to 0x0500 by default. Gambit
Re: using WTSGetActiveConsoleSessionId()
Author: Bob Gonder
Date: Thu, 17 Apr 2008 17:55
Date: Thu, 17 Apr 2008 17:55
11 lines
1393 bytes
1393 bytes
Mike Collins wrote: >Does it matter where you redefine it? Yes. It must be defined prior to reading the header that uses it, or it will do no good. #define _WIN32_WINNT 0x0501 #include <vcl.h> #pragma hdrstop
Re: using WTSGetActiveConsoleSessionId()
Author: Mike Collins
Date: Thu, 17 Apr 2008 18:38
Date: Thu, 17 Apr 2008 18:38
15 lines
1302 bytes
1302 bytes
Does it matter where you redefine it? I stuck it at the begining of my DLL's code but it makes no difference, it still won't compile... #include <vcl.h> #pragma hdrstop #define _WIN32_WINNT 0x0501 thanks, mike "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:48077f50$1@newsgroups.borland.com... >
Re: using WTSGetActiveConsoleSessionId()
Author: Remy Lebeau (TeamB)
Date: Thu, 17 Apr 2008 19:06
Date: Thu, 17 Apr 2008 19:06
16 lines
1571 bytes
1571 bytes
"Mike Collins" <its@TheBottomOfThePost> wrote in message news:480788ac@newsgroups.borland.com... > Does it matter where you redefine it? Do it in the Conditionals area of the Project Options. > I stuck it at the begining of my DLL's code but it > makes no difference, it still won't compile... Because you are defining it too late in the code. The winbase.h header file has already been processed before the compiler sees your define. Gambit
Re: using WTSGetActiveConsoleSessionId()
Author: Mike Collins
Date: Thu, 17 Apr 2008 21:40
Date: Thu, 17 Apr 2008 21:40
23 lines
1869 bytes
1869 bytes
Happy days at the farm... That is certainly much easier than using GetProcAddress. I stuck it in the conditionals of the project options, thought I didn't initially realise that you had to use the = sign in-between the name and the value i.e. _WIN32_WINNT=0x0501. Believe it or not, I did consider that the _WIN32_WINNT must be incorrect when i first tried to use the functions because in the winbase.h the functions are only declared within the _WIN32_WINNT defs. But i stuck in the re-definition where i was trying to use it as opposed to in the conditionals like you have suggested. Once again, thanks to both of you guys. Sure I'll be posting again in a few hours when the code doesn't actually work lol Have a good day, Mike "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads