Solved

C# - How to add unmanaged dll to a c# project

Posted on 2013-06-17
5
1,141 Views
Last Modified: 2013-06-17
I have a unmanaged 'C' dll  I need to used in a C# project.  I have created dllimport for my 'C' functions.  I was unable to add reference.  How do I do?  When I right click  on the project and select add reference.  I got an error whether I choose extension of assemblies or COM. See attached screen shots.  I am currently using Visual Studio 2010.
Capture1.JPG
Capture2.JPG
0
Comment
Question by:tommym121
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39253122
Is the DLL a COM DLL? If not, then you will need to import the functions by name using the DLLImport attribute. Otherwise, if the DLL is a COM DLL, then you may need to register the DLL on your system using regsvr32.exe.
0
 

Author Comment

by:tommym121
ID: 39253144
It is not a COM dll.  So I don't need use to Add reference. Am I right?
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 200 total points
ID: 39253159
You cannot use "Add Reference," no. As long as you know the names of the functions you are trying to call, you should be able to explicitly import those functions via a DllImport attribute. Make sure you know the calling mechanism used by the DLL as well as the types on the parameters as you may need to perform some marshalling in order to pass and receive data correctly.
0
 
LVL 15

Accepted Solution

by:
Minh Võ Công earned 300 total points
ID: 39253195
You don't want add reference c++ dll into C# project.
You copy c++ dll to bin folder of project and you DLLImport
cpp project
int __declspec(dllexport) a(int b)
{
      return b;
}
c# project
class Program
{
   [DllImport(@"c:\a.dll")]
   private static extern int a(int b);
   static void Main(string[] args)
   {
       Console.WriteLine(a(3));
   }
}
http://www.codeproject.com/Articles/27298/Dynamic-Invoke-C-DLL-function-in-C
http://www.codeproject.com/Articles/1285/Calling-API-functions-using-C
0
 

Author Closing Comment

by:tommym121
ID: 39253228
Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question