type
Tcalc_double = function ( r: real ): real;stdcall;
procedure TForm1.Button1Click(Sender: TObject);
var
hndDLLHandle: THandle;
calc_double: Tcalc_double;
begin
hndDLLHandle := loadLibrary ( 'ExDouble.dll' );
if hndDLLHandle = 0 then exit;
@calc_double := getProcAddress ( hndDLLHandle, 'calc_double' );
calc_double ( 10.5 ) ; //вызываем искомую функцию
end;
Как динамически вызвать функцию из dll написанной на С++ Builder
Код:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#include "IplConverter.h"
#include <cv.h>
#include <highgui.h>
#pragma hdrstop
extern "C" __declspec(dllexport) void FindContours(Graphics::TBitmap &bmp, Graphics::TBitmap &outputBmp, int threshould1, int threshould2);
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------
void FindContours(Graphics::TBitmap &bmp, Graphics::TBitmap &outputBmp, int threshould1, int threshould2)
{
IplImage *image = TBitmapToIplImage(&bmp);
IplImage *convertedImage = cvCreateImage( cvSize(image->width, image->height), image->depth, 1 );
cvSetImageCOI( image, 2 );
cvCopy( image, convertedImage, 0 );
cvCanny(convertedImage, convertedImage, threshould1, threshould2, 3 );
IplImageToTBitmap(convertedImage, &outputBmp);
}
#include <vcl.h>
#include <windows.h>
#include "IplConverter.h"
#include <cv.h>
#include <highgui.h>
#pragma hdrstop
extern "C" __declspec(dllexport) void FindContours(Graphics::TBitmap &bmp, Graphics::TBitmap &outputBmp, int threshould1, int threshould2);
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------
void FindContours(Graphics::TBitmap &bmp, Graphics::TBitmap &outputBmp, int threshould1, int threshould2)
{
IplImage *image = TBitmapToIplImage(&bmp);
IplImage *convertedImage = cvCreateImage( cvSize(image->width, image->height), image->depth, 1 );
cvSetImageCOI( image, 2 );
cvCopy( image, convertedImage, 0 );
cvCanny(convertedImage, convertedImage, threshould1, threshould2, 3 );
IplImageToTBitmap(convertedImage, &outputBmp);
}
пример
Код:
главное чтобы форматы вызова совпадали! не забудь его указать в тексте DLL! если в Delphi stdcall, то в BCB __stdcall