connect dll with Cuda to another program(Delphi)

Hello, world!

I have a program written in Delphi. It does some calc. with matrix.
I want to make it faster, so ive written a library in CUDA which does some actions with data from Delphi program. But ive got a problem: something happens with the pointer of the data.

I`ve made library code simple, but the problem remains.
Library code:
extern “C” __declspec(dllexport) host void test(double* A_I,double* B_I,int width,int height){
FILE* file = fopen(“C:/dbg/result1.txt”, “wt”);

	  for(int i=0;i<width*height;i++){
		  if (i%width!=0) {fprintf(file, "%f\t", A_I[i]);}
		  else{fprintf(file, "%f\n", A_I[i]);}
	  fprintf(file, "%f\n", ' ');

	  for(int i=0;i<width*height;i++){
		  if (i%width!=0) {fprintf(file, "%f\t", B_I[i]);}
		  else{fprintf(file, "%f\n", B_I[i]);}
	  fprintf(file, "%x\t", A_I);
	   fprintf(file, "%x\t", B_I);


In Delphi:
procedure test( A, B: Pointer; W, H: Integer);stdcall; external ‘cumatrix.dll’ name ‘test’;

function test(A: TMatrix; AName: ShortString): TMatrix;
var P,p1,p2: Pointer;w,h:integer; b,c:Pointer;
qw,qw1,qw2: TMatrix;
qw:=TMatrix.Create(A.Rows,A.Cols,AName); p:=qw.Pdata; p2:=qw.Pdata;
qw1:=TMatrix.Create(8,8,‘11’); p1:=qw1.Pdata;

if (extCudaStatus) then begin


Without test(p,p1,width,height); it works correctly.
But with it, it goes wrong(something happens with A).

Similar library, written in pure C, did it OK.
If i use some data directly, without pointers it all Works OK.

There`s a problem with pointers.

Could you help me with this?