Call EXE method from DLL
Hi
Is there a way that I can call a method in an EXE (managed code,
VB.NET) from a .NET DLL by passing a reference to the instance of the
EXE? Multiple instances of EXE might be running and loaded in memory
and I need the DLL to invoke a method within the running instance by
passing a reference (such as the application title, window handler
etc).
In case you are wondering why the DLL is calling the EXE method and not the other way around, it is because this DLL is like a wrapper class and the method that invokes the method in the EXE is actually called from an Access VBA module.
TIA
[640 byte] By [
KannanPV] at [2007-12-23]
Hi,
There are many different ways you can accomplish this, and exactly how you go about it depends on your particular needs.
Do you need to be able to interact with a running application, or are you just looking to reuse some logic written in your VB.NET app from your access application? If you are just looking to reuse application logic, then you can just add a reference to the exe to your wrapper dll (as if the exe was a dll), and you should have access to all the publicly visible types in the exe just like you would with a dll reference (in which case the exe will act just like a dll an won't actually spawn a new instance.)
If you need to interact with a running executable, then there are several other options available.
-Scott Wisniewski
Hi Scott,
Thanks for your reply.
I have to interact with a running executable and there might be multiple instances of the executable at any time. How can I reference a particular executable instance and call the method?
I have the referencing thing, setup right now but the specs have changed which now involves calling the method from a running instance of an executable.
TIA
How can I get remoting to work without the use of IIS or any webserver. The samples that I see have
http://localhost:<port number> to specify where the remoting objects are.
Is it possible to do this without remoting? It seems like overkill to do this via TCP.
My situation is this.
The user opens an instance of the application WITHOUT startup parameters. They then can open the application WITH startup parameters while the first instance is running.
I want to check if there's an instance running (already got that), and if there is, pass it the startup parameters.
Any suggestions?
Oh. and I should probably mention...this is a clickonce app.
I'm looking at using the StartupNextInstance handler, but it doesn't look to promising for a click once application.
It sounds to me like you have a model where you have 1 long lived instance of your application that needs to do work, and several other short-lived instances that will send it commands to execute and then close down.
Is this correct?
There are several other approaches besides remoting you can use to accomplish this. One method is to use MSMQ (Microsoft Message Queue). This has the advantage of already having support in the .NET Framework via the System.Messaging namespace. It does, however, have the disadvantage of requiring you to either have a shared message queue server available or to install MSMQ on all of your client machines, which may complicate your deployment. You can check out the MSDN documentation for the System.Messaging namespace here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemmessaging.asp.
If the deployment requirements of MSMQ will not work for you, then you can try using named pipes. These have the advantage of not requiring complex deployment. However, they have the disadvantage of not having direct .NET support, requiring you to use interop to call into the Win32 API. You can find information about the Named Pipes API here:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/createnamedpipe.asp
-Scott Wisniewski
Itsounds to me like you have a model where you have 1 long lived instance
of your application that needs to do work, and several other
short-lived instances that will send it commands to execute and then
close down.
Is this correct?
Not quite.
The users always launch the ClickOnce application from a URL to insure they are using the current version.
Sometimes, the URL contains additional paramaters so that they are taken directly to an area of the application.
When they open the app a second time and they already have an instance
we want it to re-use the first instance but pass the paramaters from
the 2nd.
I've looked at StartUpNextInstance and don't think that'll work. I think remoting might not be the way to go either.
In either case you should be able to use either MSMQ or named pipes.
-Scott
I'm doing pretty much the same thing using COPYDATASTRUCTURE and the WndProc. Have you looked into that approach?
I hadn't looked into that. That's actually the kind of lead I was hoping to get. However, I found an easier way. (though a bit of a hack)
In the New() method od the application I strip the parameters from the querysting and write them to a file. Then when the StartupNextInstance is run I read the paramaters from the file and delete it.
Not pretty, but it'll work well for my situation.