Please you answer for C, i don't use VB. A lot of examples "create in C, use in VB". I want simple source code plz. Thank you..
How to create and use .dll in C ?
Started by Kuto, Jun 03 2009 10:12 AM
2 replies to this topic
#1
Posted 03 June 2009 - 10:12 AM
|
|
|
#2
Posted 03 June 2009 - 10:18 AM
Creating and using a .dll in C depends a little on your compiler. The basic idea is this:
When you compile your supporting files, you have the option to link the object files into a .dll instead of linking them into a .exe. Then when you compile the program that uses the supporting files, the linker can be told to dynamically link instead of statically link to the files. As long as the .dll with the dynamic links is in the same folder as the .exe or is in a folder in the path, you're in good shape.
Note: on *nix systems, it's a .so file.
When you compile your supporting files, you have the option to link the object files into a .dll instead of linking them into a .exe. Then when you compile the program that uses the supporting files, the linker can be told to dynamically link instead of statically link to the files. As long as the .dll with the dynamic links is in the same folder as the .exe or is in a folder in the path, you're in good shape.
Note: on *nix systems, it's a .so file.
#3
Posted 06 June 2009 - 12:35 PM
Creating a DLL in C is easy, you only need to specify the entry point, wich will be the first function, and then just write your functions and compile the source to a dll.
Example (The source file):
And the header file for include in any program:
Example (The source file):
/* This is dll.c */
#include <windows.h>
/* DLL Entry Point */
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
/* Returns TRUE on success, FALSE on failure */
return TRUE;
}
/* Example function */
__declspec(dllexport) int sum(const int a, const int b){
return a + b;
}
And the header file for include in any program:
/* dll.h */ __declspec(dllimport) int sum(const int a, const int b);


Sign In
Create Account


Back to top









