Log in

View Full Version : CeCreateFile function to invoke app


wrappingduke
08-13-2008, 01:43 AM
Hello,

Attempting to use Rapi function to run java application on Pocket PC using CeCreateProcess function. It appears that the invocation runs intermittently. That is, the app does not appear to consistently run and I'm wondering if the CeCreateProcess call maybe the reason.

Here's a sample:

Dim sArgs as string
dim structProcess as PROCESS_INFORMATION

sArgs = "-Xbootclasspath/a:" & Chr(34) & "\Storage Card\database\jsr169.jar" & Chr(34) & _
"-classpath" & Chr(34) & "\Storage Card\MyJavaApp.jar" & Chr(34) & _
Chr(34) & "Parm1" & Chr(34)

Debug.Print sArgs

'result: -Xbootclasspath/a:"\Storage Card\database\jsr169.jar" -classpath "\Storage Card\MyJavaApp.jar" "Parm1"


CeCreateProcess "\Storage Card\bin\cvm.exe" & sArgs", _
"", vbNull, vbNull, 0, 0, vbNull, vbNull, vbNull, typProcessInfo


I have also tried:
-Xbootclasspath/a:"\Storage Card\database\jsr169.jar" -classpath "\Storage Card\MyJavaApp.jar" myjavaapp.Main "Parm1"
which works sometimes, as well.

The java app ran on Pocket PC creates a text file on the PPC. However, I haven't been able to delete this file w/ the CeDeleteFile due to a sharing violation.

Here's the code used:

' create me a handle to a file of this type.
lngFileHandle = CeCreateFile(sPathtoPPC & sFile, GENERIC_READ, FILE_SHARE_READ, vbNullString, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
'file is read into buffer to copied
intRetVal = CeReadFile(lngFileHandle, bytBuffer(1), 16384, lngBytesRead, 0)
'handle is closed added 08/12/08
CeFindClose lngFileHandle
'after file has been to desktop, the following is done
CeDeleteFile sPathtoPPC & "MyText1.DAT"


The odd thing about the delete issue is for those files that have been moved to PPC programmatically and not been created on the PPC, CeDeleteFile works fine. There's no issue with the delete.

any help is appreciated.

wrappingduke
08-16-2008, 03:04 AM
Hello,

I believe I have found the solution to the problem I was experiencing. CeCreateProcess runs a little more consistently w/out the some of the breakpoints in between execution.

Also, I was calling the wrong function to close the handle of a process, so this was the reason a file was not deleted when CeDeleteFile was invoke. I was using CeFindClose rather than CeCloseHandle.

wrappingduke
08-27-2008, 07:27 PM
Well, I don't I have the solution after all. It appears that CeCreateProcess was the source of the problem. As a result, attempting to use CeRapiInvoke to wait for the process complete before proceeding to the next thing.

However, I'm having some difficulty invoking this function. The desktop application used to call CeRapiInvoke unconditionally terminates when attempting to run the process in Block mode.

I'm using passing the parameter IRAPIStream a vbNull or other type of Null value.

Here's a sample of the code:

VB code:

'declaration of function
Declare Function CeRapiInvoke Lib "rapi.dll" ( _
ByVal pDllPath As String, _
ByVal pFunctionName As String, _
ByVal cbInput As Long, _
ByVal pInput As Byte, _
ByVal pcbOutput As Long, _
ByVal ppOutput As Byte, _
ByVal ppIRAPIStream As Any, _
ByVal dwReserved As Long) As Long
Dim ppInput(50) As Byte
Dim ppOutput(50) As Byte
Dim pcbOutput As Long
Dim pcbInput As Long
ppInput(1) = CByte(0)
pcbInput = LenB(ppInput(1))

ppOutput(1) = CByte(0)
pcbOutput = LenB(ppOutput(1))

'remotely execute routine by invoking custom DLL
'use Block mode
lRetVal = CeRapiInvoke( _
StrConv("\Storage Card\RunFlatFiles.dll", vbUnicode), _
StrrConv("Function1", vbUnicode), _
pcbInput, ppInput(1), _
pcbOutput, ppOutput(1), vbNull, 0)

Here's the code used C++ DLL

#define DllExport __declspec (dllexport)
// c++ file
extern "C" __declspec(dllexport) void Function1(LPCWSTR pDllPath, LPCWSTR
pFunctionName, DWORD cbInput, BYTE *pInput, DWORD *pcbOutput,
BYTE **ppOutput, IRAPIStream **ppIRAPIStream, DWORD dwReserved)
{
char sArgs[] = "testpath";
CreateProcess((LPCTSTR)"\\Storage (file://\\Storage) Card\\bin\\cvm.exe",
(LPTSTR)sArgs, NULL, NULL, false, 0, NULL, NULL,
NULL, &typProcessInfo);
}


any help is appreciated

wrappingduke
09-21-2008, 08:43 PM
Hello,

I was able to switch back to using CeCreateProcess. It appears that the windows ce was not permitting the execution a jar file, so switched to a zip file. But now I'm having an issue w/ CeFindFirstFile(). The execution of the zip file creates a .DAT file. However, when I check to see if the file exists w/ CeFindFirstFile, I'm receiving an invalid handle. When I look on the device, the file is there. I'm not sure why this is happening? Any help is appreciated.

Here's a sample of the code:

sArgs = "-Xbootclasspath/a:" & Chr(34) & _
sPathtoPPC & "jsr169.jar" & Chr(34) & _
" -Djava.class.path=" & Chr(34) & _
"\Storage Card\Myclasses.zip" & _
Chr(34) & " MyJavaApp.Main " & _
Chr(34) & sProcess & Chr(34)

lRetVal = CeCreateProcess("\Storage Card\bin\cvm.exe", _
sArgs, vbNull, vbNull, 0, 0, vbNull, _
vbNull, vbNull, typProcessInfo)
sFilePath = sPathtoPPC & sDataFile
lHandle = CeFindFirstFile(sFilePath, struct_FindData)