Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a C-console application program ,with functions and headers which record and plays sound with windows APIs using MCIs,
now i need a record and play APIs .DLL,but i dont know how can i use my console application to make this .DLL,please help me,this is urgent for me.tanx
Posted

 
Share this answer
 
Comments
Ian A Davidson 28-Apr-13 4:21am    
Helpful link.
You didn't say what platform or IDE you are using, which is important for this type of question.

The quick and easy answer is to create 2 dummy projects: an executable (console) app and a dll app of the type you want to convert to. Look at the details of the .dsp/.dsw/.sln/.vcproj/.vcxproj and source files and how you would convert from one to the other. Take the similar actions on your existing project.
 
Share this answer
 
Comments
Ian A Davidson 27-Apr-13 19:47pm    
He says it is Windows, and I don't think the IDE matters unless more detail is required on exactly how to do things.
H.Brydon 28-Apr-13 10:05am    
32 bit or 64 bit, which version of Visual Studio? The details differ between these choices. What I described in general terms works for all of the choices.
Ian A Davidson 28-Apr-13 11:28am    
Nope. It's irrelevant.
How the code is written will depend on whether you can compile it in both 32 and 64-bit, but it doesn't change how you declare the dll exports / imports. My answer below will work equally for either. Indeed, I compile all my dlls in both 32 and 64 bit.
Ian.
My experience is with C++, but I would guess this is the same for C (except that of course you won't have classes; only functions).

Create a dll project. Define a variable on the compiler line (usually using the /d switch).
E.g. for your example, you might choose something like "SOUND_EXPORTS"
You should try to make the first part unique, so that if you choose to include it later in another dll, or if someone else wants to use your dll, the name won't clash.

Then in your main header file, include a block like this:
#ifdef SOUND_EXPORTS
# define SOUND_API __declspec(dllexport)
#else
# define SOUND_API __declspec(dllimport)
#endif


The reason for the defines, is that so when you compile the dll (where you have defined your "*EXPORTS" compiler variable) your classes and functions will be exported, but when you include the header file in another project they will be marked as imports.

When you declare a function which you want to export, place it before the function declaration, e.g:
C++
SOUND_API void Play();


Then all you need to do is include the header file in your exe (or other dll) project, link to it and use the functions as you would if they were in the same project.

I hope this helps and points you in the right direction.

Regards,
Ian.
 
Share this answer
 

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