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. Strange DLL Calls in C# - Help

Strange DLL Calls in C# - Help

Scheduled Pinned Locked Moved C#
helpcsharpc++htmlcom
3 Posts 3 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.
  • M Offline
    M Offline
    Marc Chabot
    wrote on last edited by
    #1

    Hello All, I'm attempting to create a C# Wrapper around a DLL from Diamond Systems. The problem I'm having is that the DLL is very dependant on Pointers. I've suffered through must of it already, with a lot of help from these boards. However I've run into something I can't find an answer for: I need to pass a Struct containing a Pointer to a Function. Here is the C++ Code: typedef struct { DSCUserInterruptFunction func; BYTE int_mode; } DSCUSERINTFUNCTION; typedef void (*DSCUserInterruptFunction) (void* parameter); The DLL call is: BYTE dscSetUserInterruptFunction(DSCB board, DSCUSERINTFUNCTION* dscuserintfunction); Diamond Systems manual: http://docs.diamondsystems.com/dscud/manual\_DSCUD\_Function\_Reference.html If I can get this to run then the project is complete! Thanks in advance for any help you can offer me. If it is of any interest I just placed my order for next years MSDN subscription through Code Project, thus becomming a supporting member. Thanks again. -Marc

    N L 2 Replies Last reply
    0
    • M Marc Chabot

      Hello All, I'm attempting to create a C# Wrapper around a DLL from Diamond Systems. The problem I'm having is that the DLL is very dependant on Pointers. I've suffered through must of it already, with a lot of help from these boards. However I've run into something I can't find an answer for: I need to pass a Struct containing a Pointer to a Function. Here is the C++ Code: typedef struct { DSCUserInterruptFunction func; BYTE int_mode; } DSCUSERINTFUNCTION; typedef void (*DSCUserInterruptFunction) (void* parameter); The DLL call is: BYTE dscSetUserInterruptFunction(DSCB board, DSCUSERINTFUNCTION* dscuserintfunction); Diamond Systems manual: http://docs.diamondsystems.com/dscud/manual\_DSCUD\_Function\_Reference.html If I can get this to run then the project is complete! Thanks in advance for any help you can offer me. If it is of any interest I just placed my order for next years MSDN subscription through Code Project, thus becomming a supporting member. Thanks again. -Marc

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      You need to read up on delegates in C#, I would recommend you start here: Delegates Tutorial[^] from the C# Programmer's Reference. - Nick Parker
      My Blog | My Articles

      1 Reply Last reply
      0
      • M Marc Chabot

        Hello All, I'm attempting to create a C# Wrapper around a DLL from Diamond Systems. The problem I'm having is that the DLL is very dependant on Pointers. I've suffered through must of it already, with a lot of help from these boards. However I've run into something I can't find an answer for: I need to pass a Struct containing a Pointer to a Function. Here is the C++ Code: typedef struct { DSCUserInterruptFunction func; BYTE int_mode; } DSCUSERINTFUNCTION; typedef void (*DSCUserInterruptFunction) (void* parameter); The DLL call is: BYTE dscSetUserInterruptFunction(DSCB board, DSCUSERINTFUNCTION* dscuserintfunction); Diamond Systems manual: http://docs.diamondsystems.com/dscud/manual\_DSCUD\_Function\_Reference.html If I can get this to run then the project is complete! Thanks in advance for any help you can offer me. If it is of any interest I just placed my order for next years MSDN subscription through Code Project, thus becomming a supporting member. Thanks again. -Marc

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        try this:

        delegate void DSCUserInterruptFunction (IntPtr param);

        struct DSCUSERINTFUNCTION
        {
        public DSCUserInterruptFunction func;
        public byte mode;
        }

        [DllImport(diamond.dll)]
        extern static byte dscSetUserInterruptFunction(DSCB board, ref DSCUSERINTFUNCTION dscuserintfunction);

        static void DSCUserInterruptFunctionImpl(IntPtr param)
        {

        }

        DSCUSERINTFUNCTION foo = new DSCUSERINTFUNCTION();
        foo.func = new DSCUserInterruptFunction(DSCUserInterruptFunctionImpl);

        byte result = dscSetUserInterruptFunction(board, ref foo);

        top secret
        Download xacc-ide 0.0.3 now!
        See some screenshots

        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