0 votes
by Jason Chandler (120 points)

Hi there, I’m calling a function InitWindow from the raylib library using library: and extern:. I can get the function to run just fine on my M1 Mac, but on Windows it crashes. 

I think the exception code there is for a type mismatch from what I could find, but this didn’t make much sense to me since it works on the M1. 

I tried compiling the library with MSVC and mingw64 just in case, but no luck. I’ve also tried switching between pascal and “c”, but I’m out of ideas.

Anyway if anyone’s got any suggestions I’d love to hear them. 

1 Answer

0 votes
by Stephen Pelc (3.3k points)
Where is  the file raylib.dll? It must be in the Windows search path.

Before execution, run .LIBS and .BADEXTERNS. If raylib.dll gives 0, it has not been found. If InitWindow gives 0, it has not been found.

Please give me the results.

I note that you are testing using a cross compiler. Try downloading VFX64 and testing on that, as that is what we will do.

If there really is a type mismatch do three things:
1) send me raylib.dll (64 bit version)
2) decompile InitWindow (dis initWindow) and send me the result.
3) check this against the Win64 calling convention.

Help me to help you. I do not need another C compiler installation on my Windows box. What I need is a 64 bit binary for the DLL.
by Stephen Pelc (3.3k points)
As far as I can tell, Raylib does not support dynamic (DLL) linking directly, but only static linking.

If you want dynamic linking create your own DLL using the cheatsheet as a starting point.
by Jason Chandler (120 points)
Yes, the library does not make it easy to create a dll since it supplies raygui separately and it is a pretty important component. I will follow the DLL cheatsheet once I get some time.
Thanks also for the heads up on the cross compiler, I hadn't realized I'd made that mistake.

Nothing jumps out at me from the output for the correct compiler, but it does still crash.
library: raylib.dll  ok
extern: void InitWindow( int a, int b, const char * c );  ok
dis InitWindow
INITWINDOW
( 005948D0    FF152F10E9FF )          CALL    FFE9102F [RIP]    @00425905
( 005948D6    4883ED10 )              SUB     RBP, # 10
( 005948DA    48896500 )              MOV     [RBP], RSP
( 005948DE    48895D08 )              MOV     [RBP+08], RBX
( 005948E2    4883EC20 )              SUB     RSP, # 20
( 005948E6    4883E4F0 )              AND     RSP, # -10
( 005948EA    4C8B4508 )              MOV     R8, [RBP+08]
( 005948EE    48635510 )              MOVSXD  RDX, DWord [RBP+10]
( 005948F2    48634D18 )              MOVSXD  RCX, DWord [RBP+18]
( 005948F6    FC )                    CLD
( 005948F7    FF1573FFFFFF )          CALL    FFFFFF73 [RIP]    @00594870
( 005948FD    FC )                    CLD
( 005948FE    488B6500 )              MOV     RSP, [RBP]
( 00594902    488B5D20 )              MOV     RBX, [RBP+20]
( 00594906    488D6D28 )              LEA     RBP, [RBP+28]
( 0059490A    FF153D10E9FF )          CALL    FFE9103D [RIP]    @0042594D
( 00594910    C3 )                    RET/NEXT
( 65 bytes, 17 instructions )
 ok
.LIBS
raylib.dll                      0000:7FFB:264E:0000
mpeparser64.dll                 0000:0000:6A94:0000
Ole32.dll                       0000:7FFB:E059:0000
riched32.dll                    0000:7FFB:CFFC:0000
avifil32.dll                    0000:7FFB:C296:0000
ws2_32.dll                      0000:7FFB:DFB1:0000
ComDlg32.dll                    0000:7FFB:DFF9:0000
ComCtl32.dll                    0000:7FFB:C4E6:0000
shell32.dll                     0000:7FFB:DEB1:0000
gdi32.dll                       0000:7FFB:E051:0000
User32.dll                      0000:7FFB:E02D:0000
kernel32.dll                    0000:7FFB:DFC2:0000 ok
.BADEXTERNS
0 Unresolved Externs ok


I've uploaded the dll for convenience here in the meantime:
https://www.mediafire.com/file/fctcxcwgtr8whgh/raylib.dll/file
by Stephen Pelc (3.3k points)
How have you tested the DLL? Where is the C source for the program that runs the initWindows() function in the DLL?

InitWindows() takes two ints and a address. If this part of the VFX64 EXTERN: mechanism was broken, VFX64 just would not run under Windows.

Why not ask the raylib support people how to build a DLL?
by Jason Chandler (120 points)
I have indeed tested this dll. It functions as expected when I call InitWindow from it using Common Lisp's cffi (SBCL specifically), but I won't pretend to know what sort of type conversion that does.

I did find that as of version 5.0 that they have started distributing dll releases though. It is on the release page of their Github. I have the same issue with these versions unfortunately. https://github.com/raysan5/raylib/releases/tag/5.0

Anyway, I get the impression that since other functions on the DLL appear to work, that it may be something to do with the GL context that raylib opens for this function in particular.

I appreciate all of the help. I will continue experimenting with it. I might be able to work around whatever the issue is by creating the window/context myself and seeing if raylib can operate on it.

Oh sorry, I forgot to post that the source for InitWindow is here:
https://github.com/raysan5/raylib/blob/dc7f81a7b0cbc666812c870841313e0c15a87a0c/src/rcore.c#L556
...