www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Does the WInMain function is mandatory ?

reply Vinod K Chandran <kcvinu82 gmail.com> writes:
Hi,
I would like to do some win api coding in D. I just taste the 
syntactic sugar but cant do anything more. I have few questions.
1. Does WinMain is needed for a D program in order to use win api 
?
2. Can we use D strings in win api functions ?, If not, please 
show me how to convert strings
Sep 29 2018
parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 30/09/2018 7:24 PM, Vinod K Chandran wrote:
 Hi,
 I would like to do some win api coding in D. I just taste the syntactic 
 sugar but cant do anything more. I have few questions.
 1. Does WinMain is needed for a D program in order to use win api ?
No.
 2. Can we use D strings in win api functions ?, If not, please show me 
 how to convert strings
null terminated, nothing really special.
Sep 29 2018
next sibling parent reply bauss <jj_1337 live.dk> writes:
On Sunday, 30 September 2018 at 06:33:47 UTC, rikki cattermole 
wrote:
 null terminated, nothing really special.
To elaborate on this. There is function that does it for you called toStringz() https://dlang.org/library/std/string/to_stringz.html
Sep 29 2018
next sibling parent Vinod K Chandran <kcvinu82 gmail.com> writes:
On Sunday, 30 September 2018 at 06:56:41 UTC, bauss wrote:
 On Sunday, 30 September 2018 at 06:33:47 UTC, rikki cattermole 
 wrote:
 null terminated, nothing really special.
To elaborate on this. There is function that does it for you called toStringz() https://dlang.org/library/std/string/to_stringz.html
Thanks for the reply. Let me check it.
Sep 30 2018
prev sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 30 September 2018 at 06:56:41 UTC, bauss wrote:
 There is function that does it for you called toStringz()

 https://dlang.org/library/std/string/to_stringz.html
Not really best for Windows. That's for calling C functions with char*, for Windows, you should be working with wchar* instead. http://dpldocs.info/experimental-docs/std.utf.toUTFz.html so usage is: toUTFz!(wchar*)(your_string_here); If passing string literals to Windows, you can put a w at the end, like: MessageBoxW(null, "Hello"w, "World"w, 0); // note the ""w
Sep 30 2018
parent reply Vinod K Chandran <kcvinu82 gmail.com> writes:
On Sunday, 30 September 2018 at 12:48:17 UTC, Adam D. Ruppe wrote:

 so usage is:

 toUTFz!(wchar*)(your_string_here);


 If passing string literals to Windows, you can put a w at the 
 end, like:

 MessageBoxW(null, "Hello"w, "World"w, 0); // note the ""w
Thanks for the reply. But it says "toUTFz" is not defined. do i missing any import statement ?
Sep 30 2018
next sibling parent Vinod K Chandran <kcvinu82 gmail.com> writes:
On Sunday, 30 September 2018 at 13:17:33 UTC, Vinod K Chandran 
wrote:
 On Sunday, 30 September 2018 at 12:48:17 UTC, Adam D. Ruppe 
 wrote:

 so usage is:

 toUTFz!(wchar*)(your_string_here);


 If passing string literals to Windows, you can put a w at the 
 end, like:

 MessageBoxW(null, "Hello"w, "World"w, 0); // note the ""w
Thanks for the reply. But it says "toUTFz" is not defined. do i missing any import statement ?
I am trying to make this function, but compiler is rejecting all my attempts. ```D int MsgBox(string MsgTxt, string titleTxt = "MessageBox") { const wchar* Mesg = toUTFz! (wchar*)(MsgTxt) ; const wchar* Tit = toUTFz! (wchar*)(itleTxt) ; MessageBoxW(null, Mesg, Tit, 0) ; return 0 ; } ```
Sep 30 2018
prev sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 30 September 2018 at 13:17:33 UTC, Vinod K Chandran 
wrote:
 Thanks for the reply. But it says "toUTFz" is not defined. do i 
 missing any import statement ?
import std.utf;
Sep 30 2018
parent reply Vinod K Chandran <kcvinu82 gmail.com> writes:
On Sunday, 30 September 2018 at 13:21:59 UTC, Adam D. Ruppe wrote:
 On Sunday, 30 September 2018 at 13:17:33 UTC, Vinod K Chandran 
 wrote:
 Thanks for the reply. But it says "toUTFz" is not defined. do 
 i missing any import statement ?
import std.utf;
Thanks. It worked. I would like to compile this as a gui. Now it starts with the cmd. Google search didn't gave me the link i want. Any help ?
Sep 30 2018
parent reply Mike Parker <aldacron gmail.com> writes:
On Sunday, 30 September 2018 at 14:06:20 UTC, Vinod K Chandran 
wrote:

 Thanks. It worked.
 I  would like to compile this as a gui. Now it starts with the 
 cmd. Google search didn't gave me the link i want. Any help ?
With the default OPTLINK linker: dmd -L/SUBSYSTEM:windows app.d In this case, user32.lib where MessageBoxW and MessageBoxA reside is automatically linked. When using the MS linker: dmd -m64 -L/SUBSYSTEM:windows -L/ENTRY:mainCRTStartup app.d user32.lib In this case, user32.lib is not automatically linked. Replace -m64 with -m32mscoff for 32-bit output with the MS linker. -L passes command line options to the current linker.
Sep 30 2018
parent Vinod K Chandran <kcvinu82 gmail.com> writes:
On Sunday, 30 September 2018 at 15:06:31 UTC, Mike Parker wrote:
 On Sunday, 30 September 2018 at 14:06:20 UTC, Vinod K Chandran 
 wrote:

 Thanks. It worked.
 I  would like to compile this as a gui. Now it starts with the 
 cmd. Google search didn't gave me the link i want. Any help ?
With the default OPTLINK linker: dmd -L/SUBSYSTEM:windows app.d In this case, user32.lib where MessageBoxW and MessageBoxA reside is automatically linked. When using the MS linker: dmd -m64 -L/SUBSYSTEM:windows -L/ENTRY:mainCRTStartup app.d user32.lib In this case, user32.lib is not automatically linked. Replace -m64 with -m32mscoff for 32-bit output with the MS linker. -L passes command line options to the current linker.
Thanks for the reply. I think its better to write a program in which we can choose this codes from a combobox and click a button to start compiling.
Oct 02 2018
prev sibling parent Vinod K Chandran <kcvinu82 gmail.com> writes:
On Sunday, 30 September 2018 at 06:33:47 UTC, rikki cattermole 
wrote:

 No.

 2. Can we use D strings in win api functions ?, If not, please 
 show me how to convert strings
null terminated, nothing really special.
Hi, Thanks for the reply. I somehow managed to display a messagebox with "const(wchar)*"
Sep 30 2018