FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

tchar.h. #defines

 
Post new topic   Reply to topic     Forum Index -> Bindings
View previous topic :: View next topic  
Author Message
BLS



Joined: 28 Mar 2006
Posts: 44
Location: France

PostPosted: Mon Sep 11, 2006 2:48 pm    Post subject: tchar.h. #defines Reply with quote

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 hints 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
Back to top
View user's profile Send private message
KlausO



Joined: 16 Feb 2006
Posts: 27
Location: Germany

PostPosted: Tue Sep 12, 2006 2:25 pm    Post subject: Reply with quote

As you might already know tchar.h is a header which tries to provide UNICODE agnostic wrappers around runtime library functions. The aim of tchar.h is to write one source and to be able to compile it as UNICODE or ANSI version.

But in your case you could savely ommit that ugly part of the game (It seems that proxy.h is not using TCHAR declarations).
proxy.h reminds me of the macros used by M$ to declare COM-interfaces in a manner that the same source could be compiled by a C or a C++ compiler.

Your code seems to declare an interface named IStdVersion with three methods and three empty method slots for further extensions

In D this could be expressed as follows:
Code:

interface IStdVersion
{
  extern (Windows):
    int GetVersion();
    int GetCompatSince();
    int GetDllNum();
    void StdVersion_EmptySlot_1();
    void StdVersion_EmptySlot_2();
    void StdVersion_EmptySlot_3();
}


In your code I do not see any references to IUnknown or any other COM interfaces, so I guess that your interface does not support reference counting or querying other interfaces. In this case it's not necessary to inherit an implemenation from ComObject as described in

http://www.digitalmars.com/d/dll.html#com
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Bindings All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group