Category: Compact Framework

  • Mobile In The Hand 4.0 Released

    Today we put the final touches to Mobile In The Hand 4.0 and have released this latest version of the suite. This is a major reworking of the code and the library is now broken into 10 separate dlls so you only need to deploy the specific functionality you require in a project. We have also added some additional functionality alongside the code libraries themselves to add “My” keyword functionality for Visual Basic users and make it easier to incorporate and edit provisioning XML documents. Over the next few weeks I’ll be posting a number of blog articles to highlight new features and elaborate on some of the less visible features.

    Full details of the library are available on the product page.

  • Get the name of your executing .exe

    The Compact Framework doesn’t support Assembly.GetEntryAssembly to determine the launching .exe. You can instead P/Invoke the native GetModuleFileName function like so:-

    byte[] buffer = new byte[MAX_PATH * 2];

    int chars = GetModuleFileName(IntPtr.Zero, buffer, MAX_PATH);

    if (chars > 0)

    {

    string assemblyPath = System.Text.Encoding.Unicode.GetString(buffer, 0, chars * 2);

    }

    Where MAX_PATH is defined in the Windows CE headers as 260. The P/Invoke declaration for GetModuleFileName looks like this:-

    [DllImport(“coredll.dll”, SetLastError = true)]

    private static extern int GetModuleFileName(IntPtr hModule, byte[] lpFilename, int nSize);

    The function expects a HMODULE – a handle to a native module. However passing IntPtr.Zero here indicates we want the module which created the process which is our .exe. This code will always return the path of the calling .exe regardless of if it is in a utility dll, or even a GAC assembly located in the Windows folder.