[Gambas-devel] EXTERN Calls
Brought to you by:
gambas
From: Scott, V. <Vin...@pi...> - 2006-03-20 20:21:05
|
Hello, I have successfully been able to make a small C library with a couple of functions and call them from Gambas. One does nothing more than pass back a number when I call it. int Test() { return 5; } ...pretty simple. The second two functions I want to pass a pointer and get back data but cannot get them to work. I don't understand how to set them up to call them from Gambas. Here are my simple 'C' functions... 1.) Sample 1 int GetName(char* pName) { sprintf(pName, "%s", "TEST"); return 0; } AND 2.) Sample 2 char* GetAName() { Char* buf =3D malloc(5); sprintf(buf, "%s", "TEST"); return buf; } How do I set these up to make calls in Gambas? Here is what I did: 1.) Sample 1 Extern GetName(ptr AS Pointer) AS Integer IN "libtest" Public Sub Test1() Dim ret AS Ingteger Dim ptr AS Pointer Dim sTest AS String ptr =3D Alloc(sTest, 5) ret =3D GetName(ptr) Message("String=3D " & sTest) Free(ptr) End 2.) Sample 2 Extern GetAName() AS Pointer IN "libtest" Public Sub Test2() Dim ret AS Ingteger Dim ptr AS Pointer Dim sTest AS String ptr =3D GetAName() sTest =3D StrPtr(ptr) Message("String=3D " & sTest) End Both of these calls I get nothing back...or I don't know how to access it. Thanks, Vince This communication is confidential and may be legally privileged. If = you are not the intended recipient, (i) please do not read or disclose = to others, (ii) please notify the sender by reply mail, and (iii) please = delete this communication from your system. Failure to follow this = process may be unlawful. Thank you for your cooperation. |