?
Solved

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

Posted on 2013-06-17
5
Medium Priority
?
1,224 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 800 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 1200 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

765 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