Home Declare delphi structure with ctypes
Reply: 1

Declare delphi structure with ctypes

beardrinker
1#
beardrinker Published in 2018-01-11 10:12:00Z

I have delphi dll named lib.so It have structure:

TRec1 = packed record
    Version:UInt32
end;
Prec=^TRec1

function get_version(ARec: PRec): integer;
begin
  Result := 1;
  FillChar(ARec, SizeOf(TRec1), 0);
  ARec^.Version := 2;
  Result := 0;
end;

Dll have function get_version, that take pointer on this structure and return change structure.

Python code:

from ctypes import *
class TRec1(Structure):

_pack_ = 1
_fields_=[
('Version',c_uint32) 
]

PRec1=TRec1()
a=cdll.LoadLibrary('/home/Test_In_memmory_perfomance/lib.so')
print a.get_version(PRec1)

Function return Exception,that structure dont declare. When I try call get_version('string') it return OK, but i dont have callback.

Is my structure declare correctly?

beardrinker
2#
beardrinker Reply to 2018-01-11 12:43:38Z

In my situation this code resolve problem:

print a.get_version(byref(PRec1))

Can anyone tell me why it work?)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.871766 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO