试试vHEADER=pHEARDER->GetChunk(pHEADER ->ActualSize)?
解决方案 »
- vs2010编译新建的win32控制台程序提示“AlwaysCreate信息”,请问如何去掉?
- 如何获取每个进程正在使用哪些端口通信的信息?
- 请教一些语法问题。
- 有没有判断注册表中某键存在与否的函数?
- 怎么样用IHTMLEmbedElement取flash的width和height,不能解决我就死了
- 开第2帖求关于多线程的问题了(还可加分)
- 关于序列化又要求c++功底的问题,在线等待......
- 请问RGB空间到LHS颜色空间怎么转换,谢谢了
- 有什么办法可以封闭OICQ吗!让它不好聊天
- 获取一个程序的文字输出框区域的文字信息,存入字符串str0中[进程通讯]
- 关于VC映射模式, 请帮助?
- vb???如何用VB控制在指定的位置打印文本?急急急!!!
谢谢你!DAVIDS
This example uses the AppendChunk and GetChunk methods to fill an image field with data from another record.#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")#define TESTHR(x) if FAILED(x) _com_issue_error(hr)
#define ChunkSize 100#include <ole2.h>
#include <stdio.h>
#include "conio.h"
#include "malloc.h"
#include "AppendChunkX.h"//Function declarations
void AppendChunkX(VOID);
void PrintProviderError(_ConnectionPtr pCnn1);///////////////////////////////////////////////////////////
// //
// Main Function //
// //
///////////////////////////////////////////////////////////
void main()
{
HRESULT hr = S_OK; hr = ::CoInitialize(NULL);
if (SUCCEEDED(hr))
{
AppendChunkX();
//Wait here for the user to see the output
printf("\n\nPress any key to continue..");
getch();
::CoUninitialize();
}
}
///////////////////////////////////////////////////////////
// //
// AppendChunkX Function //
// //
///////////////////////////////////////////////////////////
VOID AppendChunkX(VOID)
{
// Define ADO object pointers.
// Initialize pointers on define.
// These are in the ADODB:: namespace.
_RecordsetPtr pRstPubInfo = NULL;
_ConnectionPtr pCnn1 = NULL;
//Define other variables
IADORecordBinding *picRs = NULL; //Interface Pointer declared.(VC++ Extensions)
CPubInfoRs pubrs; //C++ class object HRESULT hr = S_OK;
_bstr_t strCnn("Provider=sqloledb;Data Source=SRV;"
"Initial Catalog=pubs;User Id=sa;Password=;");
_bstr_t strMessage,strPubID,strPRInfo;
_variant_t varChunk;
long lngOffSet,lngLogoSize;
char pubId[50];
lngOffSet = 0;
UCHAR chData;
CHAR ch;
SAFEARRAY FAR *psa;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = ChunkSize; try
{
//Open a Connection.
TESTHR(hr = pCnn1.CreateInstance(__uuidof(Connection)));
hr = pCnn1->Open(strCnn,"","",NULL); TESTHR(hr= pRstPubInfo.CreateInstance(__uuidof(Recordset)));
pRstPubInfo->CursorType = adOpenKeyset;
pRstPubInfo->LockType = adLockOptimistic;
hr = pRstPubInfo->Open("pub_info",_variant_t((IDispatch*)pCnn1,true),adOpenKeyset,adLockOptimistic,adCmdTable); //Open an IADORecordBinding interface pointer which we'll use for Binding Recordset to a class
if (FAILED(hr = pRstPubInfo->QueryInterface(__uuidof(IADORecordBinding),(LPVOID*)&picRs)))
_com_issue_error(hr); //Bind the Recordset to a C++ Class here
if (FAILED(hr = picRs->BindToRecordset(&pubrs)))
_com_issue_error(hr);
//Display the available logos here
strMessage = "Available logos are : " + (_bstr_t)"\n\n";
printf(strMessage);
int Counter = 0;
while(!(pRstPubInfo->EndOfFile))
{
printf("\n%s",pubrs.m_sz_pubid);
printf("\n%s",strtok(pubrs.m_sz_prinfo,",")); //Display 5 records at a time and wait for user to continue..
if (++Counter >= 5)
{ Counter = 0;
printf("\nPress any key to continue...");
getch();
}
pRstPubInfo->MoveNext();
}
//Prompt For a Logo to Copy
printf("\nEnter the ID of a logo to copy : ");
scanf("%s",pubId);strPubID = pubId; //Copy the logo to a variable in chunks
pRstPubInfo->Filter = "pub_id = '"+strPubID+"'"; lngLogoSize = pRstPubInfo->Fields->Item["logo"]->ActualSize;
//Create a safe array to store the array of BYTES
rgsabound[0].cElements = lngLogoSize;
psa = SafeArrayCreate(VT_UI1,1,rgsabound); long index1 =0;
while(lngOffSet < lngLogoSize)
{
varChunk = pRstPubInfo->Fields->Item["logo"]->GetChunk(ChunkSize); //Copy the data only upto the Actual Size of Field.
for(long index=0;index<=(ChunkSize-1);index++)
{
hr= SafeArrayGetElement(varChunk.parray,&index,&chData);
if(SUCCEEDED(hr))
{
// *pLogo++ = chData;
hr= SafeArrayPutElement(psa,&index1,&chData); //Take BYTE by BYTE and advance Memory Location
index1++;
}
else
break;
}
lngOffSet = lngOffSet + ChunkSize;
} lngOffSet = 0;
printf("Enter a new Pub Id : ");scanf("%s",pubrs.m_sz_pubid);strPubID = pubrs.m_sz_pubid;
printf("Enter descriptive text : " );scanf("%c",&ch);
gets(pubrs.m_sz_prinfo);
pRstPubInfo->AddNew();
pRstPubInfo->Fields->GetItem("pub_id")->PutValue(strPubID);
pRstPubInfo->Fields->GetItem("pr_info")->PutValue(pubrs.m_sz_prinfo);
//Assign the Safe array to a variant.
varChunk.vt = VT_ARRAY and VT_UI1;
varChunk.parray = psa;
hr = pRstPubInfo->Fields->GetItem("logo")->AppendChunk(varChunk);
lngOffSet = lngOffSet + ChunkSize;
//Update the table
pRstPubInfo->Update(); lngLogoSize = pRstPubInfo->Fields->Item["logo"]->ActualSize;
//Show the Newly added record..
printf("New Record : %s\n Description : %s\n Logo Size : %s",pubrs.m_sz_pubid,pubrs.m_sz_prinfo,(LPCSTR)(_bstr_t)pRstPubInfo->Fields->Item["logo"]->ActualSize); //Delete new record because this is demonstration.
pRstPubInfo->Requery(0); pCnn1->Execute("DELETE FROM PUB_INFO WHERE pub_id = '"+ strPubID +"'",NULL,adCmdText); //
pRstPubInfo->Close();
pCnn1->Close();
}
catch(_com_error &e)
{
// Notify the user of errors if any.
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description()); PrintProviderError(pRstPubInfo->GetActiveConnection());
printf("Source : %s \n Description : %s\n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription); }
}
///////////////////////////////////////////////////////////
// //
// PrintProviderError Function //
// //
///////////////////////////////////////////////////////////VOID PrintProviderError(_ConnectionPtr pCnn1)
{
// Print Provider Errors from Connection object.
// pErr is a record object in the Connection's Error collection.
ErrorPtr pErr = NULL;
long nCount = 0;
long i = 0; if( (pCnn1->Errors->Count) > 0)
{
nCount = pCnn1->Errors->Count;
// Collection ranges from 0 to nCount -1.
for(i = 0; i < nCount; i++)
{
pErr = pCnn1->Errors->GetItem(i);
printf("\t Error number: %x\t%s", pErr->Number,(LPCSTR) pErr->Description);
}
}
}AppendChunkX.h:#include "icrsint.h"
//This Class extracts pubid,prinfo.class CPubInfoRs : public CADORecordBinding
{
BEGIN_ADO_BINDING(CPubInfoRs)
ADO_VARIABLE_LENGTH_ENTRY2(1, adVarChar, m_sz_pubid,
sizeof(m_sz_pubid), l_pubid, TRUE)
ADO_VARIABLE_LENGTH_ENTRY2(3, adVarChar, m_sz_prinfo,
sizeof(m_sz_prinfo), l_prinfo, TRUE)
END_ADO_BINDING()public:
CHAR m_sz_pubid[10];
ULONG l_pubid;
CHAR m_sz_prinfo[200];
ULONG l_prinfo; };