Page 1 of 1

Problems calling C dll function, timeout.

Posted: Sat May 14, 2011 2:05 pm
by Surp
Hi
i'm stuck trying to call a function in a dll.

This is the C function i' trying to call:

Code: Select all

enum
{
    sfNone       = 0,      ///< No border / title bar (this flag and all others are mutually exclusive)
    sfTitlebar   = 1 << 0, ///< Title bar + fixed border
    sfResize     = 1 << 1, ///< Titlebar + resizable border + maximize button
    sfClose      = 1 << 2, ///< Titlebar + close button
    sfFullscreen = 1 << 3  ///< Fullscreen mode (this flag and all others are mutually exclusive)
};

typedef struct
{
    unsigned int DepthBits;         ///< Bits of the depth buffer
    unsigned int StencilBits;       ///< Bits of the stencil buffer
    unsigned int AntialiasingLevel; ///< Level of antialiasing
} sfWindowSettings;

typedef struct
{
    unsigned int Width;        ///< Video mode width, in pixels
    unsigned int Height;       ///< Video mode height, in pixels
    unsigned int BitsPerPixel; ///< Video mode pixel depth, in bits per pixels
} sfVideoMode;

CSFML_API sfWindow* sfWindow_Create(sfVideoMode Mode, const char* Title, unsigned long Style, sfWindowSettings Params);
This is the PB code:

Code: Select all

Enumeration
  #sfNone = 0
  #sfTitlebar = 1 << 0
  #sfResize = 1 << 1
  #sfClose = 1 << 2
  #sfFullscreen = 1 << 3
EndEnumeration

Structure sfWindowSettings
  DepthBits.i
  StencilBits.i
  AntialiasingLevel.i
EndStructure

Structure sfVideoMode   
  Width.i
  Height.i
  BitsPerPixel.i
EndStructure

ImportC "csfml-window.lib"

  sfWindow_Create(*Mode.sfVideoMode,Title.s,Style,*Params.sfWindowSettings) 
  
EndImport

Settings.sfWindowSettings\DepthBits = 24
Settings\StencilBits = 8
Settings\AntialiasingLevel = 0
Mode.sfVideoMode\Width = 800
Mode\Height = 600
Mode\BitsPerPixel = 32

sfWindow_Create(@Mode, "SFML window", sfResize | sfClose, @Settings)
I don't really get a error just timeout:
[14:51:48] Waiting for executable to start...
[14:51:58] The debugged executable did not respond to communication for %timeout% seconds. Disconnecting.

If I comment out sfWindow_Create() it doesnt timeout, but if I put a breakpoint on that function call it doesn't even reach it.

I hope someone can help, thanks beforehand.

Re: Problems calling C dll function, timeout.

Posted: Sat May 14, 2011 3:49 pm
by KarLKoX
Hi !

Doesn't occure when turning off the debugger.
Perhaps you need to use the lib debug version of CSFML with pb debugger enabled :?:

Re: Problems calling C dll function, timeout.

Posted: Sat May 14, 2011 4:52 pm
by Surp
KarLKoX wrote:Hi !

Doesn't occure when turning off the debugger.
Perhaps you need to use the lib debug version of CSFML with pb debugger enabled :?:
The Debug version doesn't seem to change anything. :/

Re: Problems calling C dll function, timeout.

Posted: Sat May 14, 2011 4:56 pm
by idle
what if you use the flags instead of passing in 0

Code: Select all

sfWindow_Create(@Mode, "SFML window", #sfResize | #sfClose, @Settings)

Re: Problems calling C dll function, timeout.

Posted: Sat May 14, 2011 5:05 pm
by Surp
idle wrote:what if you use the flags instead of passing in 0

Code: Select all

sfWindow_Create(@Mode, "SFML window", #sfResize | #sfClose, @Settings)
Yea well it doesnt change the fact that it never executes that line =/ i have no idea whats wrong.

Re: Problems calling C dll function, timeout.

Posted: Sat May 14, 2011 6:22 pm
by idle
what version did you download?
I tried the c version of the VS 2005 build, none of the libs linked.

Re: Problems calling C dll function, timeout.

Posted: Sat May 14, 2011 6:32 pm
by Surp
SFML 1.6, VS 2008

Re: Problems calling C dll function, timeout.

Posted: Sat Jun 04, 2011 1:48 pm
by eesau
Damn, I am having this exact same problem after trying SFML. Always getting a "Invalid memory access. (read error at address 0)". Surp, did you ever find a solution for this?

Re: Problems calling C dll function, timeout.

Posted: Sat Jun 04, 2011 2:17 pm
by Trond
Maybe the wrong calling convention is used when building the library. Maybe it's using fastcall instead of cdecl.

Re: Problems calling C dll function, timeout.

Posted: Sat Jun 04, 2011 4:28 pm
by eesau
Trond wrote:Maybe the wrong calling convention is used when building the library. Maybe it's using fastcall instead of cdecl.
I doubt it but anything's possible. I'll continue trying, SFML looks like a great alternative to SDL.

Re: Problems calling C dll function, timeout.

Posted: Sat Jun 04, 2011 5:56 pm
by eesau
Nevermind, the problem was yours truly. I was using the wrong libs :oops: