Page 1 of 1

Windows CE RAPI Functions

PostPosted: Fri Oct 20, 2006 1:02 pm
by Bill Simmeth
I hope Antonio doesn't mind me posting this question...

Has anyone here worked with the RAPI functions to interact with your FWPPC app? I am trying to invoke a maintenance routine from the desktop using Rapi, but with little success. Specifically, I am trying to use the CeCreateProcess function to start this. I am able to successfully initialize/uninitialize the Rapi session, but when I call CeCreateProcess, I consistently get a Winerror #2 -- File Not Found.

I am using Xbase++ on the desktop. Here's a sample trying to invoke the calculator. I get error #2 regardless of the way I specify the app name (ie; "calc.exe", "\\My Device\Windows\calc.exe", "calc", etc)
Code: Select all  Expand view
#include "DLL.CH"

#define NULL 0

Procedure Main
Local xVal

   xVal := CeRapiInit()
   ? xVal

   If xVal <> 0
      QUIT
   Endif

   xVal := CeCreateProcess( "\Windows\calc.exe", ;
                            "", ;
                            NULL, ;
                            NULL, ;
                            .f., ;
                            NULL, ;
                            NULL, ;
                            NULL, ;
                            NULL, ;
                            NULL )
   ? xVal
   ? CeRapiGetError()
   ? CeGetLastError()

   xVal := CERapiUninit()
   ? xVal

RETURN

DLLFUNCTION CeRapiGetError() USING STDCALL FROM RAPI.DLL
DLLFUNCTION CeGetLastError() USING STDCALL FROM RAPI.DLL
DLLFUNCTION CeRapiInit() USING STDCALL FROM RAPI.DLL
DLLFUNCTION CeRapiUninit() USING STDCALL FROM RAPI.DLL
DLLFUNCTION CeRapiInvoke( cPath, ;
                 cFunction, ;
                 nInputBytes, ;
                 nInput, ;
                 nOutPutBytes, ;
                 nOutput, ;
                 nNull ) USING STDCALL FROM RAPI.DLL
DLLFUNCTION CeCreateProcess(cApp, ;
                            cParm, ;
                            nZip1, ;
                            nZip2, ;
                            lFalse, ;
                            nZero, ;
                            nZip3, ;
                            nZip4, ;
                            nZip5, ;
                            nZip6 ) USING STDCALL FROM RAPI.DLL


Thanks in advance for any ideas.

PostPosted: Fri Oct 20, 2006 7:24 pm
by Bill Simmeth
It appears that the problem is the way I specify the file name that cuases file not found. Today I played with the CeCreateFile function and it works, but the resulting file on the PPC is placed at the root with a filename of "????????". Here's the function prototype:
Code: Select all  Expand view
CeCreateFile(LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);

I call this function as follows in Xbase++...
Code: Select all  Expand view
   nHnd := CeCreateFile( "\Temp\regmanip.txt", ;
                         GENERIC_WRITE, ;
                         FILE_SHARE_WRITE, ;
                         0, ;
                         CREATE_ALWAYS, ;
                         FILE_ATTRIBUTE_ARCHIVE, ;
                         0 )

Any suggestions on how the file name should be passed?

PostPosted: Sat Oct 21, 2006 5:58 pm
by Antonio Linares
Bill,

LPCWSTR means an unicode string not an ansi one.

Try with AnsiToWide( <cAnsiText> ) --> cUnicodeText