LockWorkStation Function

  • Thread starter Thread starter Newbie Coder
  • Start date Start date
N

Newbie Coder

How do I lock a Windows 2000 machine in Visual C++.NET 7.1?

#include <windows.h>

bool LockWorkStation()

If I do it fails:

bool LockWorkStation()
{
return true;
}

if doesn't work.

Plus, I'd like to add an IF statement to check if Windows version is Windows
2000 or later then call the LockWorkStation function

Any ideas please?
 
How do I lock a Windows 2000 machine in Visual C++.NET 7.1?
#include <windows.h>

bool LockWorkStation()

Why do you declare this function? it is already declared in windows.h
If I do it fails:

bool LockWorkStation()
{
return true;
}

if doesn't work.

???? what is the point of implementing your own function that returns true?
what did you think it would do?
Plus, I'd like to add an IF statement to check if Windows version is Windows
2000 or later then call the LockWorkStation function

if you use that function in your program, it simply won't run on any OS pre
win2000. The exe will fail with a 'missing entry point' message box or
something like that.

The only way you can do that is by loading user32.dll manually, then using
getprocaddress to find that function, and only call that function if you
found it.
 
Bruno

I called the function like so:

using namespace System::Runtime:InteropServices;

[DllImport("user32.dll")]
int LockWorkStation();

Then called it like so:

if (rdoLock)
{
LockWorkStation();
}

Just need to work out the OS version now. In VB.NET I know. Maybe I will
write in VB.NET & convert it

Thanks for you reply, Bruno
 
using namespace System::Runtime:InteropServices;
[DllImport("user32.dll")]
int LockWorkStation();

Then called it like so:

if (rdoLock)
{
LockWorkStation();
}

Just need to work out the OS version now. In VB.NET I know. Maybe I will
write in VB.NET & convert it

I hadn't understood that you are using C#.
For C# questions you' be better off posting to the csharp newsgroup. This is
the C++ newsgroup.

anyway, you could do it the other way around: surround the function call
with a try / catch, and catch the 'EntryPoint not found exception' (don't
know its type).
If you get an exception you can handle the per win2K cases.
 
Bruno van Dooren said:
using namespace System::Runtime:InteropServices;

[DllImport("user32.dll")]
int LockWorkStation();

Then called it like so:

if (rdoLock)
{
LockWorkStation();
}

Just need to work out the OS version now. In VB.NET I know. Maybe I will
write in VB.NET & convert it

I hadn't understood that you are using C#.
For C# questions you' be better off posting to the csharp newsgroup. This
is
the C++ newsgroup.

That is C++, not C# (note the :: scope operator). C++/CLI supports explicit
P/Invoke same as C#, it's not usually as useful as native imports, but
conditional usage is one of the advantages, since it essentially wraps the
LoadLibrary and GetProcAddress calls for you.
 
That is C++, not C# (note the :: scope operator). C++/CLI supports explicit
P/Invoke same as C#, it's not usually as useful as native imports, but
conditional usage is one of the advantages, since it essentially wraps the
LoadLibrary and GetProcAddress calls for you.

I didn't know that C++/CLI supported the DllImport feature.
As soon as I saw that I didn't notice the :: anymore.
Good call. Thanks.
 
Bruno van Dooren said:
I didn't know that C++/CLI supported the DllImport feature.
As soon as I saw that I didn't notice the :: anymore.
Good call. Thanks.

It's not dependant on support from the language compiler as far as I know.
Whenever the attribute is placed in the MSIL and seen by the JIT compiler
the runtime will implement P/Invoke regardless of source language.
 
Back
Top