RE: ActiveX as a Service with events
- From: TAPIGuruFred <TAPIGuruFred@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 25 Nov 2005 11:51:40 -0800
Hello, I posted this on the 17th, where it the managed support that promises
a 2 day response? Thanks.
Fred
--
Fred
"TAPIGuruFred" wrote:
> Putting this all together in one message to escalate this to managed group
> support using our MS Partner alias
>
> Have an ActiveX created in Delphi 7 and need to run it in a service by
> dynamically creating the controls at runtime with event handling. Using form
> based apps in any environment that supports ActiveX, including .NET
> environments works fine.
>
> Possible Path 1? -------------------------------------
>
> If I just add the reference to the control at design time using the TLBImp
> assembly and not the Aximp assembly (myControls.myOCX instead of
> AXMyControls.AxMyOCX) and dynamically create
> the control at runtime, the service works perfectly... but only for one
> event. If I try to add more than one event handler to the project, I
> get the 0x80040202 error. This has something to do with event sinks.
> What is different about the import created that uses no
> AxInterop.myOCX, but does use Interop.myOCX and Interop.StdVCL that
> causes a component that works in every other environment to not work
> when instantiated this way? What is the solution to this path to the
> problem? I believe I have to change the ckSingle param to ckMulti in
> this function but I am not sure:
>
> if FControlFactory.EventTypeInfo <> nil then
> FConnectionPoints.CreateConnectionPoint(FControlFactory.EventIID,
> ckSingle, EventConnect);
>
> But I think I would then have to iterate through all the events and
> create sinks for each one. Why did .NET mess with this? Would I need
> 2 versions of the control so it would work with VB6 and everything
> else, or implement some other way to know whether to use single or
> multiple event sinks? Or will this change not affect how it works in
> regular VB6 and other environments? What is involved in trying to fix
> the problem using this path? Here is the code in VB.NET
>
> Private WithEvents myOCX As myControls.myOCX
>
> my OCX = new myControls.MyOCX
>
> Possible Path 2 ----------------------------------
>
> If I create an AxInterop assembly and add that also as a reference,
> then I run into a problem with the ActiveX needing a form. If I add a
> reference to system.windows.forms to the solution explorer I can get
> past one error that AxInterop needs it. I now have to slightly change
> the code adding AX in front of everything:
>
> Private WithEvents myOCX as AxmyControl.AxmyOCX
>
> It appears the AX wrapper creates event sinks with someting called
> "MultiCaster". But If I try to do this, this, I cannot instantiate the
> object now because I get an error
> stating it has to run in a single threaded apartment. I tried this, but it
> does not work:
>
> <STAThread()> _ (tried this here, in front of Main() instead and both
> places)
> Protected Overrides Sub OnStart(ByVal args() As String)
> myOCX = New AxmyControls.AxMyOCX
> myOCX.Enabled = True
>
>
> Possible Path 3 ----------------------------------
>
> Try to create a new thread, and use the AX wrapper again. Control works
> fine, but I cannot get any events. So then I try to dynamically create a
> form, put the ActiveX on it, and run it that way. I can't figure out how to
> do it. Here is my code:
>
> Private WithEvents myOCX As AxMyControls.AxMyOCX
>
> Private Sub OnStart()
> Dim t As Thread
> t = New Thread(AddressOf Me.myStart)
> t.ApartmentState = ApartmentState.STA
> t.Start()
> End Sub
>
> Private Sub myStart()
> Try
> myForm = New System.Windows.Forms.Form
> System.Windows.Forms.Application.Run(myForm)
> myOCX = New AxMyControls.AxMyOCX
> CType(myOCX,
> System.ComponentModel.ISupportInitialize).BeginInit()
> myForm.Controls.Add(myOCX)
> CType(myOCX,
> System.ComponentModel.ISupportInitialize).EndInit()
> AddHandler myOCX.OnEvent1, AddressOf myOCX_OnEvent2
> AddHandler myOCX.OnEvent2, AddressOf myOCX_OnEvent2
>
> myOCX.Enabled = True
> Catch e As Exception
> ' error code here
> End Try
>
> Notice I also have to use the BeginInit and EndInit functions. What is the
> best path to take to make this work? Isn't there a way to get where I need
> to go without a form by using the multicaster myself, or changing the ActiveX
> itself somehow? Assuming I have to live with the "invisible form" and even
> create a new thread, what am I doing wrong in the last code snippet? Thanks.
>
> --
> Fred
.
- References:
- ActiveX as a Service with events
- From: TAPIGuruFred
- ActiveX as a Service with events
- Prev by Date: Re: With what program can I see all the functions in a non-.NET assembly or non-COM dll/exe?
- Next by Date: Re: managed / unmanged - StringToHGlobalAnsi / PtrToStringAnsi
- Previous by thread: ActiveX as a Service with events
- Next by thread: Function Pointers in a struct
- Index(es):
Relevant Pages
|
Loading