C# Interface for Win32 DLL functions with pointers?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fred West

    C# Interface for Win32 DLL functions with pointers?

    I am building a C# interface to a 3rd party win32 dll. The win32 function
    has the following definition:

    extern "C" int __declspec(dlli mport) _stdcall w32func(unsigne d char id, char
    *pname);

    Now in my C# class how do I declare the function. So far from the
    documentation, I have come up with the following:

    [DllImport("thea pi.dll", EntryPoint="w32 func")]
    private static extern unsafe int W32Func(byte board id,
    [MarshalAs(Unman agedType.LPStr)] string name);

    Any comments or suggestions are greatly appreciated,

    Fred W.


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: C# Interface for Win32 DLL functions with pointers?

    Fred,

    That's the way I would do it. I am curious about is the first parameter
    with the name of "board id". That space is going to give you a syntax
    error.

    Also, you don't need the unsafe modifier. There is nothing about that
    declaration that is unsafe.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Fred West" <fredwemail-news@yahoo.com> wrote in message
    news:eRkJvg2cFH A.2688@TK2MSFTN GP14.phx.gbl...[color=blue]
    >I am building a C# interface to a 3rd party win32 dll. The win32 function
    >has the following definition:
    >
    > extern "C" int __declspec(dlli mport) _stdcall w32func(unsigne d char id,
    > char *pname);
    >
    > Now in my C# class how do I declare the function. So far from the
    > documentation, I have come up with the following:
    >
    > [DllImport("thea pi.dll", EntryPoint="w32 func")]
    > private static extern unsafe int W32Func(byte board id,
    > [MarshalAs(Unman agedType.LPStr)] string name);
    >
    > Any comments or suggestions are greatly appreciated,
    >
    > Fred W.
    >[/color]


    Comment

    • Fred West

      #3
      Re: C# Interface for Win32 DLL functions with pointers?

      That was just a typo, it should just be "byte id". Thanks

      - Fred


      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
      message news:etPY7j2cFH A.3940@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Fred,
      >
      > That's the way I would do it. I am curious about is the first
      > parameter with the name of "board id". That space is going to give you a
      > syntax error.
      >
      > Also, you don't need the unsafe modifier. There is nothing about that
      > declaration that is unsafe.
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "Fred West" <fredwemail-news@yahoo.com> wrote in message
      > news:eRkJvg2cFH A.2688@TK2MSFTN GP14.phx.gbl...[color=green]
      >>I am building a C# interface to a 3rd party win32 dll. The win32 function
      >>has the following definition:
      >>
      >> extern "C" int __declspec(dlli mport) _stdcall w32func(unsigne d char id,
      >> char *pname);
      >>
      >> Now in my C# class how do I declare the function. So far from the
      >> documentation, I have come up with the following:
      >>
      >> [DllImport("thea pi.dll", EntryPoint="w32 func")]
      >> private static extern unsafe int W32Func(byte board id,
      >> [MarshalAs(Unman agedType.LPStr)] string name);
      >>
      >> Any comments or suggestions are greatly appreciated,
      >>
      >> Fred W.
      >>[/color]
      >
      >[/color]


      Comment

      Working...