开发者

Link User32 with gcc

I have a C program which has a function call that is defined in windows.h (which I have included), however, when I try and compile it with gcc, I get the error:

warning: implicit declaration of function `LockWorkStation'

I looked at the MSDN documentation and I see that this function is the User32 library file, and I was wondering how I would go about linking 开发者_如何学Pythonthat to my file.


LockWorkstation is available on Windows 2000 and up. You have to declare the version of Windows you are targeting. Make it look like this:

#define _WIN32_WINNT 0x500
#include <windows.h>


I have the same problem with gcc - but this is not a linker error. The message means that there is no prototype for the function in winuser.h, or more accurately the compiler can't find such a prototype. That is because the relevant bit of winuser.h looks like this:

#if (_WIN32_WINNT >= 0x0500)
WINUSERAPI BOOL WINAPI LockWorkStation(void);
#endif

In other words, you need a version of Windows >= 5 (i.e Win2K) to use this function. I'm currently trying this on Win2K and it doesn't work, which indicates the macro is not being set correctly. I don't do much "real" Windows programming these days, so I'm not sure why that should be.

Edit: In fact, a bit of experiment indicates that gcc thinks the Windows version of Win2K (on my installation at least) is 0x0400.

Further: Actually, the macro _WIN32_WINNT is (as the leading underscore suggests) a reserved name in C and C++, and should not be defined in user code. Defining the macro WINVER seems to have the same effect, and is (conceptually at least) more portable. This code compiles on my gcc installation:

#define WINVER 0x0500
#include <windows.h>
int main() {
    LockWorkStation();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜