VB newbie to C# - DLL Reference problem

A

Andrew Mueller

Hello,

I have been searching for quite awhile and probably just do not know
what to search on....

Here is my issue:

I am creating a Windows Service and I referenced a dll. I have used
this dll many times with Visual Studio 6, but never 2003. I have no problem
instantiating the object. In fact, I can physically see the object's icon
in the system tray. However, I cannot seem to use the methods like I used
to be able to....

My logic is this:

Using MyDll;

namespace MyServiceName

{
public class MyService1 : System.ServiceProcess.ServiceBase
{
:
public MyService1()
{
InitializeComponent();

MyDll.MyDllClass MyObject = new MyDll.MyDllClass();

MyObject.SendMessage("Here is my message");
:
:
}


protected override void OnStart(string[] args);
{
MyObject.SendMessage("Here is my message");
}

}
}


Of course, there is a lot more code than this which makes it operable, but
this is the gist of what I have that doesn't work for me... In the
MyService1 constructor, I instantiate the object and I can see the
Intellisense working to grab the SendMessage method. However, that method
does not run within the constructor. I was unsure if it would or not, but
assume that this in not proper coding anyway even if it were to work. It
was a test.

In the OnStart routine, when I put the code there, it doesn't even compile.
With an error of:

'The type or namespace name 'MyObject' could not be found (are you
missing a using directive or an assembly reference?)"


I am assuming that I am missing an assembly reference, but I am unsure what
that is.... Please help me along with this. I am sure that it is simple and
I am missing some basics of C#...


Thanks in advance,

Andrew Mueller
 
A

Agustin Sanchez

You need to add a reference to the component using the "add reference" menu
option on visual studio, and select the COM tab. Then look for your
component on the list of registered controls.
Be aware of some performance issues when using Appartment Threaded or single
threaded components on your .NET code.

Best regards.
Agustin Sanchez
 
A

Andrew Mueller

I do have the reference set. It appears to me that since this application
brings up a dialog box (ActiveX EXE), that it will not trigger from a
Windows Service. I am not sure that this is true, though.



-----Original Message-----
From: Agustin Sanchez
Sent: Tuesday, July 15, 2003 10:12 PM
To: Andrew Mueller
Subject: Re: VB newbie to C# - DLL Reference problem



You need to add a reference to the component using the "add reference" menu

option on visual studio, and select the COM tab. Then look for your

component on the list of registered controls.

Be aware of some performance issues when using Appartment Threaded or single

threaded components on your .NET code.



Best regards.

Agustin Sanchez
 
D

Dave Loynd

Andrew,

You're right - windows services do not have the ability to interact with the
desktop in that manner. AFAIK they are limited pretty much to tossing an
icon in the system tray. You might be able to work around it by having your
service spawn a new process if a user is currently logged on, but you'll
want to do some research to before starting down that path. :)
--
Dave Loynd
C# MCP, Motorcycle Racer, Organ Donor

Andrew Mueller said:
I do have the reference set. It appears to me that since this application
brings up a dialog box (ActiveX EXE), that it will not trigger from a
Windows Service. I am not sure that this is true, though.



-----Original Message-----
From: Agustin Sanchez
Sent: Tuesday, July 15, 2003 10:12 PM
To: Andrew Mueller
Subject: Re: VB newbie to C# - DLL Reference problem



You need to add a reference to the component using the "add reference" menu

option on visual studio, and select the COM tab. Then look for your

component on the list of registered controls.

Be aware of some performance issues when using Appartment Threaded or single

threaded components on your .NET code.



Best regards.

Agustin Sanchez





Andrew Mueller said:
Hello,

I have been searching for quite awhile and probably just do not know
what to search on....

Here is my issue:

I am creating a Windows Service and I referenced a dll. I have used
this dll many times with Visual Studio 6, but never 2003. I have no problem
instantiating the object. In fact, I can physically see the object's icon
in the system tray. However, I cannot seem to use the methods like I used
to be able to....

My logic is this:

Using MyDll;

namespace MyServiceName

{
public class MyService1 : System.ServiceProcess.ServiceBase
{
:
public MyService1()
{
InitializeComponent();

MyDll.MyDllClass MyObject = new MyDll.MyDllClass();

MyObject.SendMessage("Here is my message");
:
:
}


protected override void OnStart(string[] args);
{
MyObject.SendMessage("Here is my message");
}

}
}


Of course, there is a lot more code than this which makes it operable, but
this is the gist of what I have that doesn't work for me... In the
MyService1 constructor, I instantiate the object and I can see the
Intellisense working to grab the SendMessage method. However, that method
does not run within the constructor. I was unsure if it would or not, but
assume that this in not proper coding anyway even if it were to work. It
was a test.

In the OnStart routine, when I put the code there, it doesn't even compile.
With an error of:

'The type or namespace name 'MyObject' could not be found (are you
missing a using directive or an assembly reference?)"


I am assuming that I am missing an assembly reference, but I am unsure what
that is.... Please help me along with this. I am sure that it is simple and
I am missing some basics of C#...


Thanks in advance,

Andrew Mueller
 
S

Scott

Ok your not compiling problem has nothing to do with
referencing anything. The problem is the scope in which
you have declared MyObject. Put it as a class level
variable as its only declared in the scope of the
constructor. Just do the new() in the constructor...

hope that helps u!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top