Summary: Windows Mobile 5.0 CeRapiInvoke has restricted security. This is over and above the security restrictions for RAPI in general. It is a permissions issue rather than a certificate-releated privileged code issue.


Here are some instructions for configuring RAPI so that your DLL can be invoked. It expands on what the SDK topic says.



How to configure CeRapiInvoke Permissions for a DLL

1. Use the Metabase CSP to assign RAPI permissions to the DLL in question
2. Set the System attribute on the DLL file
3. Call CeRapiInvoke


DETAILS - for CAB installation

1. To configure the permissions via CAB installation, you have to be able to run the CSP from the CAB. Running the CSP can be done via the api function DMProcessConfigXML(). Call this function from the CAB file. How? By adding custom code to the CAB using a "CE Setup DLL":
a. Create the DLL using C/C++, compiled for the Windows Mobile 5.0 SDK
b. All the DLL needs to do is call DMProcessConfigXML() passing in an XML string as the input parameter. Here is some code:

codeINSTALLINIT InstallInit()
{
		  LPCWSTR wszXml = 
		  L"<wap-provisioningdoc> "
		  L" <characteristic type=\"Metabase\"> "
		  L"  <characteristic type=\"RAPI\\Program Files\\My Co.\\MyApp.dll\\*\"> "
		  L"    <parm name=\"rw-access\" value=\"3\"/> "
		  L"    <parm name=\"access-role\" value=\"152\"/> "
		  L"   </characteristic> "
		  L"  </characteristic> "
		  L"</wap-provisioningdoc> ";
	

		  HRESULT hr         = E_FAIL;
		  LPWSTR wszOutput   = NULL;
	

		  // Process the XML.
		  hr = DMProcessConfigXML(g_wszFavoriteXml, CFGFLAG_PROCESS, &wszOutput);
	

		  // The caller must delete the XML returned from [DMProcessConfigXML.]
		  delete [] wszOutput;   
	

		  if(hr != ERROR_SUCCESS)
		  {
		      Messagebox(NULL,L"Failed",L"DMProcessConfigXML",MB_OK);
		      return codeINSTALL_INIT_CANCEL;
		  }
		  return codeINSTALL_INIT_CONTINUE;
	
}

NOTE: for the path to the DLL, it is "RAPI" + file system path + "/*"

c. Compile the DLL
d. Reference the DLL in your CAB's INF file:

		   [DefaultInstall]
		   [CESetupDLL] = [mySetupDll.dll]
	

2.
Set the System attribute on the RapiInvoke DLL file. After the CAB runs and has copied the app DLL over, set the file system attribute. The Setup DLL's after event should be sufficient:

codeINSTALLINIT InstallExit(hwndParent, pszInstallDir, ....)
{
		   // concatentate [pszInstallDir] with the DLL name
		   ...
		   [SetFileAttributes(lpFileName,] FILE_ATTRIBUTE_SYSTEM);
		   ...
	

3.
Call CeRapiInvoke in your application. This should work successfully after RAPI permissions for the DLL were set (Step 1) and the file has been copied to the file system and attributed (Step 2).


reference: Windows Mobile 5.0 SDK topics
		 ['CeRapiInvoke] (SP + PPC)'
		 ['DMProcessConfigXML']
		 'Optional Setup.dll Files for Installation', also see:
		 http://msdn2.microsoft.com/en-us/library/ms860345.aspx
		 ['CopyFile'] (Windows CE 5.0) -- see 
		 http://msdn2.microsoft.com/en-us/library/aa458980.aspx
		 ['SetFileAttributes']
		 http://msdn2.microsoft.com/en-us/library/aa912257.aspx
	


Microsoft Communities