Page 1 of 1

Using DLLs

Posted: Sat Mar 28, 2009 1:21 am
by ac667788
Am curious about the use of DLLs

I wrote a DLL with a single function

Code: Select all

#include <stdio.h>

void hello ()
  {
    printf ("Hello World!\n");
  }
I verified the DLL was written correctly and could actually see the "hello" function name using LibrayFunctionName() but when I run the following code, "Hello World" fails to show up in the console.

Code: Select all

If OpenLibrary(0, "mydll.dll") 
  OpenConsole()
    CallFunction(0,"hello")
    Delay(2000)
    CloseConsole()  
EndIf
CloseLibrary(0)
I rewrote the hello function as an addition returning an integer and that seems to work but why doesn't printf?

Posted: Sat Mar 28, 2009 10:44 am
by cxAlex
You must use CallCFunction() for C DLLs.

Posted: Sat Mar 28, 2009 11:19 am
by DarkDragon
Have you compiled with Console-mode?

Anyway, in PureBasic on Windows... I don't think there's standard-output pipelining.
cxAlex wrote:You must use CallCFunction() for C DLLs.
No, definately not just for C DLLs. You can specify cdecl or stdcall in C and for cdecl you need CallC and for stdcall you need Call.