# Cannot build a dll

**URL:** <https://ziggit.dev/t/cannot-build-a-dll/15815>\
**Category:** Explain\
**Created:** [May 31, 2026, 5:22am UTC](https://ziggit.dev/t/cannot-build-a-dll/15815 "2026-05-31T05:22:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lolothedragon](https://ziggit.dev/user_avatar/ziggit.dev/lolothedragon/32/8206_2.png) [@lolothedragon](https://ziggit.dev/u/lolothedragon)\
**Post date:** [May 31, 2026, 5:22am UTC](https://ziggit.dev/t/cannot-build-a-dll/15815/1 "2026-05-31T05:22:07Z")

</div>

Hi guys,  
Have a look at following code

```zig
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?

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [May 31, 2026, 5:25am UTC](https://ziggit.dev/t/cannot-build-a-dll/15815/2 "2026-05-31T05:25:08Z")

</div>

it needs to be `pub`, also it does not need to be `.c` callconv

and the parameters are `std.os.windows...` types

---

<div class="post-metadata">

**Author:** ![lolothedragon](https://ziggit.dev/user_avatar/ziggit.dev/lolothedragon/32/8206_2.png) [@lolothedragon](https://ziggit.dev/u/lolothedragon)\
**Post date:** [May 31, 2026, 5:26am UTC](https://ziggit.dev/t/cannot-build-a-dll/15815/3 "2026-05-31T05:26:40Z")

</div>

thank you. got it.

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [May 31, 2026, 5:30am UTC](https://ziggit.dev/t/cannot-build-a-dll/15815/4 "2026-05-31T05:30:16Z")

</div>

The correct signature is:

```zig
pub fn DllMain(
    hinstDLL: std.os.windows.HINSTANCE,
    fdwReason: std.os.windows.DWORD,
    lpReserved: std.os.windows.LPVOID,
) std.os.windows.BOOL {
}

```

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [May 31, 2026, 5:35am UTC](https://ziggit.dev/t/cannot-build-a-dll/15815/5 "2026-05-31T05:35:49Z")

</div>

The call convention is unnecessary since it is called from within zig by an exported function in `std.start`

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [May 31, 2026, 5:38am UTC](https://ziggit.dev/t/cannot-build-a-dll/15815/6 "2026-05-31T05:38:33Z")

</div>

~~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.

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [May 31, 2026, 5:43am UTC](https://ziggit.dev/t/cannot-build-a-dll/15815/7 "2026-05-31T05:43:59Z")

</div>

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`).

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [May 31, 2026, 6:26am UTC](https://ziggit.dev/t/cannot-build-a-dll/15815/9 "2026-05-31T06:26:52Z")

</div>

It is the same regardless of if you link libc, and I was not suggesting that they deal with the exporting themselves.
