I currently am using asynchronous callback to get the motion data through Window's Sensor API. For now I want to test the functionalities through a Windows 10 Console application (NOT a Windows Application). To simplify things, I am currently having the exact same problem as How to cause my C++ program to wait for sensor events for ever and not terminate, where
while(true) { hr = sensor->SetEventSink(pMyEvents); }
fires the event and I get consistent data, but the proper usage should be just
hr = sensor->SetEventSink(pMyEvents);
, which will trigger the event asynchronously.
I also used CoInitializeEx(NULL, COINIT_MULTITHREADED);
to allow multithreading in COM.
In the comments in the above SO link, two users mention that "You're forgetting the Windows message event loop." I do not want to have a graphical interface for this program, and more importantly I do not get why "COM will not work without a message loop." This seems to apply only for Windows Application Projects. Could someone elaborate on this, and how to properly use SetEventSink(ISensorEvent)
to keep receiving the data for a regular console application?
I have confirmed that other code such as for initialization/decoding dataworks by using the synchronous method - GetData()
.