Всем привет!
Такая проблема:
Написал на С библиотеку:
файл unit1.cpp
Код:
#define BUILD_DLL
#include "File1.h"
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
int Messagess (int k)
{
return k;
}
заголовочный файл File1.h
Код:
#if defined(BUILD_DLL)
# define DLL_EXP __declspec(dllexport)
#else
# if defined(BUILD_APP)
# define DLL_EXP __declspec(dllimport)
# else
# define DLL_EXP
# endif
#endif
DLL_EXP int Messagess (int k);
нарисовал в Дельфи тестовую форму с кнопкой
Код:
type
Tcalc_double = function ( k: integer ): integer;
................
procedure TForm1.Button2Click(Sender: TObject);
var
hndDLLHandle: THandle;
calc_double: Tcalc_double;
begin
try
hndDLLHandle := loadLibrary ( 'C:\C\t3\project1.dll' );
if hndDLLHandle <> 0 then begin
@calc_double := getProcAddress ( hndDLLHandle, 'Messagess' );
if addr ( calc_double ) <> nil then begin
showMessage ( intToStr ( calc_double ( 105 ) ) );
end else
showMessage ( 'Function not exists...' );
end else
showMessage ( 'DLL not found...' );
finally
freeLibrary ( hndDLLHandle );
end;
end;
Смотрю в дебаге - библиотеку подцепил, а вот функция getProcAddress ( hndDLLHandle, 'Messagess' ) говорит, что нет такой функции в библиотеке.
Очень хочется разобраться в данном вопросе, т.к. в будущем потребуется подключать к некоторым проектам С-шные библиотеки.
Спасибо.