- 1
Open VC++. Select "File," then "New." The "New" dialog box will open; select the "Project" tab. Select "Win32 Dynamic-Link Library," and then name your project, such as "FirstDLL." Press "OK."
- 2
Select the type of project. Click "A Simple DLL Project" and click "Finish."
- 3
Create Exports.def. This is a file that lists the functions of the DLL. It is like a menu that will allow external functions to use the DLL; without an exports file, the DLL would be considered an internal function. To create the file, click "Project," "Add to Project," then "New." In the dialog that appears, select a "text file" as the kind of file you want to add and name it "exports.def." Click "OK." Back in the main editing window, type "EXPORTS" and click "Save."
- 4
Write your code. On the left bottom tab, select "FileView." Expand "Source Files" tree to see a file named "FirstDLL.cpp." Double-click this file.
Enter:
// Return the sum of two numbers
int _stdcall Sum(int inA, int inB) {
return (inA + inB);
}
- 5
Add your function to the exports.def file. Open your exports file from the Source Files Tree and add "Sum" on the second line.
- 6
Build your DLL. Select "Build" in the menu and select "Build FirstDLL.dll F7." Open an explorer window and find your project's directory, then open "Debug." Here you will find the DLL you built.
5/5/11
How to Create a Windows Dynamic Link Library
A Windows dynamic link library is helpful if you utilize many programs that use common functions. DLLs allow programmers to write functions in any programming language that will go along with an executable file. If you're confused about how DLLs work, think of them like books and loose papers, where the DLL is the book, and the papers are the applications that reference the book, computer science expert Dean Pearce says.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment