SendMessageTimeoutW requires casting string to uint?

BoQsc vaidas.boqsc at gmail.com
Tue Jul 9 10:34:54 UTC 2019


I'm quite new to the programming, and I'm getting unsure how to 
make SendMessageTimeoutW to work with D lang.

Most of my attention right now resides around the Argument of the 
SendMessageTimeoutW function:
> "Environment",

It seems that SendMessageTimeoutW  accepts only uint type, and 
string can't be directly used.

I think that I have to convert string characters to "C-style 0 
terminated string".
And everything should work? But I'm unsure how to do that.


All I know that there was toString16z function from tango 
project, that made it all work.
http://www.dsource.org/projects/tango/docs/stable/tango.stdc.stringz.html#toString32z
> cast(LPARAM)(settingName.toString16z())


Here is how the method was before my modifications:
> void broadcastSettingChange (string settingName, uint timeout=1)
> {
>     auto result = SendMessageTimeoutW(
>         HWND_BROADCAST,
>         WM_SETTINGCHANGE,
>         0,
>         cast(LPARAM)(settingName.toString16z(),
>         SMTO_ABORTIFHUNG,
>         timeout,
>         null
>     );





And finally, here is myVersion.d that throws an error (that I use 
incorrect variable type for the argument)

myVersion.d
> import core.sys.windows.windows : SendMessageTimeoutW;
> import core.sys.windows.windows : GetLastError;
> import core.sys.windows.windows : ERROR_SUCCESS;
> import core.sys.windows.windows : SMTO_ABORTIFHUNG;
> import core.sys.windows.windows : LPARAM;
> import core.sys.windows.windows : HWND_BROADCAST;
> import core.sys.windows.windows : WM_SETTINGCHANGE;
>
>
> void main(){
> 	broadcastSettingChange();
> 
> }
>
> void broadcastSettingChange (uint timeout=1)
> {
>     auto result = SendMessageTimeoutW(
>         HWND_BROADCAST,
>         WM_SETTINGCHANGE,
>         0,
>         "Environment",
>         SMTO_ABORTIFHUNG,
>         timeout,
>         null
>     );
> 
>     if(result == 0)
>     {
>         auto errCode = GetLastError();
>     }
>  }




More information about the Digitalmars-d-learn mailing list