How do I create a dll file, and how can I read from it?
Thank you.
How do I create a dll file, and how can I read from it?
Thank you.
"I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe
http://www.Bloodware.net - Developing free software for the community.
Creating a DLL file is different depending which compiler you are using. Usually it is just an option that gets passed to the linker that tells it to create a library file instead of an executable.
You dont read from DLL files, you use them. This is usually done with a call to LoadLibrary() to load the DLL into memory, and then GetProcAddress() to get the address of a function in the library.
what do you mean by "function address"?
don't i use the functions from the dll like any other function?
"I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe
http://www.Bloodware.net - Developing free software for the community.
No, you dont. A DLL is a library of functions, but in order to call one of these functions - your program needs to know where the function is located in the DLL. That is where the GetProcAddress() comes in.
Now you can use a .lib file to make things a little easier for you. A .lib file is created from a dll file, and it allows you to call dll functions normally without using GetProcAddress(). The way you create or link to .lib files differs from compiler to compiler, but since it appears you are using Borland...
You create a .lib file with Borland's implib tool.
implib mydll.lib mydll.dll
To tell the compiler to link to this file, choose Project -> Add To Project from the menu. Now in the New Unit tab, choose Browse. In the dialog box, change Files of type to 'Library file (*.lib)', find the lib file and click OK
yeah i thought about using libs, and i do know how to create one, with borland
but correct me if i'm wrong, the main difference between lib and dll is the fact that i don't link the dll to the exe, unlike with lib, so i always have the exe and dll files. so using a dll file makes it easier for me to up-date my software, i can simply patch the dll file instead the entire exe.
"I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe
http://www.Bloodware.net - Developing free software for the community.
No, even if you use a .lib file, the DLL file is still required. Let's say your dll file has a function that looks like:
Without a lib file, you would have to do:Code:int dllfn(char *cArray);
If you link to the .lib file, then all you would have to do is:Code:typedef int (*DLLFN)(char*); DLLFN dllfn; char someArray[10]; HMODULE hMod = LoadLibrary("mydll.dll"); dllfn = (DLLFN)GetProcAddress(hMod,"dllfn"); dllfn(someArray);
In both cases, the dll file is needed and must be included with the .exe file. If you use the .lib file to link, you do not need to include it with the .exe file when you distribute it. The .lib file is only used in the linking process to tell the linker where the dll function are located.Code:#include "mydll.h" ... int i = dllfn(someArray);
Last edited by bithub; 11-14-2004 at 02:37 PM.
i'm sorry but i don't understand the connection of lib here...
if i could simply put the next code in a function, why would i need to create a lib and link it...
Code:typedef int (*DLLFN)(char*); DLLFN dllfn; char someArray[10]; HMODULE hMod = LoadLibrary("mydll.dll"); dllfn = (DLLFN)GetProcAddress(hMod,"dllfn");
"I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe
http://www.Bloodware.net - Developing free software for the community.
You dont need a .lib file. They are just used to make life a little easier for the programmer. Imagine if you are calling 100 different functions from a DLL file. Do you really want to go through the process of declaring a function pointer and calling GetProcAddress() for each one?if i could simply put the next code in a function, why would i need to create a lib and link it
>>i'm sorry but i don't understand the connection of lib here...
The .lib is created automatically when you make the dll. It contains the functions address (location) in the dll (same as GetProcAddress() does). It must be built into the exe (with the header).
Look at 'implicit' (static) v 'explicit' (dynamic) linking.
Sometimes you only need a function occasionally so you link to the dll while the app is running, use the function, free the dll (FreeLibrary() ). As per the code snippet.
Why?
The dll is someone elses work / not included in all versions of the app.
You may not know the name of the dll you want until run time, ie OS or hardware specific.
No changes to the header or .lib are needed if you explicitly link.
Some performance and error issues.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill