Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Invoking GetIPGlobalProperties from Unmanaged Application

Invoking GetIPGlobalProperties from Unmanaged Application

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpdotnetvisual-studiocomhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Derek Tortonian
    wrote on last edited by
    #1

    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.

    realJSOPR 1 Reply Last reply
    0
    • D Derek Tortonian

      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.

      realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote on last edited by
      #2
      1. Did you mean to say that IPGlobalProperties is a *static* class? 1) If you're calling IPGlobalProperties.GetIPGlobalProperties(), why aren't you referring directly to the properties contained in the return object instead of trying to find/invoke an appropriate Get 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

      D 1 Reply Last reply
      0
      • realJSOPR realJSOP
        1. Did you mean to say that IPGlobalProperties is a *static* class? 1) If you're calling IPGlobalProperties.GetIPGlobalProperties(), why aren't you referring directly to the properties contained in the return object instead of trying to find/invoke an appropriate Get 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

        D Offline
        D Offline
        Derek Tortonian
        wrote on last edited by
        #3

        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

        realJSOPR 1 Reply Last reply
        0
        • D Derek Tortonian

          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

          realJSOPR Offline
          realJSOPR Offline
          realJSOP
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups