On 2012-04-06 14:49:05 +0200, Mattias Gaertner wrote: > On Fri, 6 Apr 2012 09:45:38 -0300 > Leonardo M. Ramé <[email protected]> wrote: > > > On 2012-04-06 14:39:10 +0200, [email protected] wrote: > > > > > > > > > On Fri, 6 Apr 2012, Leonardo M. Ramé wrote: > > > > > > >I have a similar problem to this: > > > > > > > >http://www.lazarus.freepascal.org/index.php?topic=10571.0 > > > > > > > >My main program launches a thread, that loads a shared library, then > > > >execute a function who receives as a parameter a pointer to a callback > > > >function and an instance of the caller, as this: > > > > > > > >procedure TMythread.execute; > > > >begin > > > > ... > > > > // external function > > > > runcode(@MyCallBack, @Self); > > > > ... > > > >end; > > > > > > > >procedure MyCallback(const Result: PAnsiChar; const ACaller: pointer); > > > >cdecl; > > > >var > > > > lCaller: TMythread; > > > >begin > > > > // the parameter ACaller is used because callbacks can't be of type > > > > // procedure of object. > > > > lCaller := TMyThread(ACaller); > > > > lCaller.TestVar := Result; // <--- Ok. > > > > lCaller.ListOfThings.Add; // <--- SIGSEGV > > > > > > IMHO the problem is not in threads. > > > > > > You cannot pass objects to libraries or vice versa. > > > The VMTs will differ. > > > > > > Michael. > > > > But, I'm passing the object as a pointer that is received as (void *) and > > returned back to the callback as a parameter, the library doesn't touch > > it. Even in this case I can't pass an object?. > > Have you checked the calling convention. E.g. 'cdecl;'? > > Mattias >
Yes, I'm using cdecl. The library is a C++ library running on Linux, defined as this: typedef void (* CFindCallBack)(const char *, const void *); So, correct me if I'm wrong, the calling convention should be cdecl. -- Leonardo M. Ramé http://leonardorame.blogspot.com -- _______________________________________________ Lazarus mailing list [email protected] http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
