|
From: TheOne on 22 Apr 2008 22:05 I want to be confirmed. I'm writing a dll which includes unicode and non-unicode version of Func, namely, FuncA and FuncW. The dll should include both of them and the application side must call these function accroding to their UNICODE setting. I guess I should give the app-writer header file which looks like, dllheader.h +++ #ifdef UNICODE #define Func FuncW #else #define Func FuncA #endif +++ However, if I include the same header, dllheader.h when building the dll. Then the dll's also have only one implementation according to UNICODE setting. So I guess I should have different headers to build the actually dll and to give the user to use to build his application. Am I right? Or, is there a way in which I can use the same header file for building dll and building app? TIA. -- Daewon YOON
From: Igor Tandetnik on 22 Apr 2008 22:19 "TheOne" <daewon.yoon(a)gmail.com> wrote in message news:2b6c3c7f-a333-462c-8411-08a3c6f6d21c(a)y21g2000hsf.googlegroups.com > I'm writing a dll which includes unicode and non-unicode version of > Func, namely, FuncA and FuncW. The dll should include both of them and > the application side must call these function accroding to their > UNICODE setting. > > I guess I should give the app-writer header file which looks like, > > dllheader.h > +++ > #ifdef UNICODE > #define Func FuncW > #else > #define Func FuncA > #endif > +++ > > However, if I include the same header, dllheader.h when building the > dll. Then the dll's also have only one implementation according to > UNICODE setting. Simply don't use Func in your DLL code. Write FuncA and FuncW explicitly. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Norman Bullen on 23 Apr 2008 00:04 TheOne wrote: > I want to be confirmed. > > I'm writing a dll which includes unicode and non-unicode version of > Func, namely, FuncA and FuncW. The dll should include both of them and > the application side must call these function accroding to their > UNICODE setting. > > I guess I should give the app-writer header file which looks like, > > dllheader.h > +++ > #ifdef UNICODE > #define Func FuncW > #else > #define Func FuncA > #endif > +++ > > However, if I include the same header, dllheader.h when building the > dll. Then the dll's also have only one implementation according to > UNICODE setting. So I guess I should have different headers to build > the actually dll and to give the user to use to build his application. > > Am I right? Or, is there a way in which I can use the same header file > for building dll and building app? > > TIA. > > -- > Daewon YOON I make a header like this for the users of the DLL. MyFunc.h --------------------------------------- int MyFuncA(LPCHAR strArgument); int MyFuncW(LPWCHAR strArgument); #if defined(_UNICODE_) #define MyFunc(strArgument) MyFuncW(strArgument) #else #define MyFunc(strArgument) MyFuncA(strArgument) #endif MyFunc.h --------------------------------------- Then I put all of the code for MyFunc() into another header which only I, the developer, will use. MyFuncT.h -------------------------------------- #include <tchar.h> #include "MyFunc.h" int MyFunc(LPTSTR strArgument) { // the body of the function } MyFuncT.h -------------------------------------- Then I create two C or C++ modules like this. MyFuncA.c -------------------------------------- #undef _UNICODE_ #undef UNICODE #include "MyFuncT.h" MyFuncA.c -------------------------------------- MyFuncW.c -------------------------------------- #define _UNICODE_ #define UNICODE #include "MyFuncT.h" MyFuncW.c -------------------------------------- Because the modules MyFuncA.c and MyFuncW.c have different names and define different entry point names, they can both be in the same DLL or LIB file. -- Norm To reply, change domain to an adult feline.
From: Giovanni Dicanio on 23 Apr 2008 05:56 "TheOne" <daewon.yoon(a)gmail.com> ha scritto nel messaggio news:2b6c3c7f-a333-462c-8411-08a3c6f6d21c(a)y21g2000hsf.googlegroups.com... > I'm writing a dll which includes unicode and non-unicode version of > Func, namely, FuncA and FuncW. The dll should include both of them and > the application side must call these function accroding to their > UNICODE setting. I would implement the FuncW (Unicode UTF-16 version), and then implement the FuncA (ANSI version) just as a thin wrapper of Unicode, i.e. the FuncA version converts the string(s) from Ansi to Unicode using e.g. CA2W and simply calls the Unicode version FuncW. void FuncW( const wchar_t * wsz... ) { ... full implementation (Unicode) ... ... } void FuncA( const char * sz ... ) { // Convert from Ansi to Unicode // each string passed as input CA2W wsz( sz ); ...CA2W wszAnother( szAnother ); ... // Just call the main Unicode implementation FuncW( wsz ... ); } You export both functions (A/W) from the DLL, and then use the classic "#ifdef UNICODE" preprocessor conditional paradigma in the DLL public header file: // dllheader: #ifdef UNICODE #define Func FuncW #else #define Func FuncA #endif HTH, Giovanni
|
Pages: 1 Prev: passing vector as argument Next: create vector with index base 1 |