Unmanaged code

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

    Unmanaged code

    Hello

    I've got a DLL from a 3rd party vendor and they wrote the DLL in C++ so I
    can't just easily add a reference to it. How do I add that dll, to my C#
    application?

    Any idea, examples?



  • Michael Nemtsev

    #2
    Re: Unmanaged code

    Hello Jason,

    Using platform invoke
    Read there http://msdn2.microsoft.com/en-gb/library/ms173184.aspx and see
    sample http://msdn2.microsoft.com/en-gb/library/ms173187.aspx of calling
    WinAPI


    JHello
    J>
    JI've got a DLL from a 3rd party vendor and they wrote the DLL in C++
    Jso I can't just easily add a reference to it. How do I add that dll,
    Jto my C# application?
    J>
    JAny idea, examples?
    J>
    ---
    WBR,
    Michael Nemtsev :: blog: http://spaces.live.com/laflour

    "At times one remains faithful to a cause only because its opponents do not
    cease to be insipid." (c) Friedrich Nietzsche


    Comment

    • Jason

      #3
      Re: Unmanaged code

      Ok

      I see the........

      System.Runtime. InteropServices .DllImport("win mm.DLL", EntryPoint =
      "PlaySound" , SetLastError = true)]
      private static extern bool PlaySound(strin g szSound, System.IntPtr
      hMod, PlaySoundFlags flags);


      but how do know or find out what the entry point of a 3rd party DLL would
      be?

      "Michael Nemtsev" <nemtsev@msn.co mwrote in message
      news:1799a79b3b 9d8e8c8cb504f2d 47d4@msnews.mic rosoft.com...
      Hello Jason,
      >
      Using platform invoke
      Read there http://msdn2.microsoft.com/en-gb/library/ms173184.aspx and see
      sample http://msdn2.microsoft.com/en-gb/library/ms173187.aspx of calling
      WinAPI
      >
      >
      JHello
      JJI've got a DLL from a 3rd party vendor and they wrote the DLL in C++
      Jso I can't just easily add a reference to it. How do I add that dll,
      Jto my C# application?
      JJAny idea, examples?
      J---
      WBR,
      Michael Nemtsev :: blog: http://spaces.live.com/laflour
      >
      "At times one remains faithful to a cause only because its opponents do
      not cease to be insipid." (c) Friedrich Nietzsche
      >
      >

      Comment

      • Michael Nemtsev

        #4
        Re: Unmanaged code

        Hello Jason,

        Obviously from the your dll manuals. They should provide u the list of functions
        they export
        btw, read a bit there http://samples.gotdotnet.com/quickst...ke_Simple.aspx

        JOk
        J>
        JI see the........
        J>
        JSystem.Runtime .InteropService s.DllImport("wi nmm.DLL", EntryPoint =
        J"PlaySound" , SetLastError = true)]
        Jprivate static extern bool PlaySound(strin g szSound,
        JSystem.IntPtr
        JhMod, PlaySoundFlags flags);
        Jbut how do know or find out what the entry point of a 3rd party DLL
        Jwould be?
        J>
        J"Michael Nemtsev" <nemtsev@msn.co mwrote in message
        Jnews:1799a79b3 b9d8e8c8cb504f2 d47d4@msnews.mi crosoft.com...
        J>
        >Hello Jason,
        >>
        >Using platform invoke
        >Read there http://msdn2.microsoft.com/en-gb/library/ms173184.aspx and
        >see
        >sample http://msdn2.microsoft.com/en-gb/library/ms173187.aspx of
        >calling
        >WinAPI
        >JHello
        >JJI've got a DLL from a 3rd party vendor and they wrote the DLL
        >in C++
        >Jso I can't just easily add a reference to it. How do I add that
        >dll,
        >Jto my C# application?
        >JJAny idea, examples?
        >J---
        >WBR,
        >Michael Nemtsev :: blog: http://spaces.live.com/laflour
        >"At times one remains faithful to a cause only because its opponents
        >do not cease to be insipid." (c) Friedrich Nietzsche
        >>
        ---
        WBR,
        Michael Nemtsev :: blog: http://spaces.live.com/laflour

        "At times one remains faithful to a cause only because its opponents do not
        cease to be insipid." (c) Friedrich Nietzsche


        Comment

        • Wilfried Mestdagh

          #5
          Re: Unmanaged code

          Hi Jason,

          You only need the EntryPoint if you choose a different name. For example
          this is a part of code to access a DLL of me:

          [DllImport(Tools .dllName, EntryPoint = "Initialize ")]
          public static extern void InitializeApi() ;
          [DllImport(Tools .dllName)]
          public static extern void Disconnect();

          The first one, 'Initialize' is an error in C# because it is already
          existant, so I renamed it to InitializeApi. The second one 'Disconnect'
          I did not rename, so no EntryPoint needed.

          hope this helps.

          --
          rgds, Wilfried [MapPoint MVP]

          Comment

          • Willy Denoyette [MVP]

            #6
            Re: Unmanaged code

            "Jason" <someone@micros oft.comwrote in message
            news:OSb3J5S$GH A.924@TK2MSFTNG P03.phx.gbl...
            Ok
            >
            I see the........
            >
            System.Runtime. InteropServices .DllImport("win mm.DLL", EntryPoint = "PlaySound" ,
            SetLastError = true)]
            private static extern bool PlaySound(strin g szSound, System.IntPtr hMod,
            PlaySoundFlags flags);
            >
            >
            but how do know or find out what the entry point of a 3rd party DLL would be?
            >
            Are you sure the DLL is exporting C style functions, that is, is the DLL meant to be used
            from clients using "C style" bindings? C# and PInvoke cannot call exported C++ class
            members. Another thing you need to know is the calling convention used for the exports. You
            can try to get at the exports using tools like depends.exe and dumpbin.exe from the platform
            SDK, but what you really need is the documentation that describes the exported functions
            their argument types ,calling convention and semantics .

            Willy.

            Comment

            Working...