开发者

Garbage character from query under 32-bit OS, fine in 64-bit

开发者 https://www.devze.com 2023-04-11 21:29 出处:网络
C++, OLEDB, running a query that returns 2 columns: an int and a varchar(50). So I want to put it in struct OutputData

C++, OLEDB, running a query that returns 2 columns: an int and a varchar(50).

So I want to put it in

struct OutputData
{
    int      intID;
    wchar_t* lpszName;      
} outputData;

So, I bind

    m_oleDBUtils.CreateDBBindings(true, &pRowsetBindings[0], 1, 
        offsetof(OutputData, intID), 4, DBTYPE_I4, 0, 
        DBPARAMIO_NOTPARAM);
    m_oleDBUtils.CreateDBBindings(false, &pRowsetBindings[1], 2, 
        offsetof(OutputData, lpszName), 50, DBTYPE_WSTR | DBTYPE_BYREF, 0, 
        DBPARAMIO_NOTPARAM);

Etc. etc.

I build for Win32. Under Windows 7 x64 (running the 32-bit DLL!), it works. Under Windows XP x86, I get consistent garbage in the first two characters (with the rest of the string being fine). So instead of

One
Two
Three

I see

XXe
XXo
XXree

Again, the garbage val开发者_Go百科ue is the same for all records. I thought it was alignment, but /Zp2, /Zp4, /Zp8 and /Zp16 all show the same behavior.

Any thoughts?


Switch to client-owned memory and /Zp1 fixed it.

0

精彩评论

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