¿Cómo generar un archivo .dll a partir de un programa escrito en lenguaje C?
Pasos de producción de DLL:
1. Escriba la función dll para implementar el código fuente hello.c
#include
int say_hello (char* nombre)
{
printf( "hola %s\n ", nombre);
devuelve 1;
} p>
2. Escriba el archivo de definición de salida de la función dll hello.def.
BIBLIOTECA hola
EXPORTACIONES
say_hello @1 p>
3. Compile el código fuente dll y genere archivos dll y lib.
3.1 Cree una nueva ventana de línea de comando
3.2 ¿Establezca PATH ?
SET PATH=K:\vcnet\vc7\bin;%PATH%
SET INCLUDE=K:\vcnet\vc7\include;%INCLUDE%
SET LIB=K: \vsnet\Vc7\lib;%LIB%
3.3 Compilar hello.c
cd K:\Source\dllsample (el directorio donde hello.c y hello.def)
cl /c hello.c
3.4 Vincula hello.obj y genera dos archivos hello.dll y hello.lib.
link /def:hello.def / dll hello.obj
4. Función de prueba dll.
4.1 Escribir código de prueba test.c
extern int say_hello( char* nombre);
int main(int argc,char** argv)
{
say_hello( "robbie ");
return 0;
}
4.2 Compile el código de prueba test.c
cl /c test.c
4.3 Enlace test.obj y hello.lib para generar el archivo ejecutable test.exe
enlace test.obj hello.lib
4.4 Ejecute test.exe, salida de pantalla:
hola robbie
En este punto, se construye una dll.