[fpc-pascal] Can I store an object reference in C as void pointer?
Guillermo Martínez Jiménez
gmjimen at burdjia.com
Tue May 20 16:56:40 CEST 2008
Hello.
I'll create a library in Object Pascal. I'll compile it in a
DLL/so/dynlib and want to define a public interface to be used in any
language so I decided to define it as "C public functions".
I'll use objects so some functions of the library should return or
receive object references but I'm not sure which C data type should I
use.
As example, in pseudo Object Pascal:
_______________________________________
LIBRARY theLib;
USES
unitObject;
EXPORT FUNCTION CreateObject: TTheObjectClass; CDECL;
EXPORT PROCEDURE UseObject (Obj: TTheObjectClass; Param: INTEGER); CDECL;
EXPORT PROCEDURE DestroyObject (Obj: TTheObjectClass); CDECL;
END.
________________________________________
And the pseudo C header:
________________________________________
/* theLib.h */
typedef TTheObjectReference void*;
extern TTheObjectReference CreateObject (void); pragma __DLL__ ("theLib");
extern void UseObject (TTheObjectReference Obj, long int Param);
pragma __DLL__ ("theLib");
extern void DestroyObject (TTheObjectReference Obj); pragma __DLL__ ("theLib");
________________________________________
Then, in a pseudo C program:
________________________________________
#include "theLib.h"
void main (void)
{
TTheObjectReference Object;
Object = CreateObject ();
UseObject (Object, 1);
DestroyObject (Object);
}
_________________________________________
Is this correct or should I use a different approach?
Thanks.
More information about the fpc-pascal
mailing list