_bstr_b 范围问题是多少啊?MSDN上说:_bstr_t( char* s2 )   Constructs a _bstr_t object by calling SysAllocString to create a new BSTR object and encapsulate it. This constructor first performs a multibyte to Unicode conversion. 
If s2 is too large, you may generate a stack overflow error. In such a situation, convert your char* to a wchar_t with MultiByteToWideChar and then call the wchar_t * constructor
那么,我想知道这个更s2的最大长度是多少啊?

解决方案 »

  1.   

    栈空间通常是1MB,最多容纳512KB个Unicode字符,但各个函数都会使用栈空间,要根据程序可能的运行情况综合考虑。只要不是递归函数,KB级的使用是不需要考虑栈空间的。
      

  2.   

    我用ado插入数据到sql server,但有的记录很大,有好几兆。数据类型转换成_bstr_b时就出现问题了
      

  3.   

    那你试试按照建议的,转成wchar,再转换...
      

  4.   

    有好几兆。数据类型转换成_bstr_b时就出现问题了
    //msdn上的解释,是由于如果s2是多字节字符的话,在转换为unicode时,会产生栈空间溢出,直接使用wchar_t*转换为_bstr_t 不会有这个问题。也就是说,当你的字符串为char*时,先使用MultiByteToWideChar转换为wchar_t*,再转为_bstr_t.