Invoking GetIPGlobalProperties from Unmanaged Application
-
Hi, I'm writing an unmanaged application, and, am using the provided COM interfaces to invoke .NET Framework class methods. Generally, this works well, although the code is tedious to write. IPGlobalProperties is an abstract .NET class, and the GetIPGlobalProperties method is static. I am able to obtain a _MethodInfo interface pointer by invoking _Type.GetMethod_6 on the IPGlobalProperties type. Then, when I attempt to invoke _MethodInfo.Invoke_3, providing a bstr "GetIPGlobalProperties", the application crashes with an access violation. The same thing happens when I call _MethodInfo.QueryInterface, providing the IID for the _MethodBase interface (which succeeds), and, then invoking _MethodBase.Invoke_3. I'm thinking, maybe, I should be calling: _Type.InvokeMember, or something along these lines. Previously in my code, I had no problem obtaining a NetworkInformationPermission object by calling its constructor, and providing a NetworkInformationAccess value of read, so I'm wondering what is the reason for the access violations.
-
Hi, I'm writing an unmanaged application, and, am using the provided COM interfaces to invoke .NET Framework class methods. Generally, this works well, although the code is tedious to write. IPGlobalProperties is an abstract .NET class, and the GetIPGlobalProperties method is static. I am able to obtain a _MethodInfo interface pointer by invoking _Type.GetMethod_6 on the IPGlobalProperties type. Then, when I attempt to invoke _MethodInfo.Invoke_3, providing a bstr "GetIPGlobalProperties", the application crashes with an access violation. The same thing happens when I call _MethodInfo.QueryInterface, providing the IID for the _MethodBase interface (which succeeds), and, then invoking _MethodBase.Invoke_3. I'm thinking, maybe, I should be calling: _Type.InvokeMember, or something along these lines. Previously in my code, I had no problem obtaining a NetworkInformationPermission object by calling its constructor, and providing a NetworkInformationAccess value of read, so I'm wondering what is the reason for the access violations.
- Did you mean to say that
IPGlobalProperties
is a *static* class? 1) If you're callingIPGlobalProperties.GetIPGlobalProperties()
, why aren't you referring directly to the properties contained in the return object instead of trying to find/invoke an appropriateGet
method?
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013 - Did you mean to say that
-
- Did you mean to say that
IPGlobalProperties
is a *static* class? 1) If you're callingIPGlobalProperties.GetIPGlobalProperties()
, why aren't you referring directly to the properties contained in the return object instead of trying to find/invoke an appropriateGet
method?
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013Hi, John, By writing an unmanaged application, I'm actually using only COM interfaces to access .NET Framework classes. For Instance: the _Type interface All the various COM interfaces provide methods to access .NET objects, but, the syntax is different from C#. In my application, I obtain a COM interface pointer for the DefaultDomain (after loading the version 4 CLR), then, use that with the _AppDomain interface to call GetAssemblies. This returns a SAFEARRAY of _Assembly Interface pointers, which I can use to call GetTypes. Also, I can invoke: _AppDomain.Load, with an assembly Display Name, and this succeeds in loading a .NET assembly into the AppDomain. And, it goes on from there. Anyway, once you have an interface pointer to a Type, you can call GetConstructors, which returns a SAFEARRAY of _ConstructorInfo interface pointers. In this case (IPGlobalProperties), which is an abstract class, the GetConstructors method returns a SAFEARRAY with NO interface pointers,...so, it is impossible to invoke the constructor and then call GetIPGlobalProperties with an instance of IPGlobalProperties. ...In C#, you would do this (from the NetStat .NET Framework SDK Code Sample):
IPGlobalProperties ipGlobal = IPGlobalProperties.GetIPGlobalProperties();
I don't have Visual Studio installed on my computer. But, my COM application (which I'm writing in assembly language), I would attempt to invoke GetIPGlobalProperties using: _MethodInfo.Invoke, o
- Did you mean to say that
-
Hi, John, By writing an unmanaged application, I'm actually using only COM interfaces to access .NET Framework classes. For Instance: the _Type interface All the various COM interfaces provide methods to access .NET objects, but, the syntax is different from C#. In my application, I obtain a COM interface pointer for the DefaultDomain (after loading the version 4 CLR), then, use that with the _AppDomain interface to call GetAssemblies. This returns a SAFEARRAY of _Assembly Interface pointers, which I can use to call GetTypes. Also, I can invoke: _AppDomain.Load, with an assembly Display Name, and this succeeds in loading a .NET assembly into the AppDomain. And, it goes on from there. Anyway, once you have an interface pointer to a Type, you can call GetConstructors, which returns a SAFEARRAY of _ConstructorInfo interface pointers. In this case (IPGlobalProperties), which is an abstract class, the GetConstructors method returns a SAFEARRAY with NO interface pointers,...so, it is impossible to invoke the constructor and then call GetIPGlobalProperties with an instance of IPGlobalProperties. ...In C#, you would do this (from the NetStat .NET Framework SDK Code Sample):
IPGlobalProperties ipGlobal = IPGlobalProperties.GetIPGlobalProperties();
I don't have Visual Studio installed on my computer. But, my COM application (which I'm writing in assembly language), I would attempt to invoke GetIPGlobalProperties using: _MethodInfo.Invoke, o
Why don't you write a "COM-visible" .Net assembly that retrieves the info you want, and expose a COM interface that allows you to retrieve the properties. I think that would be less painful than trying to coerce the .Net class directly (and you can expand the .NET assembly to provide more functionality any time you need to.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013