.NET Forum / .NET Framework / Interop / December 2004
regasm issues
|
|
Thread rating:  |
Andrew S. Giles - 10 Dec 2004 21:25 GMT Does anyone know how to get regasm to register an executable as a localserver32 instead of or in addition to an inprocserver32?
Andrew S. Giles
Eric Carlson - 10 Dec 2004 22:05 GMT I tried to do this, but i do not think it is possible (i could be wrong). Regasm registers with the com categories and points the inprocserver32 to the mscoree.dll so that the .net framework can put a wrapper around your class so that com can talk to it. This wrapper will handle all the hard stuff for you (such as the classfactory).
I could not find a way to get this to work since i too was using an outofproc server (localserver32), so i had to maually create the registry entries for the com category, then implement the class factory in my code as well as some other details.
There MAY be a way to use the .net com callable wrapper with an outofproc server (exe) but i have not found out how.
Andrew S. Giles - 10 Dec 2004 22:29 GMT I am writing the class in C#. Do you know of anywhere where it lists making a class factory for COM in C#? I havent found one anywhere.
Andrew
> I tried to do this, but i do not think it is possible (i could be wrong). > Regasm registers with the com categories and points the inprocserver32 to the [quoted text clipped - 9 lines] > There MAY be a way to use the .net com callable wrapper with an outofproc > server (exe) but i have not found out how. Eric Carlson - 11 Dec 2004 01:57 GMT Andrew,
I am going to save you some time here..
First here is an article that gives some info on the classfactory interface:
http://communities2.microsoft.com/communities/newsgroups/en-us/default.aspx?&que ry=class+factory&lang=en&cr=US&guid=&sloc=en-us&dg=microsoft.public.dotnet.frame work.interop&p=1&tid=a9dc5daa-7897-4207-8f02-7ed7900f9d31&mid=a9dc5daa-7897-4207 -8f02-7ed7900f9d31
Second, here is the basic process:
Create your c# program executable If you are using com category, register with com category (basically just look at what Regasm does, but you need to use a LocalServer32 key instead of inprocserver32 key) When your application is called, it needs to place a call to CoRegisterClassObject, and you will pass it a reference to a new instance of the IClassFactory. Then the legacy application will call your CreateInstance function which you need to implement in your IClassFactory class. This CreateInstance class needs to create a new instance of the object that contains the interface that you are providing.
You don't need to implement AddRef, Release or QueryInterface methods, the .net framework will do this for you.
If you need more detailed help, i can provide examples next week.
Good luck!
> I am writing the class in C#. Do you know of anywhere where it lists making > a class factory for COM in C#? I havent found one anywhere. [quoted text clipped - 14 lines] > > There MAY be a way to use the .net com callable wrapper with an outofproc > > server (exe) but i have not found out how. Andrew S. Giles - 13 Dec 2004 16:05 GMT Eric,
I have never heard of COM category. The only way I know of the register a C# application so as to be seen as a COM object is throgh REGASM. I looked at the registration file option that can be output from this utility and it does a LOT of stuff... am I supposed ot be writing a script of my own to do this, but listing the localserver32 keys? I thought that being a server would require a class factory (a fact you seem to agree with in your post).
I am sorry I seem so dense, this ia a whole new world for me.
my theory on execution of all of this starts with the C# application, which will accept user input and send that input (via COM) to another process which will in turn get data off of a Profibus (some hardware stuff) and send it back to me (through COM). Therefore, my applicaiton will be in its own process thread, and I need to expose the COM interface to allow the other process access to the already existing thread. Is this what the Factory class does?
Thanks for all of your help, I really appreciate it.
Andrew
> Andrew, > [quoted text clipped - 43 lines] > > > There MAY be a way to use the .net com callable wrapper with an outofproc > > > server (exe) but i have not found out how. Eric Carlson - 13 Dec 2004 16:21 GMT Andrew,
The com categories is basically registry entries that enable programs to find other programs by their ID's. REGASM creates these keys for you for an inprocess server (dll), as you have seen.
The part i am not sure about is this: my out-of-proc server (exe) gets called by c++ client, and so a new instance of my exe (and therefore a new process) is started with each call. I have not found a way around this (however this does NOT mean that there isn't another way).
It sounds like in your example, you have a windows app that will be running, making calls to COM, and hopefully receiving calls from COM, is this correct? If so, i wonder if it would be possible to expose a DLL from your application that would interact with COM (receive calls). If so, this would make your life a lot easier, since .net framework will handle all of the COM interface stuff for you, and your exe app will just run , and not be called directly.
I have also seen an example of someone who created a windows service that acted as a COM server, i don't know if this would help you or not...
Eric Carlson - 13 Dec 2004 17:51 GMT By the way, here is an article on how to do what i have been talking about, an outofproc .net com server, implementing iclassfactory
http://blogs.msdn.com/adioltean/archive/2004/06/18/159479.aspx
Andrew S. Giles - 13 Dec 2004 20:11 GMT Eric,
Thanks again for all the help.
I have the article below printed out, and am considering doing something similar, I just need to learn a bit more about ClassFactories. But that is just more reading.
My windows App is written in C#, and already running, and needs to be able to communicate wit a peice of code (C++) that will be running in a separate process on the same machine. So, yes your description is correct. I am trying to figgure out just what I need to have in the DLL to get what I need done, done. Basically this data that I am getting (when my C# app is called through COM) needs to be stuffed into an Excel spreadsheet. I have all the code to do this stuffing done in C# already, and even tied in to an Even that I made up. I was thinking that I could tie the COM method that I exposed to a call that spawns the Event, thus allowing it to work well... but, due to this being in the app, requires I expose the main app class. I am wanting to work around that. Any ideas on what I move out to allow this?
I am currently trying to make a class that calls a static member of the app... but not sure if I wil succeed.
Andrew
> By the way, here is an article on how to do what i have been talking about, > an outofproc .net com server, implementing iclassfactory > > http://blogs.msdn.com/adioltean/archive/2004/06/18/159479.aspx Eric Carlson - 13 Dec 2004 20:23 GMT The c++ code, is it calling for an inproc_server or local_server ?
Andrew S. Giles - 14 Dec 2004 16:07 GMT I originally had it calling an inproc server, so when it found the registration, it instantiated another copy of my C# applicaiton to make its calls, but because of the working directory, it crapped out. I have switched it to trying to call a local_server, but now it doesnt find the class ("class not registered") when it tries to get the IUnknown interface for the class as a Local_server. This is because I do not have the C# app registered as a local server yet.
I know I need to get it to being a local server, the app has no class factory, etc, and I think that all local servers need all of that, is that correct?
Andrew
> The c++ code, is it calling for an inproc_server or local_server ? Eric Carlson - 14 Dec 2004 18:05 GMT > I originally had it calling an inproc server, so when it found the > registration, it instantiated another copy of my C# applicaiton to make its > calls, but because of the working directory, it crapped out. What do you mean it crapped out?? As i have said before, you are much better off using the inproc server, trust me, it will make things a lot easier on the .net end. Then you don't need to worry about the classfactories and other details.
Andrew S. Giles - 14 Dec 2004 20:05 GMT Eric,
By crapped out, I mean it tried to make another copy of the application run, and because the working directory of the call did not have the right files, it did not work well. Besides, I need the legacy code to talk to the application that is already in memory, not a new version... If it talks to a new one, then the data will not get stored in the excel sheet.
Can an inproc server send events to a different process?
Andrew
> > I originally had it calling an inproc server, so when it found the > > registration, it instantiated another copy of my C# applicaiton to make its [quoted text clipped - 4 lines] > easier on the .net end. Then you don't need to worry about the > classfactories and other details. Andrew S. Giles - 14 Dec 2004 20:29 GMT OK, The situation is a little different now.
I have taken the code for the COM interface and moved it into a C# DLL. And set the Register for COM Interop flag to true. This code, in the exposed methods, instantiates a class to contain the data, and calls a custom Event.
In a separate C# applicaiton (that has a reference to the DLL) I have a class that "listens" for the DLL's methods to be called, and then implements the Event Handler functions for the custom event.
In another separate console application, this time in C++, I have referenced a copy of the same COM DLL, and gotten the object. It is currently set up as an inproc server. I take this interface, and call the methods on the COM object.
When I execute the C# application, it makes the DLL class, sends it to its listening class, and waits for user input to quit. Just like it should.
Then I start up the C++ console application, it gets a copy of the COM class, and calls the methods on it. I get a lot of lines of output (one for each function call) in this concole window, but I get no output from the C# Event handler code.
Given the above, I believe that COM in the C++ app is instantiating a NEW class from the DLL (not referencing the one that exists in the C# app already) and executing its calls, just like it is supposed to for an inproc server.
Therefore, I believe, in order to get the Event Handlers to work, the DLL needs to be a local server, so the C++ app can attach to the already existing class (in the C# process thread) and then when the DLL fires off the events, the C# app can then handle it.
Does that sound right?
If so, how do I go about making the nice DLL into a Local Server and registering it appropriately.
Andrew
Eric Carlson - 14 Dec 2004 21:29 GMT Okay i need to absorb all of this, but let me say this first...
In my experience with the outofproc server... if your c++ code calls your outofproc server you will end up with a new instance of your exe running, which means you would have the same problem of one thread talking to another. So, I would suggest to stick with the DLL, then find out how to make your com-exposed-.net-dll be able to communicate wtih your running application, or why it won't communicate. Does that makes sense?
Andrew S. Giles - 15 Dec 2004 15:43 GMT Eric,
it makes some sense. I have worked it in reverse. My .NNET code called a COM localserver32 object, and it worked just as we expected....
I plan on making this COM-enabled-.NET-DLL a localserver32 (somehow) and then seeing if my .NET application (which has a reference to the DLL) will process the information the DLL receives when called from a C++ application running in a different thread.
I hope this works... now, to understand ClassFactories, and Services, and why I need those things to accomplish this task.
Andrew
> Okay i need to absorb all of this, but let me say this first... > [quoted text clipped - 4 lines] > com-exposed-.net-dll be able to communicate wtih your running application, or > why it won't communicate. Does that makes sense? Andrew S. Giles - 15 Dec 2004 19:47 GMT So, I am trying to build the local server, based off of the article mentioned earlier... and the System.ServiceProcess namespace seems not to exist. Does anyone have any ideas as to how/why I cannot add it with a using directive?
> Okay i need to absorb all of this, but let me say this first... > [quoted text clipped - 4 lines] > com-exposed-.net-dll be able to communicate wtih your running application, or > why it won't communicate. Does that makes sense? Andrew S. Giles - 16 Dec 2004 17:29 GMT I just finished putting in a bunch of code to make my nice COM class able to be used as a localserver32. However, regasm ONLY registers things as an inprocserver.
I know I need to delete the inprocserver32 entries from the registries, but what entries do I need to add to make the class visible as a localserver?
Andrew
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|