www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - win32 api & lib issue

reply Peter Hu <peterhu.peterhu outlook.com> writes:
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.
Nov 02 2023
next sibling parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
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); } } ```
Nov 02 2023
parent Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Thursday, 2 November 2023 at 09:01:06 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 08:31:41 UTC, Peter Hu wrote:
 [...]
Works for me.
This is all you need ```d import core.sys.windows.commdlg; import core.sys.windows.winuser; void main() { wchar[256] fileName; 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); } } ```
Nov 02 2023
prev sibling parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
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 :

 [...]
If it still doesn't work try adding this: ```d pragma(lib, "user32"); pragma(lib, "comdlg32"); ```
Nov 02 2023
parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Thursday, 2 November 2023 at 09:08:02 UTC, Imperatorn wrote:
 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 :

 [...]
If it still doesn't work try adding this: ```d pragma(lib, "user32"); pragma(lib, "comdlg32"); ```
Another alternative if you're using dub is to add this in your dub.json instead: ```json "libs": ["user32", "comdlg32"] ``` This seems be something related to DMD vs LDC. Because if I change the compiler to DMD I also get unresolved external symbols, but not with LDC. It seems the forwarding of directives from submodules are different.
Nov 02 2023
parent reply Peter Hu <peterhu.peterhu outlook.com> writes:
On Thursday, 2 November 2023 at 09:13:11 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 09:08:02 UTC, Imperatorn wrote:
 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 :

 [...]
If it still doesn't work try adding this: ```d pragma(lib, "user32"); pragma(lib, "comdlg32"); ```
Another alternative if you're using dub is to add this in your dub.json instead: ```json "libs": ["user32", "comdlg32"] ``` This seems be something related to DMD vs LDC. Because if I change the compiler to DMD I also get unresolved external symbols, but not with LDC. It seems the forwarding of directives from submodules are different.
Thank you. Below two pragma solved the isse but am confused as they are already in the system path.This is the first time I have to include lib files here.How come other gui programs don't have to do this. pragma(lib,"user32"); pragma(lib,"comdlg32");
Nov 02 2023
parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Thursday, 2 November 2023 at 09:58:21 UTC, Peter Hu wrote:
 On Thursday, 2 November 2023 at 09:13:11 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 09:08:02 UTC, Imperatorn wrote:
 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 :

 [...]
If it still doesn't work try adding this: ```d pragma(lib, "user32"); pragma(lib, "comdlg32"); ```
Another alternative if you're using dub is to add this in your dub.json instead: ```json "libs": ["user32", "comdlg32"] ``` This seems be something related to DMD vs LDC. Because if I change the compiler to DMD I also get unresolved external symbols, but not with LDC. It seems the forwarding of directives from submodules are different.
Thank you. Below two pragma solved the isse but am confused as they are already in the system path.This is the first time I have to include lib files here.How come other gui programs don't have to do this. pragma(lib,"user32"); pragma(lib,"comdlg32");
I'm not sure why, it works for me, but I think it could be something dmd does different. The pragma lib is inserted into the generated object file, or otherwise passed to the linker, so the linker automatically links in that library. I'm guessing dmd for some reason does not see it in the submodule, but I have no proof that's the issue, I'm just guessing.
Nov 02 2023
parent reply Peter Hu <peterhu.peterhu outlook.com> writes:
On Thursday, 2 November 2023 at 10:02:29 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 09:58:21 UTC, Peter Hu wrote:
 On Thursday, 2 November 2023 at 09:13:11 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 09:08:02 UTC, Imperatorn 
 wrote:
 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 :

 [...]
If it still doesn't work try adding this: ```d pragma(lib, "user32"); pragma(lib, "comdlg32"); ```
Another alternative if you're using dub is to add this in your dub.json instead: ```json "libs": ["user32", "comdlg32"] ``` This seems be something related to DMD vs LDC. Because if I change the compiler to DMD I also get unresolved external symbols, but not with LDC. It seems the forwarding of directives from submodules are different.
Thank you. Below two pragma solved the isse but am confused as they are already in the system path.This is the first time I have to include lib files here.How come other gui programs don't have to do this. pragma(lib,"user32"); pragma(lib,"comdlg32");
I'm not sure why, it works for me, but I think it could be something dmd does different. The pragma lib is inserted into the generated object file, or otherwise passed to the linker, so the linker automatically links in that library. I'm guessing dmd for some reason does not see it in the submodule, but I have no proof that's the issue, I'm just guessing.
Really appreciated for the help.I am learning to understand. Not using these two pragma in the source,other in the commandline:dmd -m64 user32.lib comdlg32.lib test.d compiled.But--- In an IDE say PoseidonD it still failed to compile even if I provided the library path to the compiler,I just can't understand how come my other small programs ( based on gui libslike DFL2,iup4D,dwt,NAppGui4D ) works fine without having to provide pragma in the source before compiling.
Nov 02 2023
next sibling parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Thursday, 2 November 2023 at 10:17:37 UTC, Peter Hu wrote:
 On Thursday, 2 November 2023 at 10:02:29 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 09:58:21 UTC, Peter Hu wrote:
 On Thursday, 2 November 2023 at 09:13:11 UTC, Imperatorn 
 wrote:
 On Thursday, 2 November 2023 at 09:08:02 UTC, Imperatorn 
 wrote:
 [...]
Another alternative if you're using dub is to add this in your dub.json instead: ```json "libs": ["user32", "comdlg32"] ``` This seems be something related to DMD vs LDC. Because if I change the compiler to DMD I also get unresolved external symbols, but not with LDC. It seems the forwarding of directives from submodules are different.
Thank you. Below two pragma solved the isse but am confused as they are already in the system path.This is the first time I have to include lib files here.How come other gui programs don't have to do this. pragma(lib,"user32"); pragma(lib,"comdlg32");
I'm not sure why, it works for me, but I think it could be something dmd does different. The pragma lib is inserted into the generated object file, or otherwise passed to the linker, so the linker automatically links in that library. I'm guessing dmd for some reason does not see it in the submodule, but I have no proof that's the issue, I'm just guessing.
Really appreciated for the help.I am learning to understand. Not using these two pragma in the source,other in the commandline:dmd -m64 user32.lib comdlg32.lib test.d compiled.But--- In an IDE say PoseidonD it still failed to compile even if I provided the library path to the compiler,I just can't understand how come my other small programs ( based on gui libslike DFL2,iup4D,dwt,NAppGui4D ) works fine without having to provide pragma in the source before compiling.
I'm sorry, I don't know. I have just observed that when using LDC the libraries gets forwarded from submodules but not with DMD. So what I usually do is to add them in my dub.json "libs" property as shown before. Oh my, I didn't know poseidon still existed :D Is this what you're using? https://bitbucket.org/KuanHsu/poseidond I currently use vscode and Visual D, they both work good. But it's always fun to see other IDEs
Nov 02 2023
parent reply Peter Hu <peterhu.peterhu outlook.com> writes:
On Thursday, 2 November 2023 at 10:58:51 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 10:17:37 UTC, Peter Hu wrote:
 [...]
I'm sorry, I don't know. I have just observed that when using LDC the libraries gets forwarded from submodules but not with DMD. So what I usually do is to add them in my dub.json "libs" property as shown before. Oh my, I didn't know poseidon still existed :D Is this what you're using? https://bitbucket.org/KuanHsu/poseidond I currently use vscode and Visual D, they both work good. But it's always fun to see other IDEs
Yes,exactly. That was developed with D+iupD. Under windows,I use PoseidonD with Entice Designer+DFL: Entice Designer: http://www.dprogramming.com/entice.php DFL for D2 :https://github.com/Rayerd/dfl
Nov 02 2023
parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Thursday, 2 November 2023 at 12:22:29 UTC, Peter Hu wrote:
 On Thursday, 2 November 2023 at 10:58:51 UTC, Imperatorn wrote:
 [...]
Yes,exactly. That was developed with D+iupD. Under windows,I use PoseidonD with Entice Designer+DFL: Entice Designer: http://www.dprogramming.com/entice.php DFL for D2 :https://github.com/Rayerd/dfl
Wow, it's great seeing this is still being used 😎
Nov 02 2023
parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Thursday, 2 November 2023 at 12:43:01 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 12:22:29 UTC, Peter Hu wrote:
 On Thursday, 2 November 2023 at 10:58:51 UTC, Imperatorn wrote:
 [...]
Yes,exactly. That was developed with D+iupD. Under windows,I use PoseidonD with Entice Designer+DFL: Entice Designer: http://www.dprogramming.com/entice.php DFL for D2 :https://github.com/Rayerd/dfl
Wow, it's great seeing this is still being used 😎
Would be nice to continue development of Entice Designer
Nov 02 2023
parent reply Peter Hu <peterhu.peterhu outlook.com> writes:
On Thursday, 2 November 2023 at 12:47:11 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 12:43:01 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 12:22:29 UTC, Peter Hu wrote:
 On Thursday, 2 November 2023 at 10:58:51 UTC, Imperatorn 
 wrote:
 [...]
Yes,exactly. That was developed with D+iupD. Under windows,I use PoseidonD with Entice Designer+DFL: Entice Designer: http://www.dprogramming.com/entice.php DFL for D2 :https://github.com/Rayerd/dfl
Wow, it's great seeing this is still being used 😎
Would be nice to continue development of Entice Designer
are more features than it looks in the Form Property Window.It is a pity the source editor does not support Chinese characters input(but can paste in) . Since the DFL library gets maintained,hope Entice designer gets maintained as well.Source is available in the website( http://www.dprogramming.com/entice.php).
Nov 02 2023
parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Thursday, 2 November 2023 at 13:40:14 UTC, Peter Hu wrote:
 On Thursday, 2 November 2023 at 12:47:11 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 12:43:01 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 12:22:29 UTC, Peter Hu wrote:
 On Thursday, 2 November 2023 at 10:58:51 UTC, Imperatorn 
 wrote:
 [...]
Yes,exactly. That was developed with D+iupD. Under windows,I use PoseidonD with Entice Designer+DFL: Entice Designer: http://www.dprogramming.com/entice.php DFL for D2 :https://github.com/Rayerd/dfl
Wow, it's great seeing this is still being used 😎
Would be nice to continue development of Entice Designer
setting.There are more features than it looks in the Form Property Window.It is a pity the source editor does not support Chinese characters input(but can paste in) . Since the DFL library gets maintained,hope Entice designer gets maintained as well.Source is available in the website( http://www.dprogramming.com/entice.php).
I put it on dub now so you can just do "dub add dfl". In Entice designer you can then change your compile command to cd.. && dub (if you're in the source folder, otherwise just dub). I might add the ability to create event handlers by clicking on objects. We'll see.
Nov 02 2023
parent reply Peter Hu <peterhu.peterhu outlook.com> writes:
On Thursday, 2 November 2023 at 17:38:33 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 13:40:14 UTC, Peter Hu wrote:
 [...]
I put it on dub now so you can just do "dub add dfl". In Entice designer you can then change your compile command to cd.. && dub (if you're in the source folder, otherwise just dub). I might add the ability to create event handlers by clicking on objects. We'll see.
That would be great.
Nov 02 2023
next sibling parent Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Friday, 3 November 2023 at 00:57:30 UTC, Peter Hu wrote:
 On Thursday, 2 November 2023 at 17:38:33 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 13:40:14 UTC, Peter Hu wrote:
 [...]
I put it on dub now so you can just do "dub add dfl". In Entice designer you can then change your compile command to cd.. && dub (if you're in the source folder, otherwise just dub). I might add the ability to create event handlers by clicking on objects. We'll see.
That would be great.
It's so ancient that it's a bit challenging to build it, but if I manage to I will add it on dub.
Nov 03 2023
prev sibling parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Friday, 3 November 2023 at 00:57:30 UTC, Peter Hu wrote:
 On Thursday, 2 November 2023 at 17:38:33 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 13:40:14 UTC, Peter Hu wrote:
 [...]
I put it on dub now so you can just do "dub add dfl". In Entice designer you can then change your compile command to cd.. && dub (if you're in the source folder, otherwise just dub). I might add the ability to create event handlers by clicking on objects. We'll see.
That would be great.
I have decided to use DlangUI instead: https://github.com/buggins/dlangui
Nov 04 2023
parent Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Saturday, 4 November 2023 at 18:30:41 UTC, Imperatorn wrote:
 On Friday, 3 November 2023 at 00:57:30 UTC, Peter Hu wrote:
 On Thursday, 2 November 2023 at 17:38:33 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 13:40:14 UTC, Peter Hu wrote:
 [...]
I put it on dub now so you can just do "dub add dfl". In Entice designer you can then change your compile command to cd.. && dub (if you're in the source folder, otherwise just dub). I might add the ability to create event handlers by clicking on objects. We'll see.
That would be great.
I have decided to use DlangUI instead: https://github.com/buggins/dlangui
We're adding search functionality in the editor and making the preview window more usable. You can see the work in progress here: ![DlangUI](https://i.imgur.com/KzZWo9F.gif)
Nov 04 2023
prev sibling parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
On Thursday, 2 November 2023 at 10:17:37 UTC, Peter Hu wrote:
 On Thursday, 2 November 2023 at 10:02:29 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 09:58:21 UTC, Peter Hu wrote:
 On Thursday, 2 November 2023 at 09:13:11 UTC, Imperatorn 
 wrote:
 On Thursday, 2 November 2023 at 09:08:02 UTC, Imperatorn 
 wrote:
 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 :

 [...]
If it still doesn't work try adding this: ```d pragma(lib, "user32"); pragma(lib, "comdlg32"); ```
Another alternative if you're using dub is to add this in your dub.json instead: ```json "libs": ["user32", "comdlg32"] ``` This seems be something related to DMD vs LDC. Because if I change the compiler to DMD I also get unresolved external symbols, but not with LDC. It seems the forwarding of directives from submodules are different.
Thank you. Below two pragma solved the isse but am confused as they are already in the system path.This is the first time I have to include lib files here.How come other gui programs don't have to do this. pragma(lib,"user32"); pragma(lib,"comdlg32");
I'm not sure why, it works for me, but I think it could be something dmd does different. The pragma lib is inserted into the generated object file, or otherwise passed to the linker, so the linker automatically links in that library. I'm guessing dmd for some reason does not see it in the submodule, but I have no proof that's the issue, I'm just guessing.
Really appreciated for the help.I am learning to understand. Not using these two pragma in the source,other in the commandline:dmd -m64 user32.lib comdlg32.lib test.d compiled.But--- In an IDE say PoseidonD it still failed to compile even if I provided the library path to the compiler,I just can't understand how come my other small programs ( based on gui libslike DFL2,iup4D,dwt,NAppGui4D ) works fine without having to provide pragma in the source before compiling.
It's probably because these libraries already have the symbols
Nov 02 2023
parent Peter Hu <peterhu.peterhu outlook.com> writes:
On Thursday, 2 November 2023 at 12:01:18 UTC, ryuukk_ wrote:
 On Thursday, 2 November 2023 at 10:17:37 UTC, Peter Hu wrote:
 On Thursday, 2 November 2023 at 10:02:29 UTC, Imperatorn wrote:
 On Thursday, 2 November 2023 at 09:58:21 UTC, Peter Hu wrote:
 [...]
I'm not sure why, it works for me, but I think it could be something dmd does different. The pragma lib is inserted into the generated object file, or otherwise passed to the linker, so the linker automatically links in that library. I'm guessing dmd for some reason does not see it in the submodule, but I have no proof that's the issue, I'm just guessing.
Really appreciated for the help.I am learning to understand. Not using these two pragma in the source,other in the commandline:dmd -m64 user32.lib comdlg32.lib test.d compiled.But--- In an IDE say PoseidonD it still failed to compile even if I provided the library path to the compiler,I just can't understand how come my other small programs ( based on gui libslike DFL2,iup4D,dwt,NAppGui4D ) works fine without having to provide pragma in the source before compiling.
It's probably because these libraries already have the symbols
Just tried to compile winsamp.d (dmd package folder--dmd/samples/d),exactly the same issue.Many many years ago I once played with this winsamp.d for testing win32 api (configuration ok or not) and it get passed without those two pragma.I am thinking whether it is related to MS VC lib path or MS VS path.
Nov 02 2023