1

I'm creating a C++ WinRT runtime component using Visual Studio 2022. I want to use functions like PeekMessage() to handle a basic message loop. However, I get the following errors:

error C3861: 'PeekMessage': identifier not found

I already have #include <Windows.h> at the top of the file, and I've also added #pragma comment(lib, "User32.lib").

Are there any limitations that prevent PeekMessage() from being used in a C++ WinRT component? If so, is there any workaround or recommended approach to use these APIs in this environment?

4
  • The OP' deleted question stackoverflow.com/questions/79687051/… Commented Jul 2 at 8:50
  • RTM PeekMessageA function (winuser.h): Windows 2000 Professional [desktop apps only]. Commented Jul 2 at 8:52
  • @3CEZVQ A desktop API can be called from a Windows Runtime component. Commented Jul 2 at 8:56
  • My previous question unintentionally focused on MessageBox, so I rewrote it to better reflect my intent; adding #undef WINAPI_FAMILY and #define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP in the WinRT component fixed the issue because the original setting was for UWP, but I want to use it with WinUI 3 in C#. Commented Jul 2 at 9:40

1 Answer 1

1
#undef WINAPI_FAMILY  
#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP

in the WinRT component, it worked correctly. The original setting was for UWP, but I want to use it with WinUI 3 in C#.

Sign up to request clarification or add additional context in comments.

2 Comments

Rather than fiddling with preprocessor symbols consider updating your MSBuild input (.vcxproj).,
Thank you for your advice. I found the relevant section in the .vcxproj file and was able to fix it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.