I think you could not declare the second parameter of GetData as var parameter. Because it is then treated as address.
I am not sure what corresponds to C++ unsigned long, perhaps LongWord?
So try to change the second parameter so that it is not a var parameter.
Dňa 19. 4. 2013 19:18 Leonardo M. Ramé wrote / napísal(a):
I'm using a C++ library with a function that receives a parameter this
way:

int getData(void * &buffer, unsigned long &bufSize){
   bufSize = 10;
   return 1;
}

The Pascal definition I'm using is this:

function (var buffer: pointer; var bufsize: longword): Integer; cdecl;

I'm using this library without any issue in a couple of programs, but in
this new program, after the "bufSize" variable is assigned (inside the
library) an object of my Lazarus program is trashed. Weird.

The instance of my object (an very simple TCustomControl descendant) is
declared in a TForm class, as FMyControl: TMyControl, then created an
instance in TForm's constructor. In another method of TForm, I call the
library's function then I try to use a method of FMyControl, but it
gives a SigSegv.

Example:

procedure TForm1.doSomething;
var
   lBuffer: PWord;
   lBufSize: longword;
begin
   lBuffer := nil;
   lBufSize := 0;
   FMyControl.call_some_method; // FMyControl has debugging info.
   getData(lBuffer, lBufSize);
   FMyControl.call_some_method; // FMyControl "cannot access memory 
address...SIGSEGV"
end;

I can modify the C++ function if needed. Am I incorrectly declaring the
function params?. Why is FMyControl's memory position trashed?.

Regards,


--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to