Pregunta: | 55218 - COMO AGREGAR UNA .DLL AL .EXE EN BCBUILDER C++ 4 |
Autor: | Sergio Orozco |
Hola: quisiera agregar una librería .DLL al proyecto e incluirla en el .exe que se genera para no tener que transportarla aparte. Gracias |
Respuesta: | Yosef Moreno |
Una Pregunta, ¿Que deseas hacer?
1)-¿Cargar la Libreria en tu Codigo C++? 2)-¿Compilar tu código dentro de tu programa C++? Si es la Uno tienes dos formas, una con el LoadLibrary ó con el Archivo.h de la DLL que quieres cargar, aqui te dejo un archivo header que puedes utilizar para hacerlo mas facil. /** * This is a header for simple multiplatform * Dynamic library loads. * * @copyright 2008 Kirill Gavrilov */ #ifndef __loadLibrary_h_ #define __loadLibrary_h_ #if (defined(_WIN32) || defined(__WIN32__)) #include <windows.h> #else // Linux #include <dlfcn.h> #define HMODULE void* #endif /** * Just simple struct. */ struct StringLIST { const int size; const char* data[256]; }; /** * Function call system function to return library handle. * Returns NULL if not found. * @param destination (const char* ) - library destination; * @return HMODULE (means void* ) - handle of library. */ HMODULE DLibLoad(const char* destination) { #if (defined(_WIN32) || defined(__WIN32__)) return LoadLibrary(destination); #else return dlopen(destination, RTLD_NOW); #endif } /** * Function call system function to return function address in library. * Returns NULL if not found. * @param libHandle (HMODULE = void* ) - library handle; * @param fname (const char* ) - function name; * @return void* - pointer to function in library. */ void* DLibGetfunction(HMODULE libHandle, const char* fname) { #if (defined(_WIN32) || defined(__WIN32__)) return (HMODULE )GetProcAddress(libHandle, fname); #else return dlsym(libHandle, fname); #endif } /** * Function call system function to release library. * (free memory). * @param libHandle (HMODULE = void* ) - library handle; */ void DLibFree(HMODULE libHandle) { #if (defined(_WIN32) || defined(__WIN32__)) FreeLibrary(libHandle); #else dlclose(libHandle); #endif } #endif //__loadLibrary_h_ Si es la numero 2 definitivamente necesitaras el el archivo .H de la dll que estas utilizando. |