Re: mfc activex control in c# windows service

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Dmitriy Lapshin [C# / .NET MVP] (x-code_at_no-spam-please.hotpop.com)
Date: 02/16/05


Date: Wed, 16 Feb 2005 15:35:49 +0200

Hi Andy,

1. Why do you use the AxHost class in a windows service? I am pretty sure
creating an interop assembly and instantiating the COM component instance
through the constructor exposed by its interop class is much more correct
solution.

2. The location of the OCX on disk is irrelevant. Given the OCX is properly
registered, it's location is stored in the registry so the system is able to
locate and load the .OCX file. If the OCX is not registered, no 'special'
location would allow the system to instantiate it with CoCreateInstance.

3. Can your OCX operate in non-visual mode? Windows services don't have any
GUI, they are even not allowed to interact with the desktop by default.

-- 
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx
<andy.g.ward@gmail.com> wrote in message 
news:1108506175.171028.106920@z14g2000cwz.googlegroups.com...
>I keep getting this when trying to create an MFC activex control in a
> c# windows service - anyone got any ideas what the missing module could
> be???
>
> Exception thrown : System.IO.FileNotFoundException: The specified
> module could not be found.
>   at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid&
> clsid, Object punkOuter, Int32 context, Guid& iid)
>   at System.Windows.Forms.AxHost.CreateWithoutLicense()
>   at System.Windows.Forms.AxHost.CreateWithLicense(String license)
>   at System.Windows.Forms.AxHost.CreateInstance()
>   at System.Windows.Forms.AxHost.GetOcxCreate()
>   at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
>   at System.Windows.Forms.AxHost.CreateHandle()
>   at System.Windows.Forms.Control.CreateControl(Boolean
> fIgnoreVisible)
>   at System.Windows.Forms.Control.CreateControl()
>   at MyService.MyService.Process() in s:\myservice\service1.cs:line 93
>
> For more information, see Help and Support Center at
> http://go.microsoft.com/fwlink/events.asp.
>
>
> I have tried MANY different ways to use an MFC ActiveX control in my c#
> windows service but I consistently come up against the above error
> message. There can't be any missing modules since the ocx I am trying
> to create is in the same directory as the #c service exe.
>
> Many thanks for any help,
> Andy
> 


Relevant Pages

  • Re: How can I know if I am in a Service or Application?
    ... > need to know if a Windows Service is instantiating the component or ... > got instantiated inside a Windows Service or a Console App? ... > TIA TIA TIA! ... >> caller of the component pass you a TextWriter to output to. ...
    (microsoft.public.dotnet.framework)
  • Re: How can I know if I am in a Service or Application?
    ... need to know if a Windows Service is instantiating the component or ... Console App and "they" want me to be able to automatically ... got instantiated inside a Windows Service or a Console App? ... TIA TIA TIA! ...
    (microsoft.public.dotnet.framework)
  • Re: ocx gets disconnected but VB code still thinks it is connected
    ... I need the OCX wrapper in order for a Powerbuilder ... application to receive events from the windows service. ... Private WithEvents NtxServer As DoseMercury.CDoseNtxServer ...
    (microsoft.public.vb.general.discussion)
  • ocx gets disconnected but VB code still thinks it is connected
    ... I have an OCX control that wraps a windows service ... I need the OCX wrapper in order for a Powerbuilder ... Private WithEvents NtxServer As DoseMercury.CDoseNtxServer ...
    (microsoft.public.vb.general.discussion)
  • Re: Windows Service and OCX
    ... The ocx failed to perform as expected, meaning the OCX events failed to ... I specifed the withevents clause in my declaration. ... Is there some way I can use the OCX inside of a windows service? ... ActiveX controls require a message pump to fire there events. ...
    (microsoft.public.dotnet.languages.vb)