[Gambas-devel] EXTERN Calls

Scott, Vince Vince.Scott at ...440...
Mon Mar 20 21:21:48 CET 2006


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 = 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 = Alloc(sTest, 5)

  ret = GetName(ptr)

  Message("String= " & 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 = GetAName()

  sTest = StrPtr(ptr)

  Message("String= " & 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.




More information about the Devel mailing list