A
Anon
On Windows 2000 or 2003 the following code works fine as an administrator
or Power User, but not as a regular user (it works fine for everyone on
NT4). OLELoadPicture is failing with an error of 0x80004005, which
apparently means "unspecified error". I've googled this to death with no
luck. Does anyone know why this fails? Thanks!
// This function loads a file into an IStream.
void LoadPictureFile(LPCTSTR szFile)
{
// open file
HANDLE hFile = CreateFile(szFile, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL);
_ASSERTE(INVALID_HANDLE_VALUE != hFile);
// get file size
DWORD dwFileSize = GetFileSize(hFile, NULL);
_ASSERTE(-1 != dwFileSize);
LPVOID pvData = NULL;
// alloc memory based on file size
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
_ASSERTE(NULL != hGlobal);
pvData = GlobalLock(hGlobal);
_ASSERTE(NULL != pvData);
DWORD dwBytesRead = 0;
// read file and store in global memory
BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
_ASSERTE(FALSE != bRead);
GlobalUnlock(hGlobal);
CloseHandle(hFile);
LPSTREAM pstm = NULL;
// create IStream* from global memory
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);
_ASSERTE(SUCCEEDED(hr) && pstm);
// Create IPicture from image file
if (gpPicture)
gpPicture->Release();
hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID
*)&gpPicture);
if (hr != 0) {
CHAR Buffer[10];
itoa(hr,Buffer,16);
MessageBox(NULL,Buffer,NULL,0);
}
_ASSERTE(SUCCEEDED(hr) && gpPicture);
pstm->Release();
//InvalidateRect(ghWnd, NULL, TRUE);
}
or Power User, but not as a regular user (it works fine for everyone on
NT4). OLELoadPicture is failing with an error of 0x80004005, which
apparently means "unspecified error". I've googled this to death with no
luck. Does anyone know why this fails? Thanks!
// This function loads a file into an IStream.
void LoadPictureFile(LPCTSTR szFile)
{
// open file
HANDLE hFile = CreateFile(szFile, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL);
_ASSERTE(INVALID_HANDLE_VALUE != hFile);
// get file size
DWORD dwFileSize = GetFileSize(hFile, NULL);
_ASSERTE(-1 != dwFileSize);
LPVOID pvData = NULL;
// alloc memory based on file size
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
_ASSERTE(NULL != hGlobal);
pvData = GlobalLock(hGlobal);
_ASSERTE(NULL != pvData);
DWORD dwBytesRead = 0;
// read file and store in global memory
BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
_ASSERTE(FALSE != bRead);
GlobalUnlock(hGlobal);
CloseHandle(hFile);
LPSTREAM pstm = NULL;
// create IStream* from global memory
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);
_ASSERTE(SUCCEEDED(hr) && pstm);
// Create IPicture from image file
if (gpPicture)
gpPicture->Release();
hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID
*)&gpPicture);
if (hr != 0) {
CHAR Buffer[10];
itoa(hr,Buffer,16);
MessageBox(NULL,Buffer,NULL,0);
}
_ASSERTE(SUCCEEDED(hr) && gpPicture);
pstm->Release();
//InvalidateRect(ghWnd, NULL, TRUE);
}