Originally posted by: Chris
SAFEARRAY FAR* psa = NULL;
hFile = CreateFile(
dwSizeOfFile = GetFileSize(hFile, NULL );
psa = SafeArrayCreateVector( VT_UI1 /*unsigned char*/, 0, dwSizeOfFile );
// Fill in the SAFEARRAY with the binary content of the file
V_VT(&vaResult) = VT_ARRAY | VT_UI1;
You just have to add passing parameters (filename) and that's it ! Clean this dirty code and add some fatal tests to !!
Don't try to response.write items returned by the function, VT_ARRAY | VT_UI1 can only be handled by BinaryWrite.
VARIANT cTheKFlasher::getData()
{
VARIANT vaResult; VariantInit(&vaResult);
DWORD dwSizeOfFile;
DWORD dwNumberOfBytesRead;
BOOL bResult;
HANDLE hFile;
unsigned char *pReturnBuffer = NULL;
"c:\\inetpub\\wwwroot\\test.gif", // name of the file
GENERIC_READ, // desired access
FILE_SHARE_READ, // shared access
NULL, // security attributes
OPEN_EXISTING, // creation disposition - open only if existing!
FILE_FLAG_SEQUENTIAL_SCAN, // flag attributes
NULL );
pReturnBuffer = new unsigned char[dwSizeOfFile];
bResult = ReadFile( hFile, pReturnBuffer, dwSizeOfFile, &dwNumberOfBytesRead, NULL );
if (psa == NULL)
AfxThrowOleDispatchException(1004, "Out of Memory");
for(long k = 0; k < (int) dwSizeOfFile; k++ )
{
if( FAILED(SafeArrayPutElement(psa, &k, &pReturnBuffer[k] )) )
{
AfxThrowOleDispatchException(1004, "Fail to add item");
}
}
V_ARRAY(&vaResult) = psa;
return vaResult;
}
If you wanted to allow access to the array for other purpose than BinaryWrite you should use VT_ARRAY | VT_VARIANT.
Originally posted by: Nobix
CGetFile::GetFile(VARIANT vFileName,VARIANT* pRtnFile /*[out,retval]*/ )
I got an Unexpected error in asp.
HELP !!!!
I don't want to use m_piResponse->BinaryWrite(..)
instead, I want to return this safearry to asp and
use Response.Binary(Obj.GetFile(filename));
Originally posted by: Fadi Abu-Hejleh
You should also enable the "Owner-draw fixed" property for
When using a dialog template,
specifing the LVS_EX_FULLROWSELECT type is not enough.
the dialog template.