views:

7

answers:

0

I have a .NET 3.5 Compact Framework application that uses MSMQ. We are running this application on an Intermec CN3, Windows Mobile 5.0 device.

However, when our application first tries to active the MSMQ service with ActivateDevice (pinvoke), the application crashes and we get the error report message:

A problem has occuurred with myApp.exe

Please tell Microsoft about this problem, at not cost to you. ect..

What we have done is this:

  1. Hard Reset the Device
  2. Install NETCFv35.wm.armv4i.cab
  3. Install msmq.arm.CAB
  4. *Run a CF console app that sets up MSMQ and the registry
  5. Soft reset the PDA
  6. *Run our application which calls ActivateDevice() on startup

After doing a soft reset, the first time that ActivateDevice() is called, the application crashes.

However, now that we have called ActivateDevice(), MSMQ services are working on the device atleast until it is soft reset again.

Also, any calls to ActivateDevice() will not crash the application.

The console app that we run after a hard reset is basically this:

class InstallRegister
{
    public void Main()
    {
        RunMsmqAdmin("install");
        RunMsmqAdmin("register install");
        RunMsmqAdmin("register");

        SetQuotaValueRegistry("MachineQuota");
        SetQuotaValueRegistry("DefaultLocalQuota");
        SetQuotaValueRegistry("DefaultQuota");

        RunMsmqAdmin("enable binary");
        RunMsmqAdmin("enable srmp");
        RunMsmqAdmin("start");

        RegFlushKey(0x80000002);
    }

    private void SetQuotaValueRegistry(string quotaValueName)
    {
        Microsoft.Win32.Registry.SetValue(
                "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSMQ\\SimpleClient\\"
                , quotaValueName
                , 100000);
    }

    private void RunMsmqAdmin(string command)
    {
        using (Process _process = new Process())
        {
            _process.StartInfo.FileName = @"\windows\msmqadm.exe";
            _process.StartInfo.Arguments = command;
            _process.StartInfo.UseShellExecute = true;
            _process.Start();
            _process.WaitForExit();
        }
    }
    [System.Runtime.InteropServices.DllImport("CoreDll.dll", EntryPoint = "RegFlushKey", SetLastError = true)]
    private static extern uint RegFlushKey(uint hKey);
}

Our applications call to ActivateDevice() is basically this:

class ActivateMSMQ
{
    public void Active()
    {
        var handle = ActivateDevice("Drivers\\BuiltIn\\MSMQD", 0);
        CloseHandle(handle);
    }
    [System.Runtime.InteropServices.DllImport("CoreDll.dll", SetLastError = true)]
    private static extern IntPtr ActivateDevice(string lpszDevKey, Int32 dwClientInfo);

    [System.Runtime.InteropServices.DllImport("CoreDll.dll", SetLastError = true)]
    private extern static Int32 CloseHandle(IntPtr hProcess);
}

ActivateDevice() still causes our app the crash whenever the device is soft reset.

Has anyone else experienced this with MSMQ on the compact framework?