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.
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.
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!)