DLLの登録

 ・サンプル
bool	RegServer(LPCTSTR lpcszDllPath,bool bRegist)
{
	typedef HRESULT (STDAPICALLTYPE* DllRegFunc) ();

	bool		ret;
	char		lpszDllEntry[30];
	HINSTANCE	hInstance;
	DllRegFunc	lpFunc;

	ret = false;
	if(lpcszDllPath != NULL)
	{
		if(bRegist == true)
			::strcpy(lpszDllEntry,_T("DllRegisterServer"));
		else
			::strcpy(lpszDllEntry,_T("DllUnregisterServer"));

		::OleInitialize(NULL);
		hInstance = ::LoadLibraryEx(lpcszDllPath,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);

		if(hInstance != NULL)
		{
			lpFunc = (DllRegFunc) ::GetProcAddress(hInstance,lpszDllEntry);

			if(lpFunc != NULL)
			{
				if(!(FAILED((*lpFunc)())))		// Call
					ret = true;					// 成功
			}
			::FreeLibrary(hInstance);			// 開放
		}
	}

	return	ret;
}

カテゴリー「VC++ TIPS」 のエントリー