Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / June 2006

Tip: Looking for answers? Try searching our database.

First mouse click fails in modal window of native COM object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SergeyR - 19 Jun 2006 17:47 GMT
Hello

I am writing a COM object(component) in C#. There is an interface(called
IBatchConfig)  I should implement in this COM object. In particular, this
method of the interface:

public void Configure(int hWnd, object pTaskTopic, object pConfigTopic)

which brings up a modal dialog of this component.

My goal is to call Configure method of another COM object (component) in my
Configure method.

Let's say the name of my componet is MyCSharpComp, and C# implementaion of
this method looks lile this:

public class MyCSharpComp : IBatchConfig
{
   public void Configure(int hWnd, object pTaskTopic, object pConfigTopic)
       {
           .....
           //creating an instanse of COM object "comp"
           Type compType = Type.GetTypeFromProgID(compProgID);
           IBatchConfig comp =
(IBatchConfig)Activator.CreateInstance(compType);

           //passing it to ConfigForm constructor
           ConfigForm cf = new ConfigForm(IBatchConfig comp,......);
           if (cf.ShowDialog() == DialogResult.OK)
           {
            ......
            }
        }
}
public partial class ConfigForm : Form
   {
   
         IBatchConfig comp;
         public ConfigForm ( IBatchConfig pComp, .....)
         {
              ....
              comp = pComp;
              ....
         }        

         private void SomeMethod(...)
         {
                .....
                //this method should bring up a config dialog of another
COM object "comp"
                comp.Configure(Handle.ToInt32(), taskBase, cfgBase);
                .....
         }
   }

most of other COM objects is written in C++ and theirs implementation of
Configure method looks like this:
STDMETHODIMP CFTC::Configure(LONG hWnd, IDispatch * pTaskTopic, IDispatch *
pConfigTopic)
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState())
    HRESULT rc = S_OK;
   
    CFTCCfgDlg CfgDlg(CWnd::FromHandle((HWND)hWnd ) );

    if( ( rc = CfgDlg.Init( pTaskTopic, pConfigTopic ) ) == S_OK )
    {
        CfgDlg.DoModal();
       
    }
    return rc;
}

When C# component calls c# component everything is ok.
when c++ calls c++, also everything is ok
when c++ calls c# everything looks fine
but when C# component calls c++
it brings up a dialog but the first mose click seems to do nothing wherever
you click and you should click once again to press button or to do something
else. This first click can be made anywhere inside or outside the dialog.  
The dialog seems to own the focus, and keyboard input works fine.

Is there any idea what is going on here, and how can I work around this
problem?
I will appreciate any ideas.

Sergey
TDC - 19 Jun 2006 18:27 GMT
I'd try p/invoking ReleaseCapture...

> Hello
>
[quoted text clipped - 83 lines]
>
> Sergey
SergeyR - 19 Jun 2006 19:05 GMT
could you, please, explain a little more in detail?

> I'd try p/invoking ReleaseCapture...
>
[quoted text clipped - 85 lines]
> >
> > Sergey
TDC - 19 Jun 2006 19:25 GMT
The mouse-click behavior you described sounds like what happnes when
you use the win api SetCapture, which "captures" the mouse input.  If
that is what is happening then perhaps you can use ReleaseCapture to
counter-act the ffect.  It really is just a possible workaround, and
may not help you at all, but what's the harm in trying.  So to sum up,
in your C# code, use ReleaseCapture (hmm, actually I think this might
be available in the .NET framework?) just before you call the C++
dialog.

> could you, please, explain a little more in detail?
>
[quoted text clipped - 87 lines]
> > >
> > > Sergey
SergeyR - 19 Jun 2006 19:49 GMT
Thank you so much, TDC

It really helped.

public partial class ConfigForm : Form
{
         [DllImportAttribute("user32.dll")]
          public static extern bool ReleaseCapture();
         
          IBatchConfig comp;
          public ConfigForm ( IBatchConfig pComp, .....)
          {
               ....
               comp = pComp;
               ....
          }

          private void SomeMethod(...)
          {
                 .....
                 //this method should bring up a config dialog of another
                   COM object "comp"
                  ReleaseCapture();
                  comp.Configure(Handle.ToInt32(), taskBase, cfgBase);
                 .....
          }
}

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.