Microsoft KB Archive/304964

= PRB: Stream Size May Vary Depending on Where It Is Loaded From =

Article ID: 304964

Article Last Modified on 8/23/2001

-

APPLIES TO


 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7

-



This article was previously published under Q304964



SYMPTOMS
When an ActiveX Data Objects (ADO) Stream object is loaded from a file, the leading 2 or 3 bytes of the stream may be used for the encoding. Therefore, if the size of the stream is checked, it may return 2 to 3 bytes more than the actual file size. However, if the stream is opened from the same file through a URL, the size of the stream is exactly the same as the file size.



STATUS
This behavior is by design.



MORE INFORMATION
The extra length can be 2 or 3 bytes depending on the code page (2 for UNICODE and 3 for UTF8). This discrepancy occurs only when the encoding is not already present in the file. If the encoding is present, the lengths are the same.

Steps to Reproduce Behavior
 Create an empty Win32 console application.  Add a new .cpp file to the project and paste the following code:
 * 1) include 
 * 2) import &quot;c:\program files\common files\system\ado\msado15.dll&quot; no_namespace rename(&quot;EOF&quot;, &quot;ADOEOF&quot;)

void main(int argc, char* argv[]) {

_StreamPtr m_pStream1, m_pStream2; int nSize1, nSize2; // File size3.txt has 3 characters. WCHAR m_strmSource2[1024]=L&quot;URL=http://adotest/size3.txt&quot;; WCHAR m_strmSource1[1024]=L&quot;\\\\adotest\\size3.txt&quot;; HRESULT hr = S_OK; try{

CoInitialize(NULL); _variant_t vSource; VariantInit(&vSource); vSource.vt = VT_ERROR; hr = m_pStream1.CreateInstance(__uuidof(Stream)); hr = m_pStream2.CreateInstance(__uuidof(Stream)); hr = m_pStream1->Open(vSource,adModeUnknown,adOpenStreamUnspecified,L&quot;&quot;,L&quot;&quot;);

m_pStream1->LoadFromFile(m_strmSource1); nSize1 = m_pStream1->Size; // 5 is returned, which is 3 + 2 (2 bytes for type encoding). hr = m_pStream2->Open(m_strmSource2,adModeUnknown,adOpenStreamUnspecified,L&quot;&quot;,L&quot;&quot;); nSize2 = m_pStream2->Size; // 3 is returned, which is expected.

printf(&quot;SIZE: Opening Stream from file returned: %d\n&quot;,nSize1); printf(&quot;SIZE: Opening Stream from URL returned: %d&quot;,nSize2);

hr = m_pStream1->Close; hr = m_pStream2->Close;

CoUninitialize; }       catch (_com_error &err){ _bstr_t bstrSource(err.Source); _bstr_t bstrDescription(err.Description); // Print Com errors. printf(&quot;Error\n&quot;); printf(&quot;\tCode = %08lx\n&quot;, err.Error); printf(&quot;\tCode meaning = %s\n&quot;, err.ErrorMessage); printf(&quot;\tSource = %s\n&quot;, (LPCSTR) bstrSource); printf(&quot;\tDescription = %s\n&quot;, (LPCSTR) bstrDescription); } }                    Build and then run the application to check the size difference.

Additional query words: ADO ADODB ADODB.Stream MDAC

Keywords: kbprb KB304964

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.