Which is better code for converting BSTR parameters to ANSI in C/C++?

后端 未结 4 786
谎友^
谎友^ 2021-01-14 18:28

So far I\'ve discovered I can convert incoming BSTRs to ANSI in two (of many?) ways, and I\'m curious to know whether one is \"better\" than the other with respect to speed

4条回答
  •  执笔经年
    2021-01-14 19:00

    Note in the approved answer by Nick, which whilst correct shares the same problem there is with the MSDN documentation that describes the macros.

    The problem is that some of the macros such as the one listed by @Nick - COLE2A, don't actually exist.

    However further down the MSDN page there is some text that clues you into this fact and leads you to be able to figure out the correct macro!

    The text is listed in the table under the following text:

    There are several important differences between the older string conversion macros and the new string conversion classes:

    In the New ATL 7.0 Conversion Classes column.

    Which says:

    OLE is always equivalent to W

    So the macro in @Nick's example is actually CW2A

提交回复
热议问题