1 控件都有DllRegisterServer和DllUnregisterServer两个函数
控件用这两个函数自注册,regsvr32 也是同样的道理
下面一个函数看看
BOOL RegistrActiveServer(LPCSTR lpszOcxFileName,BOOL bRegister)
{
HINSTANCE hLib=::LoadLibrary(lpszOcxFileName);
if(hLib<(HINSTANCE)HINSTANCE_ERROR)
return FALSE;
FARPROC lpfnRegister;
if(bRegister)
{
(FARPROC&)lpfnRegister=::GetProcAddress(hLib,
_T("DllRegisterServer"));
}
else
{
(FARPROC&)lpfnRegister=::GetProcAddress(hLib,
_T("DllUnregisterServer"));
}
if(lpfnRegister!=NULL)
{
if((*lpfnRegister)()!=NOERROR)
{
::FreeLibrary(hLib);
return FALSE;
}
}
::FreeLibrary(hLib);
hLib=::LoadLibrary(lpszOcxFileName);
if(hLib<(HINSTANCE)HINSTANCE_ERROR)
{
return FALSE;
}
else
{
return TRUE;
}
::FreeLibrary(hLib);
}
2 GetSystemDirectory(SysPath,50);
strcpy(RegCmd,SysPath);
strcat(RegCmd,"//regsvr32 -s ");
strcat(RegCmd,YourFileName);
WinExec(RegCmd,SW_HIDE);