Hi,
I'd be happy to help you out with your question. Sorry for the inconvenience caused.
The error C2338 in C++/WinRT indicates a mismatch between the expected parameter type and the actual type provided when using the then method. In your case, the issue lies in the line where you call create_task(session.RequestExtensionAsync()).then(this.
To resolve this error, you need to modify the lambda function to match the expected parameter type. The then method expects a callable object that takes a parameter of type concurrency::task<T>, where T is the expected return type. In your code, you are providing a lambda function that takes a parameter of type ExtendedExecutionResult, causing the type mismatch.
To fix this, you should update the lambda function to take a parameter of type concurrency::task<ExtendedExecutionResult>. Here's the updated code:
IAsyncAction App::BeginExtendedExecution(ExtendedExecutionSession session, SuspendingDeferral deferral, event_token revokedToken) { create_task(session.RequestExtensionAsync()).then(this { ExtendedExecutionResult result = resultTask.get(); // Save the settings that have not been saved when exiting. switch (result) { case ExtendedExecutionResult::Allowed: // Save settings that have changed. // You can use a MessageDialog to ask the user if they want to save settings. break; case ExtendedExecutionResult::Denied: // Just save the settings without asking the user. break; default: break; } }).then(this, session, deferral, revokedToken { // Handle closing the session. if (session != nullptr) { // Revoke the handler. session.Revoked(revokedToken); session.Close(); session = nullptr; } // Handle deferral completion. if (deferral != nullptr) { deferral.Complete(); deferral = nullptr; } }); }
By making these modifications, you ensure that the lambda function's parameter type matches the expected type, resolving the error.
Please ensure that you have included the necessary headers for the concurrency namespace and that you have set up the required dependencies correctly in your project.
If you have any other questions or need assistance with anything, please don't hesitate to let me know. I'm here to help.
If the reply was helpful, please don’t forget to upvote or accept as answer, thank you.