.Net ramblings
# Tuesday, 24 April 2012
Using XStandard dll on a Win 64-bit

I have a winforms app that ran into trouble with the XStandard XHTML component on a 64 bit system. I was registering the OCX file from code if it didn't register via the MSI. found this kb article useful, and then called the appropriate version of regsvr32.exe based on the platform.

try
{
    // attempt to load the control 
    this.pageEditor = new PageEditor();
}
catch (System.Runtime.InteropServices.COMException)
{
    // control loading failed
    string ocxPath = Path.Combine(Application.StartupPath, "Xstandard.ocx");
    try
    {
        // OCX is not registered, register it now using the Syswow64 version of regsvr32.exe if we are using a 64 bit system
        Process p = new Process();
        p.StartInfo.FileName = @"regsvr32.exe";
        p.StartInfo.WorkingDirectory = (IntPtr.Size == 8) ? @"%SystemRoot%\Syswow64" : @"%SystemRoot%\system32";  // IntPtr is size 8 on a 64 bit system
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.Arguments = String.Format("/s \"{0}\"", ocxPath);
        p.Start();
        p.Close();
        MessageBox.Show("Please restart... (OCX file registered)", "Restart");
        Application.Exit();
        return;
    }
    catch (Exception ex)
    {
        MessageBox.Show("Unable to register OCX file: " + ex.Message, "Error");
        Application.Exit();
        return;
    }
}

Tuesday, 24 April 2012 20:51:07 (GMT Daylight Time, UTC+01:00)  #    Comments [0]  .Net Windows Forms