473,721 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.FileN otFoundExceptio n: The specified
module could not be found.
at System.Windows. Forms.UnsafeNat iveMethods.CoCr eateInstance(Gu id&
clsid, Object punkOuter, Int32 context, Guid& iid)
at System.Windows. Forms.AxHost.Cr eateWithoutLice nse()
at System.Windows. Forms.AxHost.Cr eateWithLicense (String license)
at System.Windows. Forms.AxHost.Cr eateInstance()
at System.Windows. Forms.AxHost.Ge tOcxCreate()
at System.Windows. Forms.AxHost.Tr ansitionUpTo(In t32 state)
at System.Windows. Forms.AxHost.Cr eateHandle()
at System.Windows. Forms.Control.C reateControl(Bo olean
fIgnoreVisible)
at System.Windows. Forms.Control.C reateControl()
at MyService.MySer vice.Process() in s:\myservice\se rvice1.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 8777
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 CoCreateInstanc e.

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*********@gm ail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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.FileN otFoundExceptio n: The specified
module could not be found.
at System.Windows. Forms.UnsafeNat iveMethods.CoCr eateInstance(Gu id&
clsid, Object punkOuter, Int32 context, Guid& iid)
at System.Windows. Forms.AxHost.Cr eateWithoutLice nse()
at System.Windows. Forms.AxHost.Cr eateWithLicense (String license)
at System.Windows. Forms.AxHost.Cr eateInstance()
at System.Windows. Forms.AxHost.Ge tOcxCreate()
at System.Windows. Forms.AxHost.Tr ansitionUpTo(In t32 state)
at System.Windows. Forms.AxHost.Cr eateHandle()
at System.Windows. Forms.Control.C reateControl(Bo olean
fIgnoreVisible)
at System.Windows. Forms.Control.C reateControl()
at MyService.MySer vice.Process() in s:\myservice\se rvice1.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*********@gm ail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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.c om> wrote
in message news:%2******** *******@TK2MSFT NGP12.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
2393
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 in VB6). I would like to port the ActiveX EXE component it to dotNet. What type of project that I should port it to? A Windows Service or what? Please suggest. The thing is that I will not be porting the existing Windows EXE
7
10894
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 Microsoft Communication Control (MSCommLib) that comes with Visual Studio 6. It seems easy to use and works well enough for me within the context of a Windows Application. Because I need the serial ports to be monitored 24/7, however, a Windows Service...
0
1364
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, shows a message box and sets e.Cancel = True. When I click any other control in the form, the message box shows and the focus returns to the control that handled the Validating event. The problem happens when I click on the ActiveX control. The...
7
4395
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 ActiveX controls that are to be used by a pda need to be written in the ..net compact framework, or am i missing something else here? i have a HP iPaq 2490 with Windows Mobile Premium installed While i'm at it; does a activex control allow you to...
6
3518
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 1.1 Configuration. I have also put a reference to the control on my ASP .NET project. The view that I get is only a disabled text area. Below is the code that I'm using:
0
1164
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 Windows Service would be indicated but can't be used because the actual location functions used are part of an ActiveX Form control. The service will have no UI. I have the thing working as an EXE where the control is hosted by a form which is never...
4
2522
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 usual way? If yes, may you provide a hint/link for getting started? Best regards,
6
8076
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 .dll I can not call the functions in the ActiveX component. In the next step I tried to use the ActiveX component in a class library. I simply added a reference to the corresponding COM component. This this only
2
2828
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 ActiveX control we're using (GrFinger for fingerprint reader)implements several event handlers. It is also my understanding that there is no Message Pump within a Windows Service. I suppose I could create my own message pump, but this seems...
0
9376
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9150
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9086
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8028
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6678
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5994
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2146
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.