Thread overview | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 30, 2018 Does the WInMain function is mandatory ? | ||||
---|---|---|---|---|
| ||||
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 |
September 30, 2018 Re: Does the WInMain function is mandatory ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vinod K Chandran | 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. |
September 30, 2018 Re: Does the WInMain function is mandatory ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | 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 |
September 30, 2018 Re: Does the WInMain function is mandatory ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | 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)*"
|
September 30, 2018 Re: Does the WInMain function is mandatory ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bauss | 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.
|
September 30, 2018 Re: Does the WInMain function is mandatory ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bauss | 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 |
September 30, 2018 Re: Does the WInMain function is mandatory ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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 ?
|
September 30, 2018 Re: Does the WInMain function is mandatory ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vinod K Chandran | 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 ;
}
```
|
September 30, 2018 Re: Does the WInMain function is mandatory ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vinod K Chandran | 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;
|
September 30, 2018 Re: Does the WInMain function is mandatory ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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 ?
|
Copyright © 1999-2021 by the D Language Foundation