jwang
2007-10-04 03:04:00 UTC
I tried to use Microsoft.VisualBasic.Interaction.GetObject() to get a
reference to a running instance of an application that registers itself as a
COM server. There seems to be a problem with the the GetObject() method.
According to the MSDN documentation GetObject() takes two augments as
following:
public static Object GetObject (
[OptionalAttribute] string PathName,
[OptionalAttribute] string Class
So the first argument is optional if the second argument is present. Here
is what the doc says:
"If PathName is a zero-length string (""), GetObject returns a new object
instance of the specified class type. If the PathName argument is omitted,
GetObject returns a currently active object of the class type specified in
Class. If no object of the specified type exists, an error occurs."
This is exactly how GetObject() method in classic VB works.
However, if I omit the first argument, I get compilation error, "Error 4 No
overload for method 'GetObject' takes '1' arguments ".
Here is my code segment:
System.Object m_ltapp;
sProgID = "LTProject747";
m_ltapp = Microsoft.VisualBasic.Interaction.GetObject(sProgID);
I use the similar code in classic VB, it works just fine.
Any suggestion? Am I missing something here?
Thanks.
reference to a running instance of an application that registers itself as a
COM server. There seems to be a problem with the the GetObject() method.
According to the MSDN documentation GetObject() takes two augments as
following:
public static Object GetObject (
[OptionalAttribute] string PathName,
[OptionalAttribute] string Class
So the first argument is optional if the second argument is present. Here
is what the doc says:
"If PathName is a zero-length string (""), GetObject returns a new object
instance of the specified class type. If the PathName argument is omitted,
GetObject returns a currently active object of the class type specified in
Class. If no object of the specified type exists, an error occurs."
This is exactly how GetObject() method in classic VB works.
However, if I omit the first argument, I get compilation error, "Error 4 No
overload for method 'GetObject' takes '1' arguments ".
Here is my code segment:
System.Object m_ltapp;
sProgID = "LTProject747";
m_ltapp = Microsoft.VisualBasic.Interaction.GetObject(sProgID);
I use the similar code in classic VB, it works just fine.
Any suggestion? Am I missing something here?
Thanks.