hola
bueno mira este es un ejemplo muy sencillo de como crear y despues usar una dll en c
codigo de la dll
[code=c]
//---------------------------------------------------------------------------
#include <windows.h>
extern "C" __declspec(dllexport) double mayorValor(double, double);
double mayorValor(double a, double b)
{
return ((a>b)? a:b);
}
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------
[/code]
code de al app
[code=cpp]
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
typedef double(*funcion)(double,double);
funcion mayor;
HINSTANCE dll=LoadLibrary("midll.dll");
if(dll)
{
mayor=(funcion)GetProcAddress(dll, "_mayorValor");
if(mayor!=NULL)
ShowMessage(mayor(StrToFloat(Edit1->Text),StrToFloat(Edit2->Text)));
else
ShowMessage("Error en funcion");
}
else
ShowMessage("Error al cargar la dll");
FreeLibrary("midll.dll");
/*
OTRA VIA:
ES CASI LO MISMO,SI SE DAN CUENTA SOLO SE DIFERENCIAN EN QUE LA 1ra CREA UN ALIAS A LA FUNCION QUE CONTENDRA
LA DIRECCION DE LA FUNCION DENTRO DE LA DLL.
cualquier duda escribirme a yovanis.vega@inf.fie.uo.edu.cu.
ESPERO SIRVA DE ALGO.
// NOTA: En el código fuente de la dll la funcion se llama mayorValor
//pero en la dll como tal la funcion sufrira pasará a llamarse _mayorValor,eso es debido al compilador,
//el mismo antepone un _ a todas las funciones que tengamos.
double (*f)(double, double);
//carga de la dll dinamicamente,tambien se puede hacer con GetModuleHandle
HINSTANCE dllinstance=LoadLibrary("midll.dll");
if(dllinstance==NULL) ShowMessage("Error al cargar la dll");
// Para buscar la direccion de la funcion deseada. En este caso _mayorValor
f =(double (*) (double, double))GetProcAddress(dllinstance, "_mayorValor");
if(f==NULL)
ShowMessage("Error en la funcion");
else
ShowMessage(f(50.6,6.6));
FreeLibrary("midll.dll");
*/
}
[/code]
espero que te sirva de algo...
saludos