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. C#
  4. DLL wrapper and structs

DLL wrapper and structs

Scheduled Pinned Locked Moved C#
questioncsharplinuxhelpworkspace
2 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.
  • P Offline
    P Offline
    pithhelmet
    wrote on last edited by
    #1

    Hi Everyone - I am trying to create a C# wrapper around a legacy C .DLL I am stuck on one implementation area... There is a DLL function called GetDateTime extern "C" bool GetDateTime( DateTimeStruct &dateTime ) is how the SDK says it is to be implementated. I have created a wrapper shell for this function below... [DllImport("CarChipSDK", EntryPoint="GetDateTime")] public static extern bool GetDateTime ( //// what goes here??? ); I have create the struc in BOTH the main program, and the shell [StructLayout(LayoutKind.Sequential)] public struct DateTimeStruct { public int year; public int month; public int day; public int hour; public int minute; public int second; } Here are the questions... 1) Do I need to create a struct in both the caller and callee classes? 2) How do i setup the caller class to send the struct to the callee class? thanks tony

    T 1 Reply Last reply
    0
    • P pithhelmet

      Hi Everyone - I am trying to create a C# wrapper around a legacy C .DLL I am stuck on one implementation area... There is a DLL function called GetDateTime extern "C" bool GetDateTime( DateTimeStruct &dateTime ) is how the SDK says it is to be implementated. I have created a wrapper shell for this function below... [DllImport("CarChipSDK", EntryPoint="GetDateTime")] public static extern bool GetDateTime ( //// what goes here??? ); I have create the struc in BOTH the main program, and the shell [StructLayout(LayoutKind.Sequential)] public struct DateTimeStruct { public int year; public int month; public int day; public int hour; public int minute; public int second; } Here are the questions... 1) Do I need to create a struct in both the caller and callee classes? 2) How do i setup the caller class to send the struct to the callee class? thanks tony

      T Offline
      T Offline
      Tym
      wrote on last edited by
      #2

      I haven't done this before, but have been researching for my own project. This is how I think it should work... define the struct in your "callee" class namespace: namespace myNS { [StructLayout(LayoutKind.Sequential)] public struct DateTimeStruct{...} class Callee{ [DllImport("CarChipSDK", EntryPoint="GetDateTime")] public static extern bool GetDateTime (out DateTimeStruct dateTime); } } in "Caller" add MyNS as reference, add new DateTimeStruct variable and then call your function, passing this variable by reference: using MyNS; ... DateTimeStruct dts; ... Callee.GetDateTime(out dts); ... // now you can use dts members: int hr = dts.hour; Let me know if this works. Tym!

      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