#ifndef __MyuShellExtRegister_H__
#define __MyuShellExtRegister_H__

//	stdafx.hにいれとくとコンパイルが早くなります
#include <atlbase.h>

#include <string>
#include <vector>

#define MAX_KEY		(256)

#define MYU_OK		(0)
#define MYU_ERR		(0)

//	クラス宣言
class CMyuShellExtRegister
{
private:
	std::string m_componentTitle;
	std::string m_moduleFullPath;
	std::vector<std::string> m_shellExtList;
	IID m_iid;
	std::string m_iidRegStr;

	DWORD RegistShell( const char* szExtType );
	DWORD UnRegistShell( const char* szExtType );

public:
	CMyuShellExtRegister();
	virtual ~CMyuShellExtRegister();

	//	設定系
	BOOL SetIID( REFIID iid );
	void SetComponentTitle( const char* szComponentTitle ){ m_componentTitle = szComponentTitle; }
	void AddShellExt( const char* szExtType ){ m_shellExtList.push_back( szExtType ); }
	void SetShellExtList( const char* szExtList );	//	"|"区切り
	void SetModuleName( const char* szModuleFullPath ){ m_moduleFullPath = szModuleFullPath; }

	//	設定するーぅ
	BOOL SetupObject( REFIID iid, const char* szModuleFullPath, const char* szComponentTitle )
	{
		if ( SetIID( iid ) != TRUE )
			return FALSE;
		SetModuleName( szModuleFullPath );
		SetComponentTitle( szComponentTitle );
		return TRUE;
	}

	//	登録/削除
	DWORD RegistShell();
	DWORD UnRegistShell();
	DWORD RegistModule();
	DWORD UnRegistModule();

	//	ユーティリティ関数っぽいの
	static BOOL GenIidToStr( REFIID iid, char* strOut, size_t nBufSize );
};

////////////////////////////////////////////////////////////////////////
//
//	簡易追加・削除系関数

inline HRESULT MyuShellExtRegister_EzRegist( BOOL bRegistOrUnregist,
	REFIID iid, const char* szComponentTitle, const char* szShellExtList, HMODULE hModule )
{
	char szModule[MAX_PATH+1];
	GetModuleFileName(hModule, szModule, sizeof(szModule));

	CMyuShellExtRegister regstr;
	regstr.SetupObject( iid, szModule, szComponentTitle );
	regstr.SetShellExtList(szShellExtList);

	if ( bRegistOrUnregist ){
		regstr.RegistShell();
		regstr.RegistModule();
	}
	else{
		regstr.UnRegistShell();
		regstr.UnRegistModule();
	}

	return S_OK;
}

//	マクロ化
#define _MYU_SHEXTREG__DllRegisterServer(iid,szComponentTitle,szShellExtList,HMODULE)	\
	STDAPI DllRegisterServer(void){	\
		return MyuShellExtRegister_EzRegist( TRUE, iid,szComponentTitle,szShellExtList,HMODULE ); }

#define _MYU_SHEXTREG__DllUnregisterServer(iid,szComponentTitle,szShellExtList,HMODULE)	\
	STDAPI DllUnregisterServer(void){	\
		return MyuShellExtRegister_EzRegist( FALSE, iid,szComponentTitle,szShellExtList,HMODULE ); }

#endif//__MyuShellExtRegister_H__