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. How To Use a C Libray in your C# Program

How To Use a C Libray in your C# Program

Scheduled Pinned Locked Moved C#
c++tutorialcsharpwinformshardware
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.
  • A Offline
    A Offline
    Andy202
    wrote on last edited by
    #1

    For an item of hardware I have written a Shared library to make it easy to use the API for this hardware. The library sets up data structures and handles, buffers etc for simple program use. For example to arrange data to be transmitted I call routings like:- UINT16 TransmitData( UINT unit, UINT addr, TXBUFFER * tx_buffer ); However in VS2008 I used C++ in a MFC dialog application, which all worked well. Having moved to VS2010, I now see that the intellisence does not work with this product. So my thoughts were to use C# for the Windows forms and link in the Shared Library. I have built the Shared Library in VS2010 so I need to understand how to access these function in a C# program. Is this using ‘Wrappers’ and how does the libraries API001.LIB and API001.h files link in? For a C++ MFC program I included the headers and LIB files with the PATH set up for the DLL’s. The libray is built using C. Many thanks, Andy

    L R 2 Replies Last reply
    0
    • A Andy202

      For an item of hardware I have written a Shared library to make it easy to use the API for this hardware. The library sets up data structures and handles, buffers etc for simple program use. For example to arrange data to be transmitted I call routings like:- UINT16 TransmitData( UINT unit, UINT addr, TXBUFFER * tx_buffer ); However in VS2008 I used C++ in a MFC dialog application, which all worked well. Having moved to VS2010, I now see that the intellisence does not work with this product. So my thoughts were to use C# for the Windows forms and link in the Shared Library. I have built the Shared Library in VS2010 so I need to understand how to access these function in a C# program. Is this using ‘Wrappers’ and how does the libraries API001.LIB and API001.h files link in? For a C++ MFC program I included the headers and LIB files with the PATH set up for the DLL’s. The libray is built using C. Many thanks, Andy

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      you would need a DLL file and P/Invoke technology; you can't use any .h files or .lib files. Maybe read this[^] first. Things are easiest when all arrays (or objects) get allocated by managed (C#) code, then passed to the native world; that works easier than the other way around! :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      1 Reply Last reply
      0
      • A Andy202

        For an item of hardware I have written a Shared library to make it easy to use the API for this hardware. The library sets up data structures and handles, buffers etc for simple program use. For example to arrange data to be transmitted I call routings like:- UINT16 TransmitData( UINT unit, UINT addr, TXBUFFER * tx_buffer ); However in VS2008 I used C++ in a MFC dialog application, which all worked well. Having moved to VS2010, I now see that the intellisence does not work with this product. So my thoughts were to use C# for the Windows forms and link in the Shared Library. I have built the Shared Library in VS2010 so I need to understand how to access these function in a C# program. Is this using ‘Wrappers’ and how does the libraries API001.LIB and API001.h files link in? For a C++ MFC program I included the headers and LIB files with the PATH set up for the DLL’s. The libray is built using C. Many thanks, Andy

        R Offline
        R Offline
        Rick Shaub
        wrote on last edited by
        #3

        You can create a C++/CLI class library and include the .lib and .h there. Then create a managed class in C++ that wraps the functions. Finally, make a reference from the C# application to the C++/CLI project.

        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