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. DLLs in C# Application

DLLs in C# Application

Scheduled Pinned Locked Moved C#
questioncsharp
4 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
    amitmohanty
    wrote on last edited by
    #1

    I have noticed that I need not put any DLLImport statements in Windows application if I am using some DLLs. I just need to add those DLLs in the reference and then use it. My question is when is it necessary to have a DLLImport statement in my C# code? Thanks and Regards, Amit

    S 1 Reply Last reply
    0
    • A amitmohanty

      I have noticed that I need not put any DLLImport statements in Windows application if I am using some DLLs. I just need to add those DLLs in the reference and then use it. My question is when is it necessary to have a DLLImport statement in my C# code? Thanks and Regards, Amit

      S Offline
      S Offline
      Super Lloyd
      wrote on last edited by
      #2

      The DllImport are required when you want to call into pre-.NET DLL, i.e. C dll. If it's a .NET dll (i.e. an assembly) no problem, if it's a C DLL, you need to do interop. Interop is a vast topic but well documented in the SDK's documentation, I suggest you to refer to it. Basically C# need to know about the function to use it, right? C DLL define no metadata that could be used by other .NET dlls to knwo about its content (they just define C header usable by a C compiler), therefore you have to do these declaration yourself. That's the purpose of DllImpoert. You've got most of win32 API Interop declaration there: http://pinvoke.net/[^]

      A 1 Reply Last reply
      0
      • S Super Lloyd

        The DllImport are required when you want to call into pre-.NET DLL, i.e. C dll. If it's a .NET dll (i.e. an assembly) no problem, if it's a C DLL, you need to do interop. Interop is a vast topic but well documented in the SDK's documentation, I suggest you to refer to it. Basically C# need to know about the function to use it, right? C DLL define no metadata that could be used by other .NET dlls to knwo about its content (they just define C header usable by a C compiler), therefore you have to do these declaration yourself. That's the purpose of DllImpoert. You've got most of win32 API Interop declaration there: http://pinvoke.net/[^]

        A Offline
        A Offline
        amitmohanty
        wrote on last edited by
        #3

        Thanks for the answer. It, indeed, answers most of my initial questions. Now, I am trying to write a wrapper for LAPACK [http://www.netlib.org/clapack/faq.html], which is available in C and FORTRAN in C#. It is a highly optimized linear algebra subroutines. Do you have any idea about a place where I can go to learn the secret of the "writing wrappers in C#" business. Thanks and Regards, Amit -- modified at 20:24 Friday 26th August, 2005

        S 1 Reply Last reply
        0
        • A amitmohanty

          Thanks for the answer. It, indeed, answers most of my initial questions. Now, I am trying to write a wrapper for LAPACK [http://www.netlib.org/clapack/faq.html], which is available in C and FORTRAN in C#. It is a highly optimized linear algebra subroutines. Do you have any idea about a place where I can go to learn the secret of the "writing wrappers in C#" business. Thanks and Regards, Amit -- modified at 20:24 Friday 26th August, 2005

          S Offline
          S Offline
          Super Lloyd
          wrote on last edited by
          #4

          You should really learn to use the documentation coming with the SDK. In the "index" side panel there is a box named "look for", just type: "interop", "COM interop" or "data marshaling" in it and you will find a wealth of information. Alternatively, if you've got issue with the SDK documentation (strangely many .NET developer seems to ignore about its existence) you could go on MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconinteroperatingwithunmanagedcode.asp[^] Anyway about array marshaling (let's say float[]) the documentation doesn't straightforwardly explained you wether or not the whole array is copied or not to a temporary buffer every crossing the managed/unmanaged boudary (I think some attributes control that behavior). But always have the solution to use unsafe code & float* in C# or, as I prefer to write my wrappers now, use ManagedC++ (v2.0, meach cleaner, leaner and less ambiguous).

          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