当程序要调用ocx时,需要在命令行中手动注册,这样太繁琐。
当然也可以调用bat打包注册,同样在每次运行程序前需要先运行bat,也比较麻烦;
于是考虑到在程序中直接用api函数完成注册。
参考自:https://blog.csdn.net/zztoll/article/details/53284470
注册代码
//register ocx ActiveX
void RegisterOcx(LPCTSTR pszOcxName)
{
// load ActiveX ocx
HINSTANCE hLib = LoadLibrary(pszOcxName);
if (hLib < (HINSTANCE)HINSTANCE_ERROR)
{
AfxMessageBox(L"ocx file could not be loaded! ");
return;
}
//get entry of DllRegisterServer fun
FARPROC lpDllEntryPoint;
lpDllEntryPoint = GetProcAddress(hLib, "DllRegisterServer");
//load DllRegisterServer fun
if (lpDllEntryPoint != NULL)
{
if (FAILED((*lpDllEntryPoint)()))
{
AfxMessageBox(L"Call to DllRegisterServer failed! Please run it as administrator");
FreeLibrary(hLib);
return;
};
TRACE("Regis