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. Managed C++/CLI
  4. Managing native struct returned from function called in managed wrapper

Managing native struct returned from function called in managed wrapper

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++helptutorial
5 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.
  • A Offline
    A Offline
    alleyes 0
    wrote on last edited by
    #1

    I have a function in a wrapper DLL that points to a native function. The native function returns a struct and I am looking for a solution to Marshall the struct to be called by C# Winform app. The managed function: M_USB_DEVICE_DESCRIPTOR SXManaged::M_GetDeviceInfo(void) Where: M_USB_DEVICE_DESCRIPTOR is a managed struct that is virutally the same as the native struct SXManaged is the managed class in the wrapper DLL. Inside the managed function I call the native function: usb_dd = umc->GetDeviceInfo(); Where: usb_dd is a native struct variable of type USB_DEVICE_DESCRIPTOR. The members of that are very blittable - bytes and unsigned short. umc is an object that is a pointer to the native class that holds native function GetDeviceInfo() I can't leave the return type as a native struct type as it's being called in C#. I've looked as far as I can to try and see how to do this but coming up short. Any help greatly appreciated. Al

    Jer 29:11

    N 1 Reply Last reply
    0
    • A alleyes 0

      I have a function in a wrapper DLL that points to a native function. The native function returns a struct and I am looking for a solution to Marshall the struct to be called by C# Winform app. The managed function: M_USB_DEVICE_DESCRIPTOR SXManaged::M_GetDeviceInfo(void) Where: M_USB_DEVICE_DESCRIPTOR is a managed struct that is virutally the same as the native struct SXManaged is the managed class in the wrapper DLL. Inside the managed function I call the native function: usb_dd = umc->GetDeviceInfo(); Where: usb_dd is a native struct variable of type USB_DEVICE_DESCRIPTOR. The members of that are very blittable - bytes and unsigned short. umc is an object that is a pointer to the native class that holds native function GetDeviceInfo() I can't leave the return type as a native struct type as it's being called in C#. I've looked as far as I can to try and see how to do this but coming up short. Any help greatly appreciated. Al

      Jer 29:11

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Native struct and managed struct is different. Your best bet would be to create a managed class with necessary details and fill it with the values from native function. This instance can be consumed from C#.

      Best Wishes, Navaneeth

      A 1 Reply Last reply
      0
      • N N a v a n e e t h

        Native struct and managed struct is different. Your best bet would be to create a managed class with necessary details and fill it with the values from native function. This instance can be consumed from C#.

        Best Wishes, Navaneeth

        A Offline
        A Offline
        alleyes 0
        wrote on last edited by
        #3

        The "managed" function shown in the illustration IS from a managed class. :confused:

        Jer 29:11

        N 1 Reply Last reply
        0
        • A alleyes 0

          The "managed" function shown in the illustration IS from a managed class. :confused:

          Jer 29:11

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          Well, your return type is M_USB_DEVICE_DESCRIPTOR which is a managed type, right? If yes, what is the problem ate you facing in using it from C#?

          Navaneeth How to use google | Ask smart questions

          A 1 Reply Last reply
          0
          • N N a v a n e e t h

            Well, your return type is M_USB_DEVICE_DESCRIPTOR which is a managed type, right? If yes, what is the problem ate you facing in using it from C#?

            Navaneeth How to use google | Ask smart questions

            A Offline
            A Offline
            alleyes 0
            wrote on last edited by
            #5

            Hi, I have a managed version of the struct on the C# side which is easy because the struct contains primitive members. The issue is marshalling the struct from the managed function to the native function that is called by the managed one.

            Jer 29:11

            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