i want to open a picture in a format like Jpg or bmp or gif
i added it to the resource so its binded in the exe and its not taken from the harddrive of the client who is running the exe
now what i want to do is to open this pic and display it in photoviewer of the window os
my c++ code is made on an EMPTY Project with multibyte character set.
Below is something i got from net but it has few problems like first of all its in UNICODE
then its using hardcoding for paths like its using
WCHAR wsParameters[MAX_PATH] = L"\"C:\\Program Files\\Windows Photo Viewer\\PhotoViewer.dll\" ImageView_Fullscreen ";
its not must that every os will be in the drive C
then on this line
WCHAR wsFile[MAX_PATH] = L"E:\\Temp\\test.jpg";
its storing the file in clients harddrive which i don't want to do
so any suggesstions??
What I have tried:
void SaveIStreamToFile(IStream *pIStream, LPWSTR pwsFile)
{
HANDLE hFile;
LPVOID pv = NULL;
LARGE_INTEGER li;
DWORD nNbBytesWritten;
ULONG nNbBytes;
HRESULT hr;
int nBufferSize = 4096;
hFile = CreateFile(pwsFile, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
pv = (LPSTR)LocalAlloc(LPTR, nBufferSize);
if (pv)
{
LISet32(li, 0);
pIStream->Seek(li, STREAM_SEEK_SET, NULL);
do
{
hr = pIStream->Read(pv, nBufferSize, &nNbBytes);
if (SUCCEEDED(hr))
{
if (!WriteFile(hFile, pv, nNbBytes, &nNbBytesWritten, NULL))
hr = E_FAIL;
}
} while ((SUCCEEDED(hr)) && (nNbBytes == nBufferSize));
LocalFree(pv);
}
CloseHandle(hFile);
}
return;
}
int main()
{
HRESULT(STDAPICALLTYPE * pSHCreateStreamOnDllResourceW)(PCWSTR pwszDll, PCWSTR pwszName, PCWSTR pwszType, IStream** ppstm);
HMODULE hInst = LoadLibrary(L"SHLWAPI.DLL");
if (hInst)
{
(FARPROC&)pSHCreateStreamOnDllResourceW = GetProcAddress(hInst, (LPCSTR)MAKEINTRESOURCE(627));
IStream *pstm;
if (pSHCreateStreamOnDllResourceW)
{
WCHAR wszPath[MAX_PATH];
GetModuleFileNameW(NULL, wszPath, MAX_PATH);
HRESULT hr = pSHCreateStreamOnDllResourceW(wszPath, (LPWSTR)MAKEINTRESOURCE(IDR_JPEG1), L"JPEG", &pstm);
WCHAR wsFile[MAX_PATH] = L"E:\\Temp\\test.jpg";
SaveIStreamToFile(pstm, wsFile);
WCHAR wsParameters[MAX_PATH] = L"\"C:\\Program Files\\Windows Photo Viewer\\PhotoViewer.dll\" ImageView_Fullscreen ";
lstrcat(wsParameters, wsFile);
WCHAR wsProgram[MAX_PATH] = L"rundll32.exe";
SHELLEXECUTEINFO sei;
ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.fMask = SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS;
sei.hwnd = NULL;
sei.lpVerb = L"open";
sei.lpFile = wsProgram;
sei.lpParameters = wsParameters;
sei.nShow = SW_SHOWNORMAL;
BOOL bReturn = ShellExecuteEx(&sei);
}
}
}