- Код: Выделить всё
//libMy.so
#include <stdlib.h>
#define EXPORT extern "C"
EXPORT int myalloc(int **dest, int n)
{
**dest = n;
return 1;
}
- Код: Выделить всё
type
pInt = ^Integer;
tfunc = function (var dest: pInt; n: Integer): Integer; stdcall;
procedure TForm1.Button1Click(Sender: TObject);
type pbyte = ^byte;
var
b: byte;
ptr: pointer;
h: pointer;
func: tfunc;
begin
h := dlopen(pchar('libMy.so'), RTLD_LAZY);
func := tfunc(dlsym(h, pchar('myalloc')));
getmem(ptr,4);
pInt(ptr)^ := #0;
func(ptr, 2);
ShowMessage(inttostr(pInt(ptr)^)); // например вызовем это
pInt(ptr)^ := 34;
move(ptr^,pchar(@b)^,1); // или вот это
caption := inttostr(b);
freemem(ptr);
dlclose(h);
end; // тогда после end ошибка
Если не выполнять чтение памяти (убрать строчки ShowMessage и move) то все в порядке!
Кто мне может обьяснить в чем чудеса??