473,387 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to use .dll created with C++ in C#?

Hi,

I have a dll created earlier by VC++ which export a class. And now i want to
use this class in C# code, how can i do it?

And what if it is a static library(.lib)?

Thanks in advance

Joe Cai
Nov 28 '06 #1
3 1245
CAIBird <CA*****@discussions.microsoft.comwrote:
>I have a dll created earlier by VC++ which export a class. And now i want to
use this class in C# code, how can i do it?
And what if it is a static library(.lib)?
By far the easiest is to open up your DLL project again, turn on "CLI"
in Projects>Settings>General, and turn your class into a "ref class"
rather than just a "class", and rebuild. This way it will produce a
normal .net assembly with classes that can be used by any other .net
language.

--
Lucian
Nov 28 '06 #2
THX.
But I have no source code :)

"Lucian Wischik" wrote:
CAIBird <CA*****@discussions.microsoft.comwrote:
I have a dll created earlier by VC++ which export a class. And now i want to
use this class in C# code, how can i do it?
And what if it is a static library(.lib)?

By far the easiest is to open up your DLL project again, turn on "CLI"
in Projects>Settings>General, and turn your class into a "ref class"
rather than just a "class", and rebuild. This way it will produce a
normal .net assembly with classes that can be used by any other .net
language.

--
Lucian
Nov 28 '06 #3
"CAIBird" <CA*****@discussions.microsoft.comwrote in message
news:AC**********************************@microsof t.com...
Hi,

I have a dll created earlier by VC++ which export a class. And now i want to
use this class in C# code, how can i do it?
You can't, you can only call exported functions with "C" linkage. What you can do is write a
managed wrapper class using C++/CLI (VS2005). Search MSDN for "C++ Interop" for details.
And what if it is a static library(.lib)?
You can't use a .lib from C#.
Thanks in advance

Joe Cai

Nov 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: André | last post by:
Short version of what I am looking for: Given a class "public_class" which is instantiated a few times e.g. a = public_class() b = public_class() c = public_class() I would like to find...
2
by: R Duke | last post by:
I have tried everything I can think of to change the visible property of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have...
1
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created...
1
by: Lalit | last post by:
Hi, My application has two methods which creates buttons at runtime. In one method I am able to handle the events of the buttons created at run time, but in other I am not. The code structure...
7
by: MariusI | last post by:
Are objects implicitly stored in the TLS of the currently running thread? When creating multithreaded applications i get errors when accessing data from a different thread than the thread used to...
9
by: Tushar | last post by:
Followup-To: microsoft.public.dotnet.general Does anyone know when is this event raised, is it: 1) When the file is created but may not have been closed 2) When the file is created AND it has...
3
by: Happy Man | last post by:
Why we created All praise is due to Allah and may His peace and blessings be upon his last messenger (saaw) and on all those who follow the path of righteousness until the last day. We have...
10
by: Jess | last post by:
Hello, If I create a temporary object using a dynamically created object's pointer, then when the temporary object is destroyed, will the dynamically created object be destroyed too? My guess...
0
by: dhvenkat | last post by:
Hi all, Im facing issues in generating the second mail-merge document when the first document created is still open. Its a web based application, and we submit the details for mail-merge after...
16
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.