A writefln issue or a Thread issue?

Sam Hu samhudotsamhu at gmail.com
Sat Sep 5 03:31:13 PDT 2009


Given below code:

module testWin32Process;

import win32.windows;//get from:http://www.dsource.org/projects/bindings/wiki/WindowsApi


import std.string;
import std.conv;
import std.stdio;
import core.stdc.stdlib;


string startupProcess()
{
	STARTUPINFO si;
	si.cb=si.sizeof;
	
	PROCESS_INFORMATION pi;
	char* szCommandLine=cast(char*)toStringz("cmd"/*"notepad testWin32Process.d"*/);
	si.dwFlags=STARTF_USESHOWWINDOW;
	si.wShowWindow=true;

	
	int bRet=CreateProcess(
		null,
		szCommandLine,
		null,
		null,
		false,
		CREATE_NEW_CONSOLE,
		null,
		null,
		&si,
		&pi);
	if(bRet)
	{
		CloseHandle(pi.hThread);
		
		return std.string.format("New process ID:%d\n"
			"Host process ID:%d\n",
			pi.dwProcessId,
			pi.dwThreadId);
		
	}
	else
	{
		
		return "Do not know what happend.";//just want to check
	}
	
}
int main(string[] args)
{
	writefln("%s\n",toStringz(startupProcess)); // prints blank!!!
	
	MessageBox(null,toStringz(startupProcess),toStringz("result?"),0);//prints contents as expected!!
	
	system("pause");
	return 0;
}

As commented,were I use writefln(...),it prints blank;were I use MessageBox,it prints well as expected:

New Process ID:2216
Host Process ID:2456

Could anybody here figure me out what the problem is?Thanks in advance.

Regards,
Sam


More information about the Digitalmars-d-learn mailing list