<h2>Question</h2> My Pocket PC doesn't have regsvr32 utility. How can I register my COM dll on a Pocket PC device?
<h2>Answer</h2> Pocket PC SDK contains a small utility regsvrce.exe for any supported processor. This utility is a replacement for desktop regsvr32.
<img alt="regsvrce.exe" src="/articles/images/regsvrce.gif" width="240" height="320">
I am annoyed to enter full name of dll library so I created a registration utility that could display a tree of dll files and you should only select file you want to register. You can download this utility there (<a href="samples/regsvr.zip">regsvr.zip</a>) for ARM devices and x86 emulator.
<img alt="regsvr.exe" src="/articles/images/regsvr.gif" width="240" height="320">
If you want to register or un-register COM dll from code you need to call <i>DllRegisterServer</i> or <i>DllUnregisterServer</i> functions from dll you want to register. You can copy-paste the following code:
Code:
//for registration
HMODULE hLib = ::LoadLibrary(strLib);
if(hLib == 0) {
return FALSE;
}
HRESULT (STDAPICALLTYPE *pDllRegisterServer)();
(FARPROC&)pDllRegisterServer = ::GetProcAddress(hLib, _T("DllRegisterServer"));
if(pDllRegisterServer == NULL) {
::FreeLibrary(hLib);
return FALSE;
}
if(FAILED(pDllRegisterServer ())) {
::FreeLibrary(hLib);
return FALSE;
} else {
::FreeLibrary(hLib);
return TRUE;
}
Code:
//for unregistration
HMODULE hLib = ::LoadLibrary(strLib);
if(hLib == 0) {
return FALSE;
}
HRESULT (STDAPICALLTYPE *pDllUnregisterServer)();
(FARPROC&)pDllUnregisterServer = ::GetProcAddress(hLib, _T("DllUnregisterServer"));
if(pDllUnregisterServer == NULL) {
::FreeLibrary(hLib);
return FALSE;
}
if(FAILED(pDllUnregisterServer())) {
::FreeLibrary(hLib);
return FALSE;
} else {
::FreeLibrary(hLib);
return TRUE;
}
Usually registration and un-registration are performed during installation stage. It is possible to declare all libraries that should be registered in installer .inf file. The key <i>CESelfRegister</i> is used for that.
<h2>Related resources:</h2>
<img src="http://www.pocketpcdn.com/images/bullet.gif" width="22" height="15"><a href="/sections/com.html">Section: COM/ActiveX</a>