locked
Search Contracts and Initializing DirectX

    Question

  • I have added a Search Contract to my DirectX/XAML Interop app. This works fine if my app is already running. However if Search is called when the app wasn't running, then when the user clicks the default back button on the Search Results Plane, a black screen is produced.

    I assume this is because I haven't run through all the DirectX initialisation. Is there a best practice for this? What event should I respond to, to do this initialisation?

    -Graeme

    Sunday, May 06, 2012 10:54 PM

Answers

  • Thanks for that James.

    I see the bits I missed now. OnRendering was never called and DirectX was not initalised because I have been doing that in my App::OnLaunched() override. But that is only invoked when the Application starts normally.

    If I wanted to set up DirectX from a Search invocation, I could override App::OnSearchActivated(). But really this would be a silly place to do it. I should wait till (or if) my main application surface is called from the search Results page

    Is this what you were understanding?

    Appreciate the help

    Graeme

    • Marked as answer by GraemeBlack Thursday, May 10, 2012 10:37 PM
    Thursday, May 10, 2012 2:57 AM

All replies

  •  

    Hello,

     

    How did you add the search contracts. You can follow this document to add it.

     

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh771180(v=win.10).aspx

    Sample code

    http://code.msdn.microsoft.com/windowsapps/Search-app-extension-sample-6baa6270/sourcecode?fileId=43962&pathId=1462329729

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, May 07, 2012 11:41 AM
    Moderator
  • Hi Jesse,

    I just used "Add Item", added a Search Contract, then followed what I could translate from the JS-oriented guide. (There didn't seem to be a C++ version - only the sample. Your first link is for File Pickers)

    What I would like to do is debug my program when it is initiated from Search. Attach to Process is a bit late in the process. Is there a good way to do this?

    I note that OutputDebugString() doesn't send info to DebugView for Metro Apps yet. Are there any recommended logging libraries?

    Regards Graeme

    Tuesday, May 08, 2012 9:03 PM
  • Hello Graeme,

    I'm heading home for the day but if you still need help with this let me know and I'll take a closer look at it tomorrow afternoon.

    Thanks,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, May 09, 2012 1:15 AM
    Moderator
  • Thanks James,

    I think that there's something a bit wrong the way I have navigation set up. My DirectX rendering page was originally a BlankPage. In the XAML I  removed the Page and replaced it with a SwapChainBackgroundPanel. This means that the LayoutAwarePage behaviour disappeared (including some of the Navigation and the Map-based ViewModel). What I suspect is that when Search calls my application when it isn't already running, it goes directly to the SearchResultsPage, but for some reason thinks it "CanGoBack". I think my DirectX-based page is never referenced and the App never gets it's OnLaunched event handler called (As the template comment for App::OnLaunched() actually says)

    Probably the SearchResultsPage shouldn't be displaying a back button at all - but this is part of the template code - checking the previousContent for null_ptr. It seems to create a frame to be previousContent when there isn't any?

    Presumably something different would happen if the search query had some real results (haven't written this part yet) and the user clicked on the result.

    Anyway, what should my application do if from the SearchResultPage the user goes to the DirectX Main Page?

    Where should I initialize DirectX if App::OnLaunched() isn't going to be called?

    And I'm still interested in how I would debug any of this. Code a break somehow?? (My C++ is a little rusty now - it's been 4 years)

    And also are there any logging libraries for WinRT or C++ under Metro?

    Thanks (I'm actually enjoying this coding).

    Graeme

    Wednesday, May 09, 2012 11:50 AM
  • Hello Graeme,

    I think I understand your issue but just to be sure...

    What is your "PrevousExecutionState" when your app is launched from the sharing context?

    If the state is anything other than "terminated", do you see the "OnRendering" or Resuming event getting called when your app is launched from the sharing context?

    How to resume an app
    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465110.aspx

    Thanks,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, May 09, 2012 9:33 PM
    Moderator
  • Thanks for that James.

    I see the bits I missed now. OnRendering was never called and DirectX was not initalised because I have been doing that in my App::OnLaunched() override. But that is only invoked when the Application starts normally.

    If I wanted to set up DirectX from a Search invocation, I could override App::OnSearchActivated(). But really this would be a silly place to do it. I should wait till (or if) my main application surface is called from the search Results page

    Is this what you were understanding?

    Appreciate the help

    Graeme

    • Marked as answer by GraemeBlack Thursday, May 10, 2012 10:37 PM
    Thursday, May 10, 2012 2:57 AM
  • Hello Graeme,

    Yes this sounds to me to be the correct approach.

    -James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Thursday, May 10, 2012 10:27 PM
    Moderator