By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,062 Members | 1,374 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,062 IT Pros & Developers. It's quick & easy.

use DLL with c# DllImport

P: 2
Hej,

I want to use a DLL (1394camera.dll) (written in c++, I presume) in my c# project. The Dll contains functions in various classes, e.g. 'C1394Camera::CheckLink', according to the docs defined as follows:

int
CheckLink(
);
Trying to invoke the function in c# as:

Expand|Select|Wrap|Line Numbers
  1. public class Kamera
  2.     {
  3.         [DllImport("1394camera.dll")]
  4.         private static extern int CheckLink();
  5.         public int Anzahl;
  6.         public Kamera()
  7.         {
  8.             Anzahl = CheckLink();
  9.         }
  10.     }
doesn't work, neither does

Expand|Select|Wrap|Line Numbers
  1.    public class Kamera
  2.     {
  3.         [DllImport("1394camera.dll", EntryPoint = "C1394Camera::CheckLink")]
  4.         private static extern int CheckLink();
  5.         public int Anzahl;
  6.         public Kamera()
  7.         {
  8.             Anzahl = CheckLink();
  9.         }
  10.     }
I always get an "Unable to find an entry point named 'C1394Camera::CheckLink' in DLL '1394camera.dll'."

How can I correctly address the functions in this dll?

Thank you in advance, Franz
Mar 20 '06 #1
Share this Question
Share on Google+
6 Replies


P: 2
Hej Folks,

problem (at least this) solved. Using depends.exe exe I figured the right entry point out. This code now works (accesses the DLL-function, at least):

Expand|Select|Wrap|Line Numbers
  1.    public class Kamera
  2.     {
  3.         [DllImport("1394camera.dll", EntryPoint = "?CheckLink@C1394Camera@@QAEHXZ")]
  4.         private static extern int CheckLink();
  5.         public int Anzahl;
  6.         public Kamera()
  7.         {
  8.             Anzahl = CheckLink();
  9.         }
  10.     }
Now I get access violations and SecurityExceptions...
Mar 21 '06 #2

P: 2
Hej Folks,

problem (at least this) solved. Using depends.exe exe I figured the right entry point out. This code now works (accesses the DLL-function, at least):

Expand|Select|Wrap|Line Numbers
  1.    public class Kamera
  2.     {
  3.         [DllImport("1394camera.dll", EntryPoint = "?CheckLink@C1394Camera@@QAEHXZ")]
  4.         private static extern int CheckLink();
  5.         public int Anzahl;
  6.         public Kamera()
  7.         {
  8.             Anzahl = CheckLink();
  9.         }
  10.     }
Now I get access violations and SecurityExceptions...
Does this work? [DllImport("1394camera.dll", EntryPoint = "?CheckLink@C1394Camera@@QAEHXZ")]
Sep 13 '06 #3

P: 2
Solution found: He use command "dumpbin/exports" in Visual Studio Command Prompt to see it.
Sep 13 '06 #4

P: 1
Hello

i am new in c# and would like to use exported classes from c++ dll.
i have more then one method that i would like to use from my exported c++ class, does it mean that i need to declare more then one entry point? i tried that in a c# class and it did not work (error message:dllimport multiple attriutes)
how can i do that? how does the c# instantiate the object.

thanks,
Eila
Oct 5 '07 #5

P: 1
Hi
I have also the same problem. I wrote this code.
Expand|Select|Wrap|Line Numbers
  1. class Kamera1
  2.     {
  3.  
  4.         [DllImport("1394camera.dll", EntryPoint = "?InitCamera@C1394Camera@@QAEHXZ")]
  5.  
  6.  
  7.         public static extern void InitCamera();
  8.         //public int Anzahl, Anzahl1;
  9.  
  10.         public void Kamera2()
  11.         {                        
  12.               InitCamera();
  13.  
  14.         }
  15.  
  16.     }
  17.     class Kamera2
  18.     {
  19.  
  20.         [DllImport("1394camera.dll", EntryPoint = "?GetMaxSpeed@C1394Camera@@QAEHXZ")]
  21.  
  22.  
  23.         public static extern int GetMaxSpeed();
  24.         public int Anzahl2;
  25.  
  26.         public void Kamera3()
  27.         {
  28.             Anzahl2 = GetMaxSpeed();
  29.  
  30.         }
  31.  
  32.     }

Into the button event I wrote this code:

Expand|Select|Wrap|Line Numbers
  1.  private void button1_Click(object sender, EventArgs e)
  2.         {
  3.  
  4.  
  5.             k.Anzahl.ToString();
  6.  
  7.             textBox1.Text = k.Anzahl.ToString();
  8.  
  9.             k1.Kamera2();
  10.        }
I received as a result "0" when the camera is connected or not. I think that there is a problem. Could you help me to start acquire image in C#.
Thank's a lot
Oct 31 '08 #6

P: 2
Just curious but is there a particular reason you are choosing to include the assembly in your project using DllImport? You could just include it as a referenced assembly and include the namespace declaration in the "using" directives of the .cs files you wish to use it in. The fact it is in c++ makes no difference to the runtime compiler as long as the assembly is pre-compiled. The runtime only reads the IL code generated from an assembly, not the actual assembly itself and it doesn't care (or even know) what particular .NET language the assembly was written in when reading IL code.

Just curious
Mar 27 '12 #7

Post your reply

Sign in to post your reply or Sign up for a free account.