On Thursday, 2 November 2023 at 08:31:41 UTC, Peter Hu wrote:
Greetings!
From time to time I encountered issues on the subjected after I
upgraded my dmd package.Given below code :
import core.sys.windows.windows;
import core.sys.windows.commdlg;
import core.sys.windows.winuser;
extern(Windows) BOOL GetOpenFileNameW(LPOPENFILENAMEW);
extern(Windows) int MessageBoxW(HWND,LPCWSTR,LPCWSTR,UINT);
void main()
{
wchar[256] fileName;
fileName[0]=0;
OPENFILENAMEW ofn;
ofn.lStructSize=OPENFILENAMEW.sizeof;
ofn.lpstrFilter=
"Text Files\0*.txt\0 D files\0*.d;*.di\0\0"w.ptr;
ofn.lpstrFile=fileName.ptr;
ofn.nMaxFile=fileName.length;
if(GetOpenFileNameW(&ofn))
{
MessageBoxW(null,ofn.lpstrFile,"File Selected:"w.ptr,0);
}
}
The compiler failed to build this small program.It complains
GetOpenFileNameW & MessageBoxW are unresolved external symbol.
DMD 2.103+VS Community 2015+Win10 64bit.
estwinapi.obj : error LNK2019: 无法解析的外部符号
_GetOpenFileNameW@4,该符号在函数 __Dmain 中被引用
testwinapi.obj : error LNK2019: 无法解析的外部符号
_MessageBoxW@16,该符号在函数 __Dmain 中被引用
testwinapi.exe : fatal error LNK1120: 2 个无法解析的外部命令
Error: linker exited with status 1120
Appreciated any help on figuring me out what the issue is and
how to fix it.
Works for me.
But you don't need to declare the functions, they are already
declared in commdlg and winuser.
```d
import core.sys.windows.windows;
import core.sys.windows.commdlg;
import core.sys.windows.winuser;
void main()
{
wchar[256] fileName;
fileName[0]=0;
OPENFILENAMEW ofn;
ofn.lStructSize=OPENFILENAMEW.sizeof;
ofn.lpstrFilter=
"Text Files\0*.txt\0 D files\0*.d;*.di\0\0"w.ptr;
ofn.lpstrFile=fileName.ptr;
ofn.nMaxFile=fileName.length;
if(GetOpenFileNameW(&ofn))
{
MessageBoxW(null,ofn.lpstrFile,"File Selected:"w.ptr,0);
}
}
```