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 / C++ / MFC
  4. How use win32 dll in c#

How use win32 dll in c#

Scheduled Pinned Locked Moved C / C++ / MFC
csharpquestion
4 Posts 3 Posters 2 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
    ashish8patil
    wrote on last edited by
    #1

    Hello All , I create win32 dll .with simple function Add(int,int). using dumpbin i can see add function is in my dll. Then i create new c# console application. in that folder i put trydll.dll,trydll.lib . then in .cs file i add using System.Runtime.InteropServices; my class was like this ------ class Program { [DllImport("trydll.dll")] public static extern int Add(int a, int b); static void Main(string[] args) { int c; //int a=2; c = Add(5, 6); Console.Write(c); } } ------- when i run prog .i get run time exception \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'trydll.dll ': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at dlltry.Program.Add(Int32 a, Int32 b) at dlltry.Program.Main(String[] args) in C:\Documents and Settings\........ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ What is my mistake

    C _ 2 Replies Last reply
    0
    • A ashish8patil

      Hello All , I create win32 dll .with simple function Add(int,int). using dumpbin i can see add function is in my dll. Then i create new c# console application. in that folder i put trydll.dll,trydll.lib . then in .cs file i add using System.Runtime.InteropServices; my class was like this ------ class Program { [DllImport("trydll.dll")] public static extern int Add(int a, int b); static void Main(string[] args) { int c; //int a=2; c = Add(5, 6); Console.Write(c); } } ------- when i run prog .i get run time exception \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'trydll.dll ': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at dlltry.Program.Add(Int32 a, Int32 b) at dlltry.Program.Main(String[] args) in C:\Documents and Settings\........ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ What is my mistake

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      ashish8patil wrote:

      in that folder i put trydll.dll,trydll.lib .

      Is that the working directory of your application ? Make sure this is the case. I'm not a C# expert but I suppose you can find that in the project options.

      Cédric Moonen Software developer
      Charting control [v2.0] OpenGL game tutorial in C++

      A 1 Reply Last reply
      0
      • C Cedric Moonen

        ashish8patil wrote:

        in that folder i put trydll.dll,trydll.lib .

        Is that the working directory of your application ? Make sure this is the case. I'm not a C# expert but I suppose you can find that in the project options.

        Cédric Moonen Software developer
        Charting control [v2.0] OpenGL game tutorial in C++

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

        yes i put it in working dir

        1 Reply Last reply
        0
        • A ashish8patil

          Hello All , I create win32 dll .with simple function Add(int,int). using dumpbin i can see add function is in my dll. Then i create new c# console application. in that folder i put trydll.dll,trydll.lib . then in .cs file i add using System.Runtime.InteropServices; my class was like this ------ class Program { [DllImport("trydll.dll")] public static extern int Add(int a, int b); static void Main(string[] args) { int c; //int a=2; c = Add(5, 6); Console.Write(c); } } ------- when i run prog .i get run time exception \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'trydll.dll ': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at dlltry.Program.Add(Int32 a, Int32 b) at dlltry.Program.Main(String[] args) in C:\Documents and Settings\........ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ What is my mistake

          _ Offline
          _ Offline
          _AnsHUMAN_
          wrote on last edited by
          #4

          you need to put the mangled name for the function. [DllImport("/*put the path of the dll*/")] public static extern int Add/*mangled function name instead of Add*/(int a, int b);

          You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

          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