开发者

handling activeX-events in ax 2009

i've got an activeX component with several events. debugging this dll in .net proofs, that the events are raised and can be breakpointed ( is this a word? ;) ) registering this dll via regasm /codebase works and i can add this activeX in ax on a form. the events are listed in the activeX-explorer in ax. but it seems, that i've got no chance to handle the events raised in ax.

using another activeX ( eg Microsoft Date and Time Picker Control ) works fine.

i appreciate any hints or tips!

here are some lines of the code, which i talk about.

namespace <someNamespace>
{
    [ProgId("<someProgID>")]
    [ClassInterface(ClassInterfaceType.AutoDual), ComSourceInterfaces(typeof( <myInterface> ))]
    [Guid("<someGUID>")]
    [ComVisible(true)]

    public class <ClassName>
    {

        [instantiate some COM-Object, named dummy]

        public 
        <ClassName>( ...)
        {
            init();
        }

        public delegate void <someDelegate>( int a, int b );
        public event someDelegate myDelegate;

        [ComVisible(true)]
        public void OnEvent( int a, int b )
        {
            if ( myDelegate != null )
            {
                Console.WriteLine( "yippie" );
            }
        }

        [ComVisible(true)]
        public void run( ... )
        {
            this.myDelegate += new someDelegate( this.OnEvent );
        }

        private void
        onEvent( int a, int b )
        {
             myDelegate( a, b );
        }

       开发者_开发问答 #endregion
    }
}

[Guid("<someOtherGUID>")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface <myInterface>
{
    [DispId(1)]
    void myDelegate( int a, int b );
}
}

these are the basic functions ( hope i didn't forget one of them ) relating to the event-thing. the activeX itself is a wrapper for a com-object, which itself can't be integrated in ax, afaik. "onEvent" is a function called by an event of the com-object and fires "myDelegate". all this is working fine, testing in visual studio - the event can be handled on a form, calling the activeX-part. the last step would be to handle this event in ax. as i already wrote, the event itself is listed correctly in the activeX-explorer, but i didn't find a way to react on this event in x++.


I assume your ActiveX is also written in .NET.

There are a couple of funnies when writing ActiveX controls in .NET. One of them is you need a separate interface for the events exposed by the ActiveX control. You will also need to manually raise the event in your control, when whatever conditions are met.

I answered a similar question about handling ActiveX events (written in C#) from Javascript. Maybe check out the ActiveX structure I posted there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜