views:

29

answers:

1

I need to use activeX to create a plugin for a legacy application. I'm using C# so that i can share the codebase of several related stand alone products.

When I host the control in the SDK's test container (TstCon32.exe) everything works fine. The problem is that when I try to load it in the target application the first time I click on the control everything except the item I clicked on (textbox or datagrid cell) is painted over with control grey, if I change the background color of the control to something else the background stays the same color I specified but all the controls are still covered over with control grey (from the container app?). Clicking on additional controls will cause them to paint, resizing the control will cause everything to repaint. After the initial blanking the control functions normally until the next time a copy is created.

A: 

I finally found a solution. The first part was to change my targeted framework from 4.0 to a prior version. This revealed an exception thta was occuring when the control was blanked that was previously being consumed and hidden from me:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at System.Windows.Forms.UnsafeNativeMethods.IOleInPlaceSite.OnUIActivate()
   at System.Windows.Forms.Control.ActiveXImpl.InPlaceActivate(Int32 verb)
   at System.Windows.Forms.Control.ActiveXImpl.OnFocus(Boolean focus)
   at System.Windows.Forms.Control.ChildGotFocus(Control child)
   at System.Windows.Forms.Control.OnGotFocus(EventArgs e)
   at System.Windows.Forms.Control.WmSetFocus(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

From there I was able to find a post by tomasvdb who encountered the same problem I had with the Google Sidebar.

One of the replies to that post linked to this message which provided a workaround for a bug where the sidebar application was sending invalid data to the .net control.

Calling that workaround method in the Control's VisibleChanged event handler solved my problem as well.

Dan Neely