D
De Roeck
Hi,
I've want to launch an application by reflection and get his handle
back.
But when I run this code in C# then it's handled correctly.
The application(-path) is started on a new thread and obj is the hwnd
of the started application.
private static BindingFlags allFlags = BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
public static object StartAUT(string applicationPath, string typeName)
{
try
{
Assembly asm = Assembly.LoadFrom(applicationPath);
Type typeUT = asm.GetType(typeName);
object obj = Activator.CreateInstance(typeUT);
MethodInfo mi = typeUT.GetMethod("Show", allFlags);
mi.Invoke(obj, null);
return obj;
}
catch{}
return null;
}
but when I launch this code in VB.NET than I received an
AmbiguousMatchException execption.
Private Shared allFlags As BindingFlags = BindingFlags.Public Or
BindingFlags.NonPublic Or BindingFlags.Static Or BindingFlags.Instance
Public Shared Function StartAUT(ByVal applicationPath As String, ByVal
typeName As String) As Object
Try
Dim asm As System.Reflection.Assembly =
System.Reflection.Assembly.LoadFrom(applicationPath)
Dim typeUT As Type = asm.GetType(typeName)
Dim obj As Object = Activator.CreateInstance(typeUT)
Dim mi As MethodInfo = typeUT.GetMethod("Show", allFlags)
mi.Invoke(obj, Nothing)
Return obj
Catch
End Try
Return Nothing
End Function
What do I wrong?
Greetings,
Davy
I've want to launch an application by reflection and get his handle
back.
But when I run this code in C# then it's handled correctly.
The application(-path) is started on a new thread and obj is the hwnd
of the started application.
private static BindingFlags allFlags = BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
public static object StartAUT(string applicationPath, string typeName)
{
try
{
Assembly asm = Assembly.LoadFrom(applicationPath);
Type typeUT = asm.GetType(typeName);
object obj = Activator.CreateInstance(typeUT);
MethodInfo mi = typeUT.GetMethod("Show", allFlags);
mi.Invoke(obj, null);
return obj;
}
catch{}
return null;
}
but when I launch this code in VB.NET than I received an
AmbiguousMatchException execption.
Private Shared allFlags As BindingFlags = BindingFlags.Public Or
BindingFlags.NonPublic Or BindingFlags.Static Or BindingFlags.Instance
Public Shared Function StartAUT(ByVal applicationPath As String, ByVal
typeName As String) As Object
Try
Dim asm As System.Reflection.Assembly =
System.Reflection.Assembly.LoadFrom(applicationPath)
Dim typeUT As Type = asm.GetType(typeName)
Dim obj As Object = Activator.CreateInstance(typeUT)
Dim mi As MethodInfo = typeUT.GetMethod("Show", allFlags)
mi.Invoke(obj, Nothing)
Return obj
Catch
End Try
Return Nothing
End Function
What do I wrong?
Greetings,
Davy