This is some sort of heisenbug. It is reproducible on Windows, with dmd version 1.102.2, and with ldc version 1.32.0
The project should be constructed as follows:
1. Create an empty dub project.
2. Set a dependency for bindbc-sdl with exact version 1.2.4
3. Edit the code to contain this:
```d
import std.stdio;
import bindbc.sdl;
import std.file;
void main()
{
}
```
Building with dub by default, you will get the error:
```
C:\pathtodmd\..\import\std\internal\windows\advapi32.d(36,9): Error: undefined identifier `HMODULE`, did you mean alias `HMODULE`?
```
The odd things about this error:
1. Removing *any* of the imports removes the error
2. Reordering the imports removes the error
3. Changing to a newer version of bindbc-sdl removes the error
I do not know the cause of this, or how to narrow it down further. I will note that the `HMODULE` alias is defined using a mixin template (one of very many).
It appears like whoever created this file went a bit crazy on template usage. The code is:
```d
package template DECLARE_HANDLE(string name, base = HANDLE) {
mixin ("alias " ~ base.stringof ~ " " ~ name ~ ";");
}
```
Located here: https://github.com/dlang/dmd/blob/4430ae1fdf80c8232cfdf7ee0f82d7eeb5be81af/druntime/src/core/sys/windows/basetsd.d#L47
And the declaration looks like:
```d
mixin DECLARE_HANDLE!("HMODULE");
```
Located here:
https://github.com/dlang/dmd/blob/4430ae1fdf80c8232cfdf7ee0f82d7eeb5be81af/druntime/src/core/sys/windows/windef.d#L97
I honestly can't see why we are doing this instead of:
```d
alias HMODULE = HANDLE;
```
But something regarding how this is done is messing up the compiler. So even if this is improved, the bug that causes this error should be investigated and fixed. I'm keeping all the versions in here so it can be reproduced and examined, even if we fix that problem.
Comment #1 by razvan.nitu1305 — 2023-04-20T09:09:48Z
Comment #2 by razvan.nitu1305 — 2023-04-28T11:49:05Z
*** Issue 19816 has been marked as a duplicate of this issue. ***
Comment #3 by vital.fadeev — 2023-08-29T06:41:01Z
Created attachment 1887
advapi32 HMODULE patch
.\import\std\internal\windows\advapi32.d(36,9): Error: undefined identifier HMODULE, did you mean alias HMODULE?
See patch in attached file.
Comment #4 by vabenil — 2024-01-08T01:47:49Z
I have this exact same issue compiling to windows. Though for me changing the import order doesn't seem to fix anything. My project uses `bindbc.opengl` instead of `bindbc.sdl`, asides from that it doesn't use anything windows specific.
Reproducible on this tag https://github.com/vabenil/vadgl/releases/tag/v0.2.0 in my repo.
Comment #5 by vabenil — 2024-01-08T18:15:13Z
For further clarification I replicated the same issue on dmd v2.106.1 and dmd 2.107.0-beta.1. I can also replicate it on ldc2 v1.34.0, v1.35.0 and 1.36.0
Comment #6 by dlang-bot — 2024-01-08T19:12:38Z
@vabenil created dlang/dmd pull request #16007 "Fix issue 23818 - Error HMODULE not defined, please use HMODULE" fixing this issue:
- Fix issue 23818 - Error HMODULE not defined, please use HMODULE
Use alias instead of DECLARE_HANDLE.
https://github.com/dlang/dmd/pull/16007
Comment #7 by dlang-bot — 2024-01-09T04:00:40Z
dlang/dmd pull request #16007 "Fix issue 23818 - Error HMODULE not defined, please use HMODULE" was merged into master:
- 0f975986e0299dca0e2880fc944d0427e35ec7a5 by vabenil:
Fix issue 23818 - Error HMODULE not defined, please use HMODULE
Use alias instead of DECLARE_HANDLE.
https://github.com/dlang/dmd/pull/16007