OLELoadPicture fails for regular users

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);
}
 
M

msalters

Anon said:
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).
Then it's not a C++ problem.

HTH,
Michiel Salters
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top