Reference Question
-
I have a Reference Question. I am faily new to C# so this might be a very basic question. I have my references folder in my project. I can add and delete them as needed. But I am trying to add two references that have the same name but different version numbers. But I need both because the both do something different for me. Is there a way to add a reference that is the same name and type but a different version number? What I am trying to do is connect to a COM server. The Reference is to the COM type library so that I can access it and get all of the data out of it. The problem being is I am supposed to support two versions of the same server. When I try to add the reference it states that the type library already exists. When I add the reference I add it from the location on my C drive and it adds it to my project. Is there a way not to add it to my project, but point to it with a path and take whatever reference I need whenever I need it and not have it part of my project?
-
I have a Reference Question. I am faily new to C# so this might be a very basic question. I have my references folder in my project. I can add and delete them as needed. But I am trying to add two references that have the same name but different version numbers. But I need both because the both do something different for me. Is there a way to add a reference that is the same name and type but a different version number? What I am trying to do is connect to a COM server. The Reference is to the COM type library so that I can access it and get all of the data out of it. The problem being is I am supposed to support two versions of the same server. When I try to add the reference it states that the type library already exists. When I add the reference I add it from the location on my C drive and it adds it to my project. Is there a way not to add it to my project, but point to it with a path and take whatever reference I need whenever I need it and not have it part of my project?
The problem you're looking at is those two libraries are using the same GUIDS, so, there's no way for Visual Studio to tell the difference between the two. You're only option is to use all late-binding methods to use these libraries, but that's going to be VERY painful to write. You won't have any Intellisense support at all. It'll be like writing code in Notepad.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
The problem you're looking at is those two libraries are using the same GUIDS, so, there's no way for Visual Studio to tell the difference between the two. You're only option is to use all late-binding methods to use these libraries, but that's going to be VERY painful to write. You won't have any Intellisense support at all. It'll be like writing code in Notepad.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
What exactly is a late-binding method? How would I set it up so that I can use these methods? Are there any examples out there?
Late Binding is, when your code runs, the objects and methods are not exactly known before hand. You ahve to create the objects, then manipulate them using methods that lookup and execute the object's methods and properties, kind of like this[^]. The problem with the example listed is that it won't work with your problem because in order to create the object "Excel.Application", the COM component must be registered. Since your two component most like have the same names, you can't register them both. Or can you?? You'll have to investigate this yourself since we know nothing of your components. I seem to remember a brief foray into registrationless-COM a few years back, but I haven't heard anything about it since. This involves writing managed C# custom wrappers around the COM components, but documentation and tools on the technique are just about impossible to come by now-a-days, so I think this is a dead end.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Late Binding is, when your code runs, the objects and methods are not exactly known before hand. You ahve to create the objects, then manipulate them using methods that lookup and execute the object's methods and properties, kind of like this[^]. The problem with the example listed is that it won't work with your problem because in order to create the object "Excel.Application", the COM component must be registered. Since your two component most like have the same names, you can't register them both. Or can you?? You'll have to investigate this yourself since we know nothing of your components. I seem to remember a brief foray into registrationless-COM a few years back, but I haven't heard anything about it since. This involves writing managed C# custom wrappers around the COM components, but documentation and tools on the technique are just about impossible to come by now-a-days, so I think this is a dead end.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Here is the code. object padobj = System.Runtime.InteropServices.Marshal.GetActiveObject("PowerPCB.Application"); padsApp = (PowerPCB.Application)padobj; View.Doc.padsDoc = padsApp.ActiveDocument; View.Doc.padsDoc.SelectionChange += new PowerPCB._PowerPCBDocEvents_SelectionChangeEventHandler(eeSelection); padsApp.UnlockServer(); If you notice I am setting padsApp to the the object. But I have to cast the object to PowerPCB.Application. The problem that I am running into is the PowerPCB reference has two versions. I have no problem connecting to the loaded PowerPCB reference, but when I try to connect to the other version I crash when I try to use the padsApp object because I am not using the correct version of the PowerPCB reference. But if I change out the reference and restart the program I am able to connect to the other version just fine. So basically there is no way to point to a reference in a specific location and use that specific reference? It has to be loaded into my project?
-
Here is the code. object padobj = System.Runtime.InteropServices.Marshal.GetActiveObject("PowerPCB.Application"); padsApp = (PowerPCB.Application)padobj; View.Doc.padsDoc = padsApp.ActiveDocument; View.Doc.padsDoc.SelectionChange += new PowerPCB._PowerPCBDocEvents_SelectionChangeEventHandler(eeSelection); padsApp.UnlockServer(); If you notice I am setting padsApp to the the object. But I have to cast the object to PowerPCB.Application. The problem that I am running into is the PowerPCB reference has two versions. I have no problem connecting to the loaded PowerPCB reference, but when I try to connect to the other version I crash when I try to use the padsApp object because I am not using the correct version of the PowerPCB reference. But if I change out the reference and restart the program I am able to connect to the other version just fine. So basically there is no way to point to a reference in a specific location and use that specific reference? It has to be loaded into my project?
SRogers88 wrote:
I have no problem connecting to the loaded PowerPCB reference, but when I try to connect to the other version I crash when I try to use the padsApp object because I am not using the correct version of the PowerPCB reference
You can't do it this way. You're going to have to create two seperate wrapper projects. The first is going to have to reference the first version of this COM server and the second is going to have to reference the second version. You need to set references to the .DLL files themselves and not to what you find under the COM tab in the Add Reference dialog box. You're then going to need to re-expose the classes, properties, methods, and events you want to use for each version of the servers, as appropriate. Then, when you get both servers wrapped, you'll add references to both of your wrapper projects and use those COM servers through the wrappers. There is no guarantee this is going to work though. You're going tohave to experiment with this yourself to find out.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008