Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi,
I am having a C project which is generating an .exe as output.Since i require to create a DLL file of the existing project so can any one plz help me.Thanks in advance. sorry fr inappropriate English.
Posted
Comments
BrainlessLabs.com 25-Jan-12 5:48am    
Which IDE are you using?

Actually if we use __declspec(dllexport) alone, then compiler will do name mangling, so we have to use extern "C" also to create a perfect C-DLL

An alternative to export functions from DLL is to write a DEF file.
Say you are having Fun_1(), Fun_2(), then you can create a DEF file in V.Studio by

Add "New Item --> code --> Module-definition dile (.def)"

Inside the def file:

C++
LIBRARY   CDLL
EXPORT

Fun_1
Fun_2


This will export Fun_1 & Fun_2 without name mangling.
 
Share this answer
 
Comments
[no name] 25-Jan-12 9:22am    
Very true, I forgot to write extern "C" 5!
subrata kumar Nayak 30-Jan-12 6:59am    
thanks for the reply..
But when i am creating the dll i am geting the error C2059:syntax error:'string'
So plz help for this.
if i will remove__declspec(dllexport)then the dll is getting created But i am unable to use that.
Assuming you are using Visual Studio, First of all make functions you want to export as '__declspec(dllexport)', e.g,

__declspec(dllexport) void __cdecl Fun1();


Now, go to Project menu, select Project properties.

In Configuration Properties --> General --> Configuration Type as Dynamic Library (.dll)

Compile your code, you will find .dll and .lib file created in your output directory.

Regards
 
Share this answer
 
Comments
subrata kumar Nayak 25-Jan-12 7:34am    
Thanks for the reply,But i m having around 200functionswhich are present inside around 50 .c files,putting the prefix in all the functions is getting difficult and confused.Is there any other way to do this? If there please reply...... Thanks Again
[no name] 25-Jan-12 9:24am    
If all functions you need to expose.. then you need to do what is suggested.. Some of the functions are just helper functions. I don't think you want to explore them.
subrata kumar Nayak 31-Jan-12 0:34am    
thanks for the reply.. But when i am creating the dll i am geting the error C2375: 'WinMain' : redefinition; different linkage So plz help for this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900