Hi guys,
Have a look at following code
const std = @import("std");
// zig build-lib -dynamic lib.zig
fn DllMain(_: usize, _: u32, _: usize) callconv(.c) bool {
std.debug.print("hello\n", .{});
return true;
}
it seems that the DllMain is not called. Any suggestion?
it needs to be pub, also it does not need to be .c callconv
and the parameters are std.os.windows... types
1 Like
The correct signature is:
pub fn DllMain(
hinstDLL: std.os.windows.HINSTANCE,
fdwReason: std.os.windows.DWORD,
lpReserved: std.os.windows.LPVOID,
) std.os.windows.BOOL {
}
2 Likes
The call convention is unnecessary since it is called from within zig by an exported function in std.start
This is not always true, some times it is exported as is, but only if the .winapi is used as a calling convention.
Sorry, you are right. The calling convention is irrelevant.
The function in question (in root) is not exported, the one in std.start is, which has the .winapi calling convention. The function in root does not need a specific calling convention.
If they wanted to export the function themselves then yes they would need the .winapi calling convention, and also they’d need to use the correct symbol name (_DllMainCRTStartup).
1 Like
It is the same regardless of if you link libc, and I was not suggesting that they deal with the exporting themselves.