Showing posts with label Windows API. Show all posts
Showing posts with label Windows API. Show all posts

Thursday, 30 July 2015

Page.Loaded Fails to Fire

Yesterday, we installed windows 10.

We tried out our app BouncingBalls and was surprised that the balls didn’t start bouncing, when they did on Windows 8.1

Even more oddly, if you opened the settings page, they would suddenly start bouncing.

Firing up the debugger, we found that Page.Loaded was not firing when we navigated to the main page.  The code we use is similar across all of our apps, but for some reason this particular app was not behaving.

After quite a bit of code hacking, we found it came down to the handling of the splash screen.

We add a handler for Splashscreen.Dismissed, and handle navigation to the main page (or another page depending on trial mode) from there.

In our OnLaunched handler, we called

Window.Current.Content = _launchframe;
Window.Current.Activate();

but we hadn’t yet navigated to a page, or set any content for our frame _launchframe.

In the Dismissed handler, we did this:

var nowarn = _launchFrame.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => ContinueAfterSplash1());

And in ContinueAfterSplash1() we eventually call after a few async calls.

_launchFrame.Navigate(typeof(BouncingBalls.MainPage), args)

MainPage received an OnNavigatedTo call, but never received the Loaded event we wired up.

The solution?

In the end, we changed the code not to call Window.Current.Content until after we successfully navigated to the MainPage.

For whatever reason, that caused the Loaded event to fire every time.

Sunday, 1 June 2014

Why is documentation so terrible these days?

I’m recovering from ankle surgery after a low speed skiing accident that I had in February, and have decided to take the opportunity to port our Surface Level to Windows Phone 8.1 that I wrote while recovering from the initial accident.

I have about 8 weeks where I’m unable to drive, so will be working from home and very bored, so as a result, will have plenty of time for the project.

One of the things I’ve noticed both for my apps, and my job is that the documentation supplied by companies these days appears to be getting worse.  For instance, in my day job, I’m currently building an embedded system based on an STM32F4 microcontroller, and hooking it to a variety of WIFI modules on the market (the only reason for the variety is we keep coming to problems that aren’t documented, and then prevent us from using a particular module in our product).

I’m not sure if the documentation is intentionally bad so that competitors can’t find the weaknesses, or if the product is bad because it’s rushed to market, or if it’s just pure incompetence.

So, back to Surface Level.  While building the Windows Phone 8.1 version, I added back some code from the working Windows 8.1 version, including an AppBar

 

image

A quick check of the docs shows it works, but then when I run the program I get this:

A first chance exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in SurfaceLevel.WindowsPhone.exe

WinRT information: Cannot create instance of type '%0' [Line: 17 Position: 17]

Additional information: The text associated with this error code could not be found.

Well, that’s a helpful message.  Line 17 does in fact have this on it:

<AppBar x:Name="BottomBar" Opened="OnOpened">

But position 17 is at x:Name?!

If you do manage to get all the way down the page in the online version of the documentation, you might find this:

image

Oh, I see.  I can’t use it.

Then I tried to mirror the front camera, like I do on the Windows 8.1 version, like this:

mediaCaptureMgr.SetPreviewMirroring(selectedDeviceInformation != null ? (selectedDeviceInformation.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front) : false);

That throws an exception, because the phone camera doesn’t support it (at least not on my phone), and there’s some helpful documentation in the remarks section:

Horizontal mirroring is useful for video conferencing or video chat applications, because the users typically want to see a reflected image of themselves. The non-mirrored view can look strange, because we are used to seeing ourselves in a mirror.

To mirror the preview video, apps should instead use the following method. Windows Store apps using JavaScript should use the msHorizontalMirror property of the video object. Windows Store apps using C++, C#, or Visual Basic should use the FlowDirection property on the CaptureElement.

SetPreviewMirroring can potentially be used as a performance optimization on some devices

So, we have a method that we shouldn’t use.

While the information is there, it takes at least 20 minutes to discover why things aren’t working by poring over the documentation for each and every method/function call, and my first language is American English.  I feel really sorry for people who aren’t native speakers.

Tuesday, 20 March 2012

ShellExecute print verb fails on WOW64

I have a 32 bit program that has been installed by a customer on 64 bit windows.

There appears to be a problem with using ShellExecute and the print verb in that configuration.  First my test program.

// printme.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "objbase.h"
#include <windows.h>

#include <shellapi.h>

int main(int argc, char* argv[])
{
if (argc != 2)
{
printf("Usage: %s file_to_print", argv[0]);
return 0;
}

CoInitializeEx(NULL, COINIT_APARTMENTTHREADED) ; //| COINIT_DISABLE_OLE1DDE);

HINSTANCE retVal = ::ShellExecute(NULL, "print", argv[1], NULL, NULL, 0); // don't ask, as the user can always cancel...
printf("RetVal = %08x\n", retVal);
printf("LastError = %08x\n", GetLastError());
return 0;
}


This program works correctly on 32 bit windows version up to Windows 7.  The program simply runs the print verb on the first argument passed on the command line.


printme Page1.htm


On the system in question, the registry is set up as follows:


regprint64



If I run the following command
rundll32 c:\windows\system32\mshtml.dll,PrintHTML “Page1.htm”
the print dialog is successfully shown.


However running my program blinks, but nothing ever launches.


Process manager shows the following:
failure


As you can see the selected bottom line is running the 32bit version, which never completes.  The 64 bit version run previously does work.


Is there any workaround?  Not that I’ve found yet.