Click here to Skip to main content
11,631,706 members (72,687 online)
Click here to Skip to main content
Add your own
alternative version

XCmyk - CMYK to RGB Calculator with source code

, 5 Jul 2003 CPOL 234.9K 4.7K 51
XCmyk implements an RGB to CMYK calculator
#include "StdAfx.h"
#include "gdipinitializer.h"

long CGDIpInitializer::m_initcount=0;  

CGDIpInitializer::CGDIpInitializer(bool bInitCtorDtor) 
: m_bInitCtorDtor(bInitCtorDtor), 
			m_bInited(false), m_hMap(NULL), m_gdiplusToken(NULL), 
			m_gdiplusStartupInput(NULL)
{
	if (m_bInitCtorDtor) 
		Initialize();
}

CGDIpInitializer::~CGDIpInitializer()  
{
	if (m_bInitCtorDtor) 
		Deinitialize();
}

void CGDIpInitializer::Initialize()
{
	if (!m_bInited) 
	{
		TCHAR buffer[1024];
		_stprintf(buffer, _T("GDIPlusInitID=%x"), GetCurrentProcessId());
		m_hMap = CreateFileMapping((HANDLE) INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE | SEC_COMMIT, 0, sizeof(long), buffer);
		if (m_hMap != NULL) 
		{
			// We might have a winner
			if (GetLastError() == ERROR_ALREADY_EXISTS) 
			{ 
				CloseHandle(m_hMap); 
			} 
			else 
			{
				// Yes, we have a winner
				m_bInited = true;
				Gdiplus::GdiplusStartup(&m_gdiplusToken, &m_gdiplusStartupInput, NULL);
				TRACE(_T("Inited GDIPlus\n"));
			}
		}
	}
	m_initcount++;
}

void CGDIpInitializer::Deinitialize()
{
	using namespace Gdiplus;

	m_initcount--;
	if (m_bInited && m_initcount == 0) 
	{
		TRACE(_T("GDIPlus shutdown\n"));
		Gdiplus::GdiplusShutdown(m_gdiplusToken);
		CloseHandle(m_hMap);
		m_bInited = false;
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Hans Dietrich
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see www.hdsoft.org.






You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150723.1 | Last Updated 6 Jul 2003
Article Copyright 2003 by Hans Dietrich
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid