getting Win32 Messagebox to work
rikki cattermole
rikki at cattermole.co.nz
Fri Oct 26 12:39:13 UTC 2018
On 27/10/2018 1:36 AM, Mark Moorhen wrote:
> Hi,
>
> I've recently started looking into D, and I'm afraid i'm gonna need some
> support to get me going.
>
> I work mostly on Windows, so i've downloaded the examples from
> "https://github.com/AndrejMitrovic/DWinProgramming". Only these examples
> do not work out-of-the-box on my machine (Win10, 64-bit / DMD32 D
> Compiler v2.082.0)
>
> Now I'm trying to pass the content for a Messagebox as a variable like
> this:
> <code>
> import core.runtime;
> import win32.windef;
> import win32.winuser;
>
> extern (Windows)
> void WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
> lpCmdLine, int iCmdShow)
> {
> string content = "Some random content.";
> MessageBox(NULL, content , "Window title", 0);
> }
> </code>
>
> When compiling I get the error:
>
> HelloMsg.d(9): Error: function `win32.winuser.MessageBoxA(void*,
> const(char)*, const(char)*, uint)` is not callable using argument types
> `(typeof(null), string, string, int)`
> HelloMsg.d(9): cannot pass argument `content` of type `string` to
> parameter `const(char)*`
>
> Can anyone help me out with this?
alias string = immutable(char)[];
A slice (string in this case) is a length + pointer pair. You need to
add .ptr on content with a cast to get to const(char)*.
More information about the Digitalmars-d-learn
mailing list