tchar.h, #defines, Cpp to D

BLS nanali at wanadoo.fr
Mon Sep 11 12:40:47 PDT 2006


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)											\
				typedef class I##proxy* PI##proxy;							\
				class NOVTABLE I##proxy { public:
	#define PROXY_DECLARE_V(proxy,version,compat_since)						\
				static const int proxy##_PROXY_VERSION=version;				\
				static const int proxy##_PROXY_COMPAT_SINCE=compat_since;	\
				typedef class I##proxy* PI##proxy;							\
				class NOVTABLE I##proxy : public IStdVersion { public:
	#define PROXY_METHOD(type,proxy,method,args)		virtual type __stdcall 
I##proxy::method args =0;
	#define PROXY_EMPTY_METHOD(proxy)				 
_PROXY_EMPTY_METHOD_BEG(proxy,__LINE__)
	#define _PROXY_EMPTY_METHOD_BEG(proxy,line)		virtual void 
I##proxy::_PROXY_EMPTY_METHOD_END(EmptySlot,line) () {}
	#define _PROXY_EMPTY_METHOD_END(method,line)		method##line
	#define PROXY_STDVERSION_METHODS(proxy)							\
				PROXY_METHOD(int,proxy,nGetVersion,())				\
				PROXY_METHOD(int,proxy,nGetCompatSince,())			\
				PROXY_METHOD(int,proxy,nGetDllNum,())				\
				virtual void I##proxy::StdVersion_EmptySlot_1() {}	\
				virtual void I##proxy::StdVersion_EmptySlot_2() {}	\
				virtual void I##proxy::StdVersion_EmptySlot_3() {}
	#define PROXY_END					};

	PROXY_DECLARE(StdVersion)
		PROXY_STDVERSION_METHODS(StdVersion)
	PROXY_END


#endif //#ifndef __PROXY_H



More information about the Digitalmars-d-learn mailing list