Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
Make builds 100% clean
Browse files Browse the repository at this point in the history
  • Loading branch information
OJ committed Nov 14, 2013
1 parent 2e3ec9d commit 03c786b
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 68 deletions.
51 changes: 34 additions & 17 deletions source/extensions/extapi/clipboard_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@ DWORD get_encoder_clsid(WCHAR *mimeType, CLSID * pClsId)
{
UINT numEncoders;
UINT size;
if (GetImageEncodersSize(&numEncoders, &size) != Ok)
if (GetImageEncodersSize(&numEncoders, &size) != Ok) {
BREAK_WITH_ERROR("[EXTAPI CLIPIMG] Unable to get encoders array size.", ERROR_FUNCTION_FAILED);
}

if (size == 0)
if (size == 0) {
BREAK_WITH_ERROR("[EXTAPI CLIPIMG] No encoders found.", ERROR_FUNCTION_FAILED);
}

if ((pImageCodecInfo = (ImageCodecInfo*)malloc(size)) == NULL)
if ((pImageCodecInfo = (ImageCodecInfo*)malloc(size)) == NULL) {
BREAK_WITH_ERROR("[EXTAPI CLIPIMG] Couldn't allocate memory for ImageCodeInfo", ERROR_OUTOFMEMORY);
}

if (GetImageEncoders(numEncoders, size, pImageCodecInfo) != Ok)
if (GetImageEncoders(numEncoders, size, pImageCodecInfo) != Ok) {
BREAK_WITH_ERROR("[EXTAPI CLIPIMG] Unable to get encoders.", ERROR_FUNCTION_FAILED);
}

for (UINT i = 0; i < numEncoders; ++i) {
if (wcscmp(pImageCodecInfo[i].MimeType, mimeType) == 0) {
Expand All @@ -56,8 +60,9 @@ DWORD get_encoder_clsid(WCHAR *mimeType, CLSID * pClsId)
}
} while (0);

if (pImageCodecInfo != NULL)
if (pImageCodecInfo != NULL) {
free(pImageCodecInfo);
}

return dwResult;
}
Expand Down Expand Up @@ -130,16 +135,19 @@ DWORD convert_to_jpg(const LPBITMAPINFO lpBI, const LPVOID lpDIB, ULONG ulQualit

do
{
if (GdiplusStartup(&gdiPlusToken, &gdiStartupInput, NULL) != Ok)
if (GdiplusStartup(&gdiPlusToken, &gdiStartupInput, NULL) != Ok) {
BREAK_WITH_ERROR("[EXTAPI CLIPIMG] Unable to initialize GdiPlus", ERROR_FUNCTION_FAILED);
}

CLSID jpegClsid;
dprintf("[EXTAPI CLIPIMG] Attempting to get the jpg class id");
if (get_encoder_clsid(L"image/jpeg", &jpegClsid) != ERROR_SUCCESS)
if (get_encoder_clsid(L"image/jpeg", &jpegClsid) != ERROR_SUCCESS) {
BREAK_WITH_ERROR("[EXTAPI CLIPIMG] Unable to find an appropriate image encoder", ERROR_FUNCTION_FAILED);
}

if ((pBitmap = new Bitmap(lpBI, lpDIB)) == NULL)
if ((pBitmap = new Bitmap(lpBI, lpDIB)) == NULL) {
BREAK_WITH_ERROR("[EXTAPI CLIPIMG] Failed to create bitmap instance", ERROR_FUNCTION_FAILED);
}

EncoderParameters encParams;
encParams.Count = 1;
Expand All @@ -148,27 +156,32 @@ DWORD convert_to_jpg(const LPBITMAPINFO lpBI, const LPVOID lpDIB, ULONG ulQualit
encParams.Parameter[0].Type = EncoderParameterValueTypeLong;
encParams.Parameter[0].Value = &ulQuality;

if (CreateStreamOnHGlobal(NULL, TRUE, &pStream) != S_OK)
if (CreateStreamOnHGlobal(NULL, TRUE, &pStream) != S_OK) {
BREAK_WITH_ERROR("[EXTAPI CLIPIMG] Failed to create stream", ERROR_FUNCTION_FAILED);
}

if (pBitmap->Save(pStream, &jpegClsid, &encParams) != Ok)
if (pBitmap->Save(pStream, &jpegClsid, &encParams) != Ok) {
BREAK_WITH_ERROR("[EXTAPI CLIPIMG] Failed to save image to stream", ERROR_FUNCTION_FAILED);
}

STATSTG stat;
if (pStream->Stat(&stat, STATFLAG_NONAME) != S_OK)
if (pStream->Stat(&stat, STATFLAG_NONAME) != S_OK) {
BREAK_WITH_ERROR("[EXTAPI CLIPIMG] Failed to get image stat", ERROR_FUNCTION_FAILED);
}

// if the image requires the quadpart, then we're in trouble anyway!
pImage->dwImageBufferSize = stat.cbSize.LowPart;
if ((pImage->pImageBuffer = (LPBYTE)malloc(pImage->dwImageBufferSize)) == NULL)
if ((pImage->pImageBuffer = (LPBYTE)malloc(pImage->dwImageBufferSize)) == NULL) {
BREAK_WITH_ERROR("[EXTAPI CLIPIMG] Failed to allocate memory for the JPEG", ERROR_OUTOFMEMORY);
}

ULARGE_INTEGER pos;
LARGE_INTEGER zero;
zero.QuadPart = 0;
pos.QuadPart = 0;
if (pStream->Seek(zero, STREAM_SEEK_SET, &pos) != S_OK)
if (pStream->Seek(zero, STREAM_SEEK_SET, &pos) != S_OK) {
BREAK_WITH_ERROR("[EXTAPI CLIPIMG] Failed set stream position", ERROR_FUNCTION_FAILED);
}

ULONG bytesRead = 0;
if ((hRes = pStream->Read(pImage->pImageBuffer, pImage->dwImageBufferSize, &bytesRead) != S_OK)) {
Expand All @@ -177,23 +190,27 @@ DWORD convert_to_jpg(const LPBITMAPINFO lpBI, const LPVOID lpDIB, ULONG ulQualit
break;
}

if (bytesRead != pImage->dwImageBufferSize)
if (bytesRead != pImage->dwImageBufferSize) {
BREAK_WITH_ERROR("[EXTAPI CLIPIMG] Failed to read image data from stream", ERROR_FUNCTION_FAILED);
}
} while (0);

if (dwResult != ERROR_SUCCESS && pImage->pImageBuffer != NULL) {
free(pImage->pImageBuffer);
pImage->pImageBuffer = NULL;
}

if (pStream != NULL)
if (pStream != NULL) {
pStream->Release();
}

if (pBitmap != NULL)
if (pBitmap != NULL) {
delete pBitmap;
}

if (gdiPlusToken != 0)
if (gdiPlusToken != 0) {
GdiplusShutdown(gdiPlusToken);
}

return dwResult;
}
Expand Down
10 changes: 2 additions & 8 deletions source/extensions/extapi/extapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ Command customCommands[] =
*/
DWORD __declspec(dllexport) InitServerExtension(Remote *remote)
{
DWORD index;

hMetSrv = remote->hMetSrv;

for (index = 0; customCommands[index].method; index++)
command_register(&customCommands[index]);
command_register_all(customCommands);

return ERROR_SUCCESS;
}
Expand All @@ -54,10 +51,7 @@ DWORD __declspec(dllexport) InitServerExtension(Remote *remote)
*/
DWORD __declspec(dllexport) DeinitServerExtension(Remote *remote)
{
DWORD index;

for (index = 0; customCommands[index].method; index++)
command_deregister(&customCommands[index]);
command_deregister_all(customCommands);

return ERROR_SUCCESS;
}
Loading

0 comments on commit 03c786b

Please sign in to comment.