Reputation: 3443
I am writing programs that use another Application.
Lets say the Application ProgID is TheCompany.TheProg
up untill now, i was using "Add References/COM" and selecting the TheProg Type Lib
but it was mentioned by the 3ed party vendor that creating Interop DLLs is not supported and can cause some interface changes with version upgrades.
my question is: How can i reference this TheCompany.TheProg COM+ object without the creation of the Interop DLL?
I know i can use
Type theProgType = Type.GetTypeFromProgID("TheCompany.TheProg");
dynamic myObject = Activator.CreateInstance(theProgType);
dynamic version = myObject.AMethod();
but:
1. i need to cast Everything dynamic which require .NET FW v4!
unless i want to use theProgType.InvokeMethod() :)
2. I Have no IntelliSense.
Thanks a lot
Upvotes: 3
Views: 2532
Reputation: 61744
Can't help myself giving a late answer to this question, as I just dealt with a similar thing.
Basically, you could define your own subset of their interfaces to be used via late binding only, here's how:
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] // late binding only
[Guid("00020400-0000-0000-C000-000000000046")] // IDispatch's GUID
interface IMyLateBindingAdaptor
{
// a subset of IWebBrowser2 [http://msdn.microsoft.com/en-us/library/aa752127(v=vs.85).aspx]
string LocationURL { get; }
void Navigate(string url, ref object flags, ref object TargetFrameName, ref object PostData, ref object Headers);
}
Make sure the names and signatures of the defined properties and method match the specification from your vendor.
Using it:
var adaptor = this.webBrowser1.ActiveXInstance as IMyLateBindingAdaptor;
if (null == adaptor)
throw new ApplicationException("No late binding.");
object missing = Type.Missing; // VT_EMPTY
adaptor.Navigate("http://www.example.com", ref missing, ref missing, ref missing, ref missing);
MessageBox.Show(adaptor.LocationURL);
In my opinion, it's better than dynamics as it gives you compile-time type safety (sort of) and IntelliSense.
Upvotes: 2