Export
- 객체 생성 함수
- 레지스트리 등록/해제 함수
-> CreateInstance()대신 DllGetClassObject()를 사용
Client
- CoGetClass Object () 함수 사용
-> 1. 레지스트리 검색. 2. 해당 DLL메모리로 로딩 3. DllGetClassObject함수 호출
4. 4번째 인자로 돌아온다.
// DLL을 레지스트리에로딩할때의 정보 -------------------------------
static HMODULE g_hModule = NULL;
const int CLSID_STRING_SIZE = 39;
const char szFriendlyName[] = "InsideCom Example";
const char szVerIndProgID[] = "InsideCom.Component";
const char szProgID[] = "InsideCom.Component.1";
//-------------------------------------------------------------------
STDAPI DllRegisterServer() // 라이브러리 처럼사용. 그대로 사용.
{
char szCLSID[CLSID_STRING_SIZE];
char szModule[512];
char szKey[64];
DWORD dwResult = ::GetModuleFileName(g_hModule,
szModule,
sizeof(szModule)/sizeof(char));
if(dwResult == 0) {
return E_FAIL;
}
ClsidToChar(CLSID_InsideCom, szCLSID,sizeof(szCLSID));
strcpy(szKey,"CLSID\\");
strcat(szKey,szCLSID);
SetRegistryInform(szKey,NULL,szFriendlyName);
SetRegistryInform(szKey,"InprocServer32",szModule); //Location..Threading Model
SetRegistryInform(szKey,"ProgID",szProgID); // Program ID
SetRegistryInform(szKey,"VersionIndependentProgID",szVerIndProgID);
//HKEY_CLASSES_ROOT\InsideCom Example
SetRegistryInform(szVerIndProgID,NULL,szFriendlyName);
SetRegistryInform(szVerIndProgID,"CLSID",szCLSID);
SetRegistryInform(szVerIndProgID,"CurVer",szProgID);
//HKEY_CLASSES_ROOT\InsideCom.Component.1
SetRegistryInform(szProgID, NULL, szFriendlyName);
SetRegistryInform(szProgID, "CLSID", szCLSID);
return S_OK;
}
STDAPI DllUnregisterServer() // 그대로 사용.
{
//Build the key CLSID\\{...}
char szCLSID[CLSID_STRING_SIZE];
char szKey[64];
ClsidToChar(CLSID_InsideCom,szCLSID,sizeof(szCLSID));
strcpy(szKey,"CLSID\\");
strcat(szKey, szCLSID);
//CLSID Key - CLSID\{...} 삭제.
LONG lResult = DeleteRegistryKey(HKEY_CLASSES_ROOT,szKey);
//version-independent ProgID Key 삭제.
lResult = DeleteRegistryKey(HKEY_CLASSES_ROOT,szVerIndProgID);
//ProgID Key 삭제
lResult = DeleteRegistryKey(HKEY_CLASSES_ROOT,szProgID);
return S_OK;
}