> 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:
>
[quoted text clipped - 4 lines]
>
> 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.

Signature
Kind regards,
Bruno.
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"
Newbie Coder - 06 Mar 2007 12:45 GMT
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

Signature
Newbie Coder
(It's just a name)
Bruno van Dooren [MVP VC++] - 06 Mar 2007 14:04 GMT
> using namespace System::Runtime:InteropServices;
>
[quoted text clipped - 10 lines]
> 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.

Signature
Kind regards,
Bruno.
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"
Ben Voigt - 06 Mar 2007 16:22 GMT
>> using namespace System::Runtime:InteropServices;
>>
[quoted text clipped - 15 lines]
> 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.
> 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 [MVP VC++] - 07 Mar 2007 11:36 GMT
> 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.

Signature
Kind regards,
Bruno.
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"
Newbie Coder - 07 Mar 2007 12:38 GMT
Yes, it is C++.NET 2003 which I am using

Signature
Newbie Coder
(It's just a name)
Ben Voigt - 07 Mar 2007 22:43 GMT
>> That is C++, not C# (note the :: scope operator). C++/CLI supports
>> explicit
[quoted text clipped - 6 lines]
> 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.