Answered by:
Consume WinJS.Promise (or equivalent) in C++ code

Question
-
I'm writing and a hybrid application in JavaScript/HTML5 for UI and C++ for backend processing. At one point I need to generate a user prompt from the C++ code and have it wait for user response.
When initializing my C++ object I pass a JavaScript callback function that takes prompt parameters and returns a WinJS.Promise that is fulfilled when the user responds. However call to that function fails in C++ with exception 0x800A000D (type mistmatch).
I assume that it is related to me trying to return a promise.
I've tried these function signatures and both don't work
IAsyncOperation<int>^ promptCallbackType(Platform::String^ text);
Platform::Object^ promptCallbackType(Platform::String^ text);
What is the proper way for passing a WinJS.Promise or something functionally equivalent to C++ code?
Tuesday, October 16, 2012 7:21 PM
Answers
-
Hi,
As far as I know, the JavaScript cannot write component, so that we cannot use JS function directly.
But if we want to call JS function, we can use create a event in C++ and then add listen a function for this event. Fire this event in C++, so that the listener will be called in JS.
Best regards,
JesseJesse Jiang [MSFT]
MSDN Community Support | Feedback to us
- Proposed as answer by Chris Guzak Thursday, October 18, 2012 6:24 AM
- Marked as answer by Jesse Jiang Tuesday, October 23, 2012 2:52 AM
Thursday, October 18, 2012 5:36 AM
All replies
-
Hi,
I think this document can help you.
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh755833.aspx
You can follow the codes in that document to call a C++ async function in JS.Also, this document will help you to pass other data type from C++ to JS.
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh441569.aspxBest regards,
JesseJesse Jiang [MSFT]
MSDN Community Support | Feedback to us
Wednesday, October 17, 2012 7:31 AM -
Jesse,
Thank you for the links. I'm actually looking to do the opposite - I need to call a JS async function from C++
Wednesday, October 17, 2012 4:27 PM -
Hi,
As far as I know, the JavaScript cannot write component, so that we cannot use JS function directly.
But if we want to call JS function, we can use create a event in C++ and then add listen a function for this event. Fire this event in C++, so that the listener will be called in JS.
Best regards,
JesseJesse Jiang [MSFT]
MSDN Community Support | Feedback to us
- Proposed as answer by Chris Guzak Thursday, October 18, 2012 6:24 AM
- Marked as answer by Jesse Jiang Tuesday, October 23, 2012 2:52 AM
Thursday, October 18, 2012 5:36 AM