www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - tchar.h, #defines, Cpp to D

reply BLS <nanali wanadoo.fr> writes:
First of all: I know that giving good anweres ( to sometimes silly 
questions) is requireing patience and  takes a lot of time. So I can't 
repeat it enough : Thank you !

I have to translate the following pieces of code into D. (Btw : The 
following  code describes exactly why I hate C++)


/////////////////////////////////////////////////////CENTAL.H
#ifndef __CENTRAL_H
#define __CENTRAL_H

	#include <tchar.h>
	#define XCHAR		TCHAR
	#define _X(txt)		__T(txt)
	#define PCXSTR		LPCTSTR
	#define PXSTR		LPTSTR
	#define XRC			_X("\r\n")			// retour а la ligne
	#define STRCPY		_tcscpy
	#define STRICMP		_tcsicmp

	#if defined(__BORLANDC__)
		#define NOVTABLE
	#else
		#define NOVTABLE  __declspec(novtable)
	#endif
#ifdef __HFCONTEXT_H
#define WDFINHF	if (gclHF.piGetHFContext() != 
NULL){gclHF.piGetHFContext()->nExternalRelease();char ** pgclHF = (char 
**)((char *)&gclHF + sizeof(void*));*pgclHF = NULL;}
#define WDTerm	WDFINHF;WDTerm
#endif

#endif //#ifndef __CENTRAL_H


My primary problem is : How to handle the tchar.h stuff . Any hints are 
welcome.

----------------------------------------------------------------------------------------------

Next : The following code makes me really happy!
All I understand at the moment is that - Cpp class code is generated and 
the methods (generated by PROXY_METHOD) should be defined - in D -  as 
extern(Windows).
My question :  Will using  : dmc -c proyy.h -e -l  help?  Again, ANY 
hinst are welcome.

Björn


////////////////////////////////////////////PROXY.H
ifndef __PROXY_H
#define __PROXY_H

	#include "central.h"

	#define PROXY_DECLARE(proxy)											\


	#define PROXY_DECLARE_V(proxy,version,compat_since)						\




	#define PROXY_METHOD(type,proxy,method,args)		virtual type __stdcall 

	#define PROXY_EMPTY_METHOD(proxy)				 
_PROXY_EMPTY_METHOD_BEG(proxy,__LINE__)
	#define _PROXY_EMPTY_METHOD_BEG(proxy,line)		virtual void 

	#define
	#define PROXY_STDVERSION_METHODS(proxy)							\
				PROXY_METHOD(int,proxy,nGetVersion,())				\
				PROXY_METHOD(int,proxy,nGetCompatSince,())			\
				PROXY_METHOD(int,proxy,nGetDllNum,())				\



	#define PROXY_END					};

	PROXY_DECLARE(StdVersion)
		PROXY_STDVERSION_METHODS(StdVersion)
	PROXY_END


#endif //#ifndef __PROXY_H
Sep 11 2006
parent Lionello Lunesu <lio lunesu.remove.com> writes:
The _X() and _T() macros need not be converted. D will automatically 
interpret a string constant as ascii (actually utf8!) or wide (utf16) 
depending on the variable. You should use alias for the XCHAR (and 
TCHAR) type:

// this should be in a translated tchar.h
version(UNICODE) {
alias wchar TCHAR;
alias strcpy _tcscpy;
//etc
} else {
alias ubyte TCHAR;//note that 'char' implies utf8
alias wcscpy _tcscpy;
//etc
}

alias TCHAR XCHAR;
alias _tcscpy STRCPY;
const XCHAR[] XRC = "\r\n";
//etc

I've only seen your TCHAR/XCHAR stuff, so can't comment on the rest.

L.
Sep 12 2006