#Loading extension functions of WinSock2

1 messages · Page 1 of 1 (latest)

analog hull
#

Hi, I'm trying to load ConnectEx function of WinSock2. The following code is taken from TigerBeetle's source. It compiles on version 0.9.0 but it doesn't on HEAD. What can I do as a workaround?

const LPFN_CONNECTEX = fn (
    Socket: os.windows.ws2_32.SOCKET,
    SockAddr: *const os.windows.ws2_32.sockaddr,
    SockLen: os.socklen_t,
    SendBuf: ?*const anyopaque,
    SendBufLen: os.windows.DWORD,
    BytesSent: *os.windows.DWORD,
    Overlapped: *os.windows.OVERLAPPED,
) callconv(os.windows.WINAPI) os.windows.BOOL;

const ConnectEx = try os.windows.loadWinsockExtensionFunction(
    LPFN_CONNECTEX,
    socket,
    windows.ws2_32.WSAID_CONNECTEX,
);
twilit dawn
#

what's the error?

analog hull
# twilit dawn what's the error?

it's unable to resolve comptime value since socket argument given in loadWinsockExtensionFunction can't be known at compile time. also the return type of the mentioned function is also comptime known so it's executed in comptime.

src\main.zig:62:9: error: unable to resolve comptime value
        socket,
        ^~~~~~

note: expression is evaluated at comptime because the generic function was instantiated
with a comptime-only return type
pub fn loadWinsockExtensionFunction(comptime T: type, sock: ws2_32.SOCKET, guid: GUID) !T {
twilit dawn
#

ah, use *const LPFN_CONNECTEX

analog hull
#

it worked, thanks! how is it different than &LPFN_CONNECTEX?

#

oh actually it's for the function right? I believe this is the same

const LPFN_CONNECTEX = *const fn (
    Socket: os.windows.ws2_32.SOCKET,
    SockAddr: *const os.windows.ws2_32.sockaddr,
    SockLen: os.socklen_t,
    SendBuf: ?*const anyopaque,
    SendBufLen: os.windows.DWORD,
    BytesSent: *os.windows.DWORD,
    Overlapped: *os.windows.OVERLAPPED,
) callconv(os.windows.WINAPI) os.windows.BOOL;