开发者

COM: how to choose the compile option?

in the VS2008 ide, i write a wrapper to encapsulate the VC dll(vc.dll) to be a Com(com.dll) and the vc.dll will be called by c.exe

qutsion#1: i found the compile option for vc.dll was Char Set:Not Set my question is, Which Char 开发者_Python百科Set should i use to compile the com project?

question#2: if we set the Char set to be Not Set also for the com project ,then how should i handle the string in the interface of the functions? because there are many string types such as TCHAR and BSTR and _bstr_t which one is better for my Com project?

question#3: how should i set the Char Set for the C project(C.exe)?


There are zero reasons left to avoid setting the Character Set to Unicode. Windows has been a native Unicode operating system for the past 17 years. COM automation can only work with Unicode strings. It doesn't actually matter that much since you should be using BSTRs in your COM code, it is not affected by that setting.

Always use BSTR in your interface declarations. The _bstr_t class is indeed a handy wrapper class around BSTR to make manipulating these strings easy. TCHAR is archaic and not compatible with COM automation.

Same reasoning goes for the client app. The setting doesn't matter because you forced the client to use BSTR with your interface declaration. But not using Unicode in the rest of that app's code is archaic. And the code you'd have to write to convert the BSTR to a const char* and back is just a waste of your time and a potent source of lossage when the Unicode string contains characters that cannot be translated to the system code page. All mainstream COM clients (Java, .NET, Javascript and other scripting languages) use Unicode.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜