473,418 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

mfc activex control in c# windows service

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.CoCreateI nstance(Guid&
clsid, Object punkOuter, Int32 context, Guid& iid)
at System.Windows.Forms.AxHost.CreateWithoutLicense()
at System.Windows.Forms.AxHost.CreateWithLicense(Stri ng 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

Nov 16 '05 #1
5 8747
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

<an*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.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.CoCreateI nstance(Guid&
clsid, Object punkOuter, Int32 context, Guid& iid)
at System.Windows.Forms.AxHost.CreateWithoutLicense()
at System.Windows.Forms.AxHost.CreateWithLicense(Stri ng 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


Nov 16 '05 #2
Hi Dmitriy,
Thanks for your answers. I wanted to use an activeX so that I could
indirectly use a set of MFC dlls created for another application. The
ActiveX control links with these other dlls libraries and allows me to
use them. I thought it would be the easiest way to use these dlls from
a c# windows service...

You say I should create an interop assembly and instantiate the COM
component instance through the constructor exposed by its interop
class. Do you have any comments on how I can do this considering the
above requirement?

I thought I would have to alter the MFC dlls to be able to use them
directly in c#. I don't want to do this. I simply want to use the
functionality in thes dll's in a c# windows service.

Again, many thanks,
Andy

Nov 16 '05 #3
Andy,

My experience with MFC dates back to, I guess, something around 1999, so I
can miss some important points. Still, here goes.

If these DLLs are regular Win32 DLLs with declared exports, you can use
these DLLs as you would use Windows API dlls - through the DllImport
attribute.
Just make sure to specify correct calling convention - not sure this is
WINAPI for MFC dlls.

If you however want to use classes, going the MFC-based COM object is much
better as you cannot import C++ classes from a DLL in .NET.
In this case, make sure the COM is registered with regsvr32.exe, then, from
your C# project, go to the "Add Reference" dialog, switch to the "COM" tab
and choose your COM object from the list (or browse to the OCX). The IDE
will generate an interop assembly for you. You can also do the same with
command-line tlbimp.exe, if you want more control on namespaces and import
options.

Now that you have referenced the COM object and its interop asssembly has
been added to the list of references, launch Object Browser and examine the
namespace from the interop assembly.
You should see a class named something like MyObjectClass having a
parameterless constructor. This is the class you need to instantiate to
create an instance of your COM object. The class should have the same
interface your COM object has, so I think once you have an instance, the
rest should be simple.

--
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

<an*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi Dmitriy,
Thanks for your answers. I wanted to use an activeX so that I could
indirectly use a set of MFC dlls created for another application. The
ActiveX control links with these other dlls libraries and allows me to
use them. I thought it would be the easiest way to use these dlls from
a c# windows service...

You say I should create an interop assembly and instantiate the COM
component instance through the constructor exposed by its interop
class. Do you have any comments on how I can do this considering the
above requirement?

I thought I would have to alter the MFC dlls to be able to use them
directly in c#. I don't want to do this. I simply want to use the
functionality in thes dll's in a c# windows service.

Again, many thanks,
Andy


Nov 16 '05 #4

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:%2***************@TK2MSFTNGP12.phx.gbl...
Andy,

My experience with MFC dates back to, I guess, something around 1999, so I
can miss some important points. Still, here goes.

If these DLLs are regular Win32 DLLs with declared exports, you can use
these DLLs as you would use Windows API dlls - through the DllImport
attribute.
Just make sure to specify correct calling convention - not sure this is
WINAPI for MFC dlls.

If you however want to use classes, going the MFC-based COM object is much
better as you cannot import C++ classes from a DLL in .NET.
In this case, make sure the COM is registered with regsvr32.exe, then,
from your C# project, go to the "Add Reference" dialog, switch to the
"COM" tab and choose your COM object from the list (or browse to the OCX).
The IDE will generate an interop assembly for you. You can also do the
same with command-line tlbimp.exe, if you want more control on namespaces
and import options.

Now that you have referenced the COM object and its interop asssembly has
been added to the list of references, launch Object Browser and examine
the namespace from the interop assembly.
You should see a class named something like MyObjectClass having a
parameterless constructor. This is the class you need to instantiate to
create an instance of your COM object. The class should have the same
interface your COM object has, so I think once you have an instance, the
rest should be simple.


Dmitriy,Andy

ActiveX controls can ONLY be hosted in a Windows Forms application and IE
(itself an ActiveX host), and only if they derive from
System.Windows.Forms.AxHost.

To achieve this you have to create a wrapper control using aximp.exe
file.dll or file.ocx. This wrapper control contains an instance of the
underlying ActiveX control. It knows how to communicate with the ActiveX
control, but it appears as a Windows Forms control. This generated control
hosts the ActiveX control and exposes its properties, methods, and events as
those of the generated control.

But here it comes, ActiveX controls (just like Windows.Forms) are not
designed to be used hosted in windows services, they need a STA to live in
and a thread that pumps messages. Unless they are based on a light weight
windowless control, they assume to run in a interactive user session, which
services by default do not.

So I my suggestion is - don't do this, it's a recipt for failure.

Willy.


Nov 16 '05 #5
Dmitriy / Willy,

Thanks for all your help - I've decided to go the DLLImport route after
all, seems the easiest way!

Cheers,
Andy

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: David | last post by:
Hi everyone, I have a ActiveX EXE component written in VB6. This ActiveX EXE exposes various public methods that can be called by several other independent Windows EXE applications (also written...
7
by: Will | last post by:
I'm working on a C# Windows Service that needs to monitor serial port communication. Because the .Net framework does not include support for serial communications, I've decided to use the...
0
by: zevikw | last post by:
I am using an ActiveX control in a .NET application which I put on a form. I have another .NET control on that form that handles the Validating event. The method that handles the Validating event,...
7
by: Jarod_24 | last post by:
I just downloaded a activex control that was written in C# and tried to view it on my PDA's Internet Explorer. At my regular PC it displayed just fine, but nothing showed up on the pda. Do...
6
by: Budhi Saputra Prasetya | last post by:
Hi All, I'm trying to display .NET Custom Control (created using Inherited Control) on an ASPX page, but no luck. I already registered the Control to Global Assembly Cache through .NET Framework...
0
by: Bob | last post by:
I need to code a service which accepts latitude and longitude coordinates and returns the nearest place name. It will accept the coordinates from an MSMQ and return the placename on another. A...
4
by: Henrik Dahl | last post by:
Hello! Is it possible to use Visual Studio 2005 or, secondarily, Visual Studio .NET 2003 to create ActiveX controls which may be consumed by VB 6.0 programs, i.e. dealt with on forms in the...
6
by: hufaunder | last post by:
I have an ActiveX component that I want to use in a library that I am writing. As a first test I used the ActiveX component in a windows form application. Adding the component created: Ax.dll...
2
by: =?Utf-8?B?Sm9obiBG?= | last post by:
Hello All, I have a question about using an ActiveX control with a Windows Servce in C#. I believe it is not possible to properly setup an ActiveX control in a windows service as the particular...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.