Using dylibsymbol instead of import libraries (.dll.a)

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
jcfuller
Posts: 324
Joined: Sep 03, 2007 18:40

Postby jcfuller » Sep 02, 2009 18:21

voodooattack wrote:
jcfuller wrote:Is it possible to do this with dll functions that take optional parameters like the printf function from crt?

James


Yes, those are still functions as far as the compiler is concerned, vararg functions use the cdecl convention.

It's all about how the compiler sees it, when you give it a function prototype pointer then call it, it emits the correct assembly instructions for calling that function prototype, now no matter what address you assign your variable to, it still gets called the same.


This works because I am only using four parameters for this particular app. but there might be times when I want more.

Code: Select all

Dim Shared g_object_get As Sub cdecl(p1 As long,p2 As zstring ptr, p3 As Any Ptr,p4 As Any Ptr)

This fails.

Code: Select all

Dim Shared g_object_get As Sub cdecl(p1 As long,p2 As zstring ptr[, ...])


James
voodooattack
Posts: 605
Joined: Feb 18, 2006 13:30
Location: Alexandria / Egypt
Contact:

Postby voodooattack » Sep 02, 2009 19:17

This works:

Code: Select all

sub object_get cdecl(p1 as long,p2 as zstring ptr, ...)
    if p1 = 0 or p2 = 0 then return

    print p1, *p2
   
    dim as any ptr arg = va_first()
   
    for i as integer = 1 to p1
        print va_arg(arg, integer)
        arg = va_next(arg, integer)
    next
end sub

dim shared g_object_get as sub cdecl(p1 as long,p2 as zstring ptr, ...)

g_object_get = @object_get

g_object_get(2, "testing", 10, 30)

sleep


I'm guessing that the cause was the square brackets around the ellipsis.
jcfuller
Posts: 324
Joined: Sep 03, 2007 18:40

Postby jcfuller » Sep 02, 2009 20:29

Works fine now thank you.
I was going by the help file and it shows a bracket.

James
counting_pine
Site Admin
Posts: 6169
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Postby counting_pine » Sep 02, 2009 20:41

Which page in the help file? Bear in mind also that the square brackets are used to indicate that parts of the syntax are optional.

The wiki page www.freebasic.net/wiki/KeyPgDots shows how it should be used. (No square brackets here, because the ellipses can't be omitted in an example that's explicitly showing how to use them!)

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 3 guests