D2 string conversion

Sam Hu samhudotsamhu at gmail.com
Sat May 9 09:02:00 PDT 2009


Sorry.

//Source:
module d2001;

import std.stdio;
import std.c.stdlib;
import std.c.windows.windows;
import std.string;
import std.conv;


void pause()
{
	writefln("Press any key to continue...");
	getchar;
}


extern(Windows) int MessageBoxW(HWND,LPCSTR,LPCSTR,UINT);
int showMessage(wchar[] msg,wchar[] caption=cast(wchar[])"Application",
	int style=MB_OK|MB_ICONINFORMATION)
{
	return MessageBoxW(null,to!(const(char)[])(msg),to!(const(char)[])(caption),style);//try one
	//try two:
	//return MessageBoxW(null,toStringz(to!(const(char[])(msg)),toStringz(to!(const(char)[])(caption)),style);

}


int main(string[] args)
{

	writefln("Hello d2...");
	showMessage("ÄãºÃ£¡");

	pause;

	return 0;
	
}

For *try one* the error message is as below:
G:\DLang\DEx\D2Ex>dmd d2001.d
d2001.d(21): Error: function d2001.MessageBoxW (HANDLE, const(char)*, const(char
)*, uint) does not match parameter types (void*,const(char)[],const(char)[],int)

d2001.d(21): Error: cannot implicitly convert expression (to(msg)) of type const
(char)[] to const(char)*
d2001.d(21): Error: cannot implicitly convert expression (to(caption)) of type c
onst(char)[] to const(char)*
G:\DLang\DEx\D2Ex>

For *try two* the erro message is as below:
G:\DLang\DEx\D2Ex>dmd d2001.d
d2001.d(23): expression expected, not 'const'
d2001.d(23): found '[' when expecting '.' following 'char'
d2001.d(23): found ']' when expecting identifier following 'char.'
d2001.d(23): found ';' when expecting ','
d2001.d(25): expression expected, not '}'
d2001.d(28): found 'int' when expecting ','
d2001.d(28): found 'args' when expecting ','
d2001.d(28): expression expected, not ')'
d2001.d(29): found '{' when expecting ','
d2001.d(31): found ';' when expecting ','
d2001.d(32): found ';' when expecting ','
d2001.d(34): found ';' when expecting ','
d2001.d(36): expression expected, not 'return'
d2001.d(36): found '0' when expecting ','
d2001.d(36): expression expected, not ';'
d2001.d(38): found '}' when expecting ','
d2001.d(38): expression expected, not 'EOF'
d2001.d(38): found 'EOF' when expecting ','
d2001.d(38): expression expected, not 'EOF'
d2001.d(38): found 'EOF' when expecting ','
d2001.d(38): expression expected, not 'EOF'

G:\DLang\DEx\D2Ex>
DMD202+Phobos under xp sp3.

Thanks for helping.
Sam


More information about the Digitalmars-d-learn mailing list