WinUI3 : How to use DispatcherQueue without Lambda function to exec a parameterized function

Harshithraj1871 1,516 Reputation points
2023-11-16T10:28:21.54+00:00

Hi,

Im working on a WinUI3 desktop application in CPP without using XAML files.

In my application, I'm using the Dispatcher queue to switch from the worker thread to the main thread.

int winid = 1;

DispatcherQueueHandler      executeinstructiondispatch = [=] () {	TWOSInstructionHandler::ExecuteInstructionSet (winid);
}

TWWinUI3App::sDispatcherQueue.TryEnqueue (executeinstructiondispatchhandler);    

Here to execute a parameterized function in the main thread, Im using the Lambda function.

For some reason, I do not want to use any Lambda functions in my application. Is there any way to make this peace of code work without the Lambda function?

I could have done this if it was not a parameterized function,

DispatcherQueueHandler      executeinstructiondispatch = TWOSInstructionHandler::ExecuteInstructionSet;

In the case of a parameterized function, is there a way to use Dispatcher Queue without the lambda function?

Thank you

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
748 questions
{count} votes

Accepted answer
  1. Xiaopo Yang - MSFT 12,151 Reputation points Microsoft Vendor
    2023-11-28T08:14:04.2833333+00:00

    As far as I'm concerned, it's not supported for C++/WinRT to enable passing functions with parameters. You can also use a Lambda function to wrap these functions except std::bind.

    0 comments No comments

0 additional answers

Sort by: Most helpful