www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - example of how to build juno with DMD1.016

example of how to build juno with DMD1.016

from D china:
http://bbs.yidabu.com/forum-10-1.html
http://bbs.yidabu.com/thread-619-1.html


download juno

	download juno from:
	http://www.dsource.org/projects/juno

	put to:\dmd\src\other\juno.

compile juno and find errors

	use DSSS to compile juno
	\dmd\src\other\dsss.conf:
	
		[*]
		buildflags=-g -O -debug
		[juno]
		type=library
	
	note:without -O switch, will cause Stack Overflow.

	\dmd\src\other\build.bat:
	
		dsss build juno
		pause
	


modified files

	run build.bat, will cause a lot of errors, fixed errors:

	1 com.reflect.d

	line 822,delete override.
	line 155,change ref to nref,
	in editor scite,search
	
		([^\w])ref
	
	replaced with:
	
		\1nref
	


	2 xml.core.d

	line,162, changed to:
	pcbRead = stream_.readBlock(cast(void*)buffer, cb);
	line 163, changed to:
	std.c.string.memcpy(pv, cast(void*)buffer, cb);
	line,237, changed to:
	std.c.string.memcpy(cast(void*)buffer, pv, cb);
	line 238, changed to:
	pcbWritten = stream_.writeBlock(cast(void*)buffer, cb);

	3 com.core.d

	line 1623, changed ref to nref,searh and replace in file.
	line 1604, changed to:
	*ppvObject = cast(void*)(cast(IUnknown)this);
	line 1607:
	*ppvObject =cast(void*)(cast(T[i])this);
	line 1640,1641:
	std.gc.removeRange(cast(void*)this);
	std.c.stdlib.free(cast(void*)this);
	line 554:
	v.byref = cast(void*)value,
	line 1590:
	uint r = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, null, error, 0, buffer.ptr, buffer.length + 1,
null);
	line 1592:
	return juno.base.string.toUtf8(buffer.ptr,0, r - 1);
	line,1983£º
	char[] str = juno.base.string.toUtf8(bstr[0 .. len].ptr);

	4 xml.dom.d
	juno\xml\dom.d(60):Error: cannot create instance of abstract class
XmlCDataSection
	I'm no idea of how to modify line 60,62,64,66,68,74,79,81,83,85,87,89,91.
	the simple solution is delete all "abstract",maybe some wrong here.

	5 io.core.d
	line 22 changed to£º
	return readBlock(cast(void*)buffer, buffer.length);
	line 26:
	return writeBlock(cast(void*)buffer, buffer.length);
	line 172:
	uint len = GetConsoleTitle(buffer.ptr, buffer.length);

	6 intl.core.d
	line 96 changed to:
	int cch = LCIDToLocaleName(culture, buffer.ptr, buffer.length, 0);
	line 104:
	int cch = DownlevelLCIDToLocaleName(culture, buffer.ptr, buffer.length, 0);
	line 265 changed to£º
	int cch = GetLocaleInfo(culture, field, buffer.ptr, buffer.length);
	line 279 changed to£º
	int cch = GetGeoInfo(geoId, geoType, buffer.ptr, buffer.length, 0);
	line 285 changed to£º
	int cch = GetCalendarInfo(culture, calendar, calType, buffer.ptr,
buffer.length, null);
	line 326 changed to£º
	int cch = GetLocaleInfo(culture, field, buffer.ptr, buffer.length);
	439,440 changed to£º
	translated = MultiByteToWideChar(CP_UTF8, 0, pChars, length, result.ptr, cch);
	return result.ptr;
	line 1591,1600 changed to:
	return (juno.base.string.parse!(double)(s));
	4109,4110 changed to£º
	wcscpy(tzi.StandardName.ptr, key.getStringValue("Std").toUTF16z());
	wcscpy(tzi.DaylightName.ptr, key.getStringValue("Dlt").toUTF16z());

	7 base.win32.d
	add import std.windws.charset.
	line 994 changed to£º
	T func = cast(T)GetProcAddress(moduleHandle,
std.windows.charset.toMBSz(entryPoint));
	line 1012 changed to£º
	func = cast(T)GetProcAddress(moduleHandle,
std.windows.charset.toMBSz(entryPointName));
	line 951 changed to
	uint r = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, null, error, 0, buffer.ptr, buffer.length + 1,
null);


	8 utils.registry.d
	line 81,82 changed to£º
	RegQueryValueEx(hkey_, name.toLPStr(), null, type, b.ptr, cb);
	char[] result = juno.base.string.toUtf8(b.ptr);
	96,97 changed to£º
	RegQueryValueEx(hkey_, name.toLPStr(), null, type, b.ptr, cb);
	return expandEnvironmentVariables(juno.base.string.toUtf8(b.ptr));
	line 110 changed to
	RegQueryValueEx(hkey_, name.toLPStr(), null, type, b.ptr, cb);
	line 120 changed to
	result ~= juno.base.string.toUtf8(b[index .. pos].ptr);
	line 125 changed to
	result ~= juno.base.string.toUtf8(b.ptr,index, end);
	line 141 changed to
	RegQueryValueEx(hkey_, name.toLPStr(), null, type, b.ptr, cb);
	line 189 changed to
	RegSetValueEx(hkey_, name.toLPStr(), 0, REG_DWORD, value.ptr, value.length);
	218,line 219 changed to
	RegEnumKeyEx(hkey_, i, buffer.ptr, len, null, null, null, null);
	result[i] = juno.base.string.toUtf8(buffer.ptr);
	240,line 241 changed to
	RegEnumValue(hkey_, i, buffer.ptr, len, null, null, null, null);
	result[i] = juno.base.string.toUtf8(buffer.ptr);

	9 io.path.d
	151,152 changed to£º
	GetTempPath(buffer.length, buffer.ptr);
	return getFullPath(juno.base.string.toUtf8(buffer.ptr));
	158,line 159 changed to
	GetTempFileName(path.toLPStr(), "tmp", 0, buffer.ptr);
	return juno.base.string.toUtf8(buffer.ptr);
	164,line 165 changed to
	SHGetFolderPath(Handle.init, cast(int)folder, Handle.init, 0, buffer.ptr);
	return juno.base.string.toUtf8(buffer.ptr);
	176,178,line 179 changed to
	PathCanonicalizeW(buffer.ptr, path.toLPStr());
	GetLongPathNameW(buffer.ptr, buffer.ptr, MAX_PATH);
	return juno.base.string.toUtf8(buffer.ptr);

	10 intl.format.d
	line 479 changed to£º
	char* p = cast(char*)number.digits;
	line 643 changed to
	char* p = cast(char*)digits.ptr;
	line 915 changed to
	char* p = cast(char*)digits.ptr;
	line 1035 changed to
	char* p = cast(char*)number.digits;
	line 1099 changed to
	char* p = cast(char*)number.digits;
	line 1134 changed to
	char* p = cast(char*)number.digits;

	11 base.meta.d
	line 48 changed to£º
	const char[] demangleType = newdemangleBasicType(s);
	add function(maybe some problem here):
	
		char[] newdemangleBasicType(char[] s) {
			if (s == "v") return "void";
			else	if (s == "x") return "bool";
			else	if (s == "g") return "byte";
			else	if (s == "h") return "ubyte";
			else	if (s == "s") return "short";
			else	if (s == "t") return "ushort";
			else	if (s == "i") return "int";
			else	if (s == "k") return "uint";
			else	if (s == "l") return "long";
			else	if (s == "m") return "ulong";
			else	if (s == "d") return "double";
			else	if (s == "f") return "float";
			else	if (s == "e") return "real";
			else	if (s == "o") return "ifloat";
			else	if (s == "p") return "idouble";
			else	if (s == "j") return "ireal";
			else	if (s == "a") return "char";
			else	if (s == "u") return "wchar";
			else	if (s == "w") return "dchar";
			return null;
		}
	

	12 com.client.d
	line 115 changed to£º
	dispParams.rgvarg = cast(VARIANT*)varArgs;

	13 base.environment.d
	line 14 changed to£º
	uint n = ExpandEnvironmentStrings(temp.toLPStr(), buffer.ptr, c);
	line 18 changed to:
	n = ExpandEnvironmentStrings(temp.toLPStr(), buffer.ptr, c);
	line 22 changed to
	int n = ExpandEnvironmentStrings(name.toLPStr(), buffer.ptr, c);
	line 26 changed to
	n = ExpandEnvironmentStrings(name.toLPStr(), buffer.ptr, c);
	line 28 changed to
	char[] result = juno.base.string.toUtf8(buffer.ptr);
	line 35 changed to
	int n = GetEnvironmentVariable(variable.toLPStr(), buffer.ptr, buffer.length);
	line 40 changed to
	n = GetEnvironmentVariable(variable.toLPStr(), buffer.ptr, buffer.length);
	line 42 changed to
	char[] result = juno.base.string.toUtf8(buffer.ptr);

	14 juno.base.test.d
	line 205-208 changed to£º
	info.webName = juno.base.string.toUtf8(cp.wszWebCharset.ptr);
	info.headerName = juno.base.string.toUtf8(cp.wszHeaderCharset.ptr);
	info.bodyName = juno.base.string.toUtf8(cp.wszBodyCharset.ptr);
	info.description = juno.base.string.toUtf8(cp.wszDescription.ptr);
	line 616 changed to£º
	ConvertINetString(&dwMode, CP_UTF8, codePage_, cast(ubyte*)chars.ptr,
&charsLength, bytes.ptr, &bytesLength);
	line 630 changed to£º
	ConvertINetString(&dwMode, codePage_, CP_UTF8, bytes.ptr, &bytesLength, null,
&charsLength);
	line 633 changed to
	ConvertINetString(&dwMode, codePage_, CP_UTF8, bytes.ptr, &bytesLength,
cast(ubyte*)chars.ptr, &charsLength);

	run build.bat, build juno.lib sucessed.


example of use juno

	save code below to test.d£º
	
		//from http://www.dsource.org/projects/juno/wiki/Tutorials/LateBinding
		import juno.com.core;
		import juno.com.client;
		pragma(lib,"juno.lib");

		int main() {
			try
			{
				// Create an instance of the Message object
				scope auto message = new juno.com.client.DispatchObject("CDO.Message");
				printf("auto message \n");
				// Build the mail message
				message.set("Subject", "test juno cdo.message");
				message.set("TextBody", "hello,D china http://bbs.yidabu.com");
				message.set("From", "www.yidabu.com gmail.com"); // Replace with your email
address
				message.set("To", "bbs.yidabu.com gmail.com"); // Replace with the
recipient's email address
				// Configure CDOSYS to send via a remote SMTP server

				scope auto config = new DispatchObject(message.get("Configuration"));
				// Call config's Fields property and get a reference to its Fields instance
				scope auto fields = new DispatchObject(config.get("Fields"));
				// Set the appropriate values
				scope auto sendUsing = new DispatchObject(fields.get("Item",
				 "http://schemas.microsoft.com/cdo/configuration/sendusing"));
				sendUsing.set("Value", 2); // cdoSendUsingPort = 2
				scope auto port = new DispatchObject(fields.get("Item",
				 "http://schemas.microsoft.com/cdo/configuration/smtpserverport"));
				port.set("Value", 465);
				scope auto server = new DispatchObject(fields.get("Item",
				 "http://schemas.microsoft.com/cdo/configuration/smtpserver"));
				server.set("Value", "smtp.gmail.com"); // Replace 'mail.remote.com' with
your remote server's address
				// Set the authentication type, user name and password

				scope auto authentication = new DispatchObject(fields.get("Item",
				 "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"));
				authentication.set("Value", 1); // cdoBasic = 1

				scope auto ssl = new
DispatchObject(fields.get("Item","http://schemas.microsoft.com/cdo/configuration/smtpusessl"));
				ssl.set("Value",true);

				scope auto userName = new DispatchObject(fields.get("Item",
				 "http://schemas.microsoft.com/cdo/configuration/sendusername"));
				userName.set("Value", "www.yidabu.com"); // Replace 'username' with your
account's user name
				scope auto password = new DispatchObject(fields.get("Item",
				 "http://schemas.microsoft.com/cdo/configuration/sendpassword"));
				password.set("Value", "bbs.yidabu.com"); // Replace 'password' with your
account's password
				fields.call("Update");
				message.call("Send");
				printf("send sucessed \n");
			}//try
			catch(Exception e)
			{
				printf("catch %.*s\n",e.msg);
				return 1;
			}
			return 0;
		}
	

	build test.d, cause error: not found shlwapi.lib, so:
	
		implib /s shlwapi.lib shlwapi.dll
	
	copy shlwapi.lib to \dmd\lib.

	build test.d, com.base.stirng.TypeInfo_Aa cause error: com.base.string,
commented TypeInfo_Aa, build test.d sucessed, but when run test.exe, will cause
unhandled Error: Stack Overflow,

	how to got when and where cause Stack Overflow?

	download ddbg from:
	http://ddbg.mainia.de/
	copy ddbg.exe,ddbg_debug.exe to D:\d\dmd\bin.

	commandline:ddbg test.exe

	then input:r to run test.exe,prompt:
	Unhandled Exception at juno.base.string.ArgumentList.opCall(class
TypeInfo[],void*)

	I'd no idea to fix this.
	my simple solution is cancled "import juno.base.string" in juno.com.core, copy
some function from juno.base.string to juno.com.core.

	build test.d, prompt error:Symbol Undefined _SafeArrayGetVartype 8£¬search
msdn, got£º
	
		HRESULT SafeArrayGetVartype(
			SAFEARRAY *psa,
			VARTYPE *pvt
		);
	

	change code below in juno.com.core:
	
		int SafeArrayGetVartype(SAFEARRAY* psa, out ushort pvt);
	
	to£º
	
		int SafeArrayGetVartype(SAFEARRAY* psa, out ushort* pvt);
	

	line 568 changed to£º
	
		ushort* pvt = &vt;
		SafeArrayGetVartype(value, pvt);
	

	changed:
	
		struct SAFEARRAYBOUND {
			uint cElements;
			int lLbound;
		}

		struct SAFEARRAY {
			ushort cDims;
			ushort fFeatures;
			uint cbElements;
			uint cLocks;
			void* pvData;
			SAFEARRAYBOUND[1] rgsabound;
	

	to£º
	


		//bbs.yidabu.com: below from win32.com.OAIDL
		struct myIID {	// size is 16
			align(1):
			uint Data1;
			ushort	Data2;
			ushort	Data3;
			byte	Data4[8];
		}

		struct	FLAGGED_WORD_BLOB
			{
			uint fFlags;
			uint clSize;
			ushort[1] asData;
			}
		alias FLAGGED_WORD_BLOB	*wireBSTR;
		struct SAFEARR_BSTR {
			uint Size;
			wireBSTR * aBstr;
		}

		//
		struct SAFEARR_UNKNOWN {
			uint Size;
			IUnknown * apUnknown;
		}

		//
		struct SAFEARR_DISPATCH {
			uint Size;
			IDispatch * apDispatch;
		}

		//
		struct _wireVARIANT {
		}
		struct _wireBRECORD {
		}
		// Forward references.
		alias _wireVARIANT * wireVARIANT;
		alias _wireBRECORD * wireBRECORD;
		struct SAFEARR_VARIANT {
			uint Size;
			wireVARIANT * aVariant;
		}

		//
		struct SAFEARR_BRECORD {
			uint Size;
			wireBRECORD * aRecord;
		}

		//
		struct SAFEARR_HAVEIID {
			uint Size;
			IUnknown * apUnknown;
			myIID	iid;
		}

		//
		struct BYTE_SIZEDARR
			{
			uint clSize;
			byte	*pData;
			}	;

			//
		 struct	WORD_SIZEDARR
			{
			uint clSize;
			ushort *pData;
			}	;

			//
		struct	DWORD_SIZEDARR
			{
			uint clSize;
			uint * pData;
			}	;

			//
		struct	HYPER_SIZEDARR
			{
			uint clSize;
			long *pData;
			}



		union uSAFEARRAY_UNION {
		SAFEARR_BSTR	BstrStr;
		SAFEARR_UNKNOWN	UnknownStr;
		SAFEARR_DISPATCH DispatchStr;
		SAFEARR_VARIANT	VariantStr;
		SAFEARR_BRECORD	RecordStr;
		SAFEARR_HAVEIID	HaveIidStr;
		BYTE_SIZEDARR	ByteStr;
		WORD_SIZEDARR	WordStr;
		DWORD_SIZEDARR	LongStr;
		HYPER_SIZEDARR	HyperStr;
		}

		struct SAFEARRAY_UNION {
			uint sfType;
			uSAFEARRAY_UNION u;
		}

		alias SAFEARRAY_UNION SAFEARRAYUNION;

		struct SAFEARRAYBOUND {
			uint cElements;
			int lLbound;
		}
		struct wireSAFEARRAY {
			ushort cDims;
			ushort fFeatures;
			uint	cbElements;
			uint	cLocks;
			SAFEARRAYUNION uArrayStructs;
			SAFEARRAYBOUND[1] rgsabound;
		}
		alias wireSAFEARRAY SAFEARRAY ;
		//bbs.yidabu.com:above from win32.com.OAIDL
	

	run build.bat£º
	
		dmd test.d \dmd\src\other\juno\com\core.d \dmd\src\other\juno\com\client.d -g
-debug -O -L/exet:nt/su:windows:4.0
	

	prompt:Symbol Undefined _SafeArrayGetVartype 8
	search SafeArrayGetVartype in oleaut32.lib, found nothing.

	download linkdef from:
	http://www.dprogramming.com/linkdef.php
	build with£º
	
		dmd test.d \dmd\src\other\juno\com\core.d \dmd\src\other\juno\com\client.d -g
-debug -O -L/exet:nt/su:windows:4.0 | linkdef oleaut32
	

	then:
	
		implib safearray.lib oleaut32.def
	
	copy safearray.lib to \d\dm\lib, add code below to juno.com.core:
	
		pragma(lib, "safearray.lib");
	

	build test.d, run test.exe, send mail to gmail sucessed.
Jun 20 2007