Click to See Complete Forum and Search --> : Re; Remote API calls with VB
Drew A
September 19th, 2001, 02:48 PM
I'm trying to use this rapi function to execute a dll on my remote machine. I've been able to run the dll with a C++ program but not with my VB program. I don't need to pass in any arguments its the matter of getting the return value from the dll in this pcbOutput variable. In C all I have to do is this:
DWORD cbOutput;
PBYTE pOutput;
HRESULT hres = CeRapiInvoke(L"\\FFX1\\HwRev", L"RaeGetHw", 0, 0, &cbOutput, &pOutput, NULL, 0);
But in VB I have this so far:
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 Long, _
byval dwReserved as Long) as Long
private Sub Command2_Click()
Dim lret as Long
Dim FilePath as string
Dim FileName as string
Dim ppOutput(100) as Byte
Dim pcbOutput as Long
Dim findData as CE_FIND_DATA
pcbOutput = 100
'Initialize RAPI
FileSelBackupCEInit
FilePath = "FFX1\HwRev.dll"
FileName = "RaeGetHw"
lret = CeFindFirstFile(FilePath, findData)
lret = CeRapiInvoke(FilePath, FileName, 0, 0, pcbOutput, ppOutput, 0, 0)
FileSelBackupCEUnInit
End Sub
any help would be trully appreciated
Thanks Drew A
DSJ
September 19th, 2001, 02:56 PM
Try passing ppOutput as the first element like:
lret = CeRapiInvoke(FilePath, FileName, 0, 0, pcbOutput, ppOutput(0), 0, 0)
let me know if it works!
Drew A
September 19th, 2001, 04:12 PM
I'm no longer getting any error messages but all I get in pcbOutput is 100 (the length of ppOutput). The result returned to lret is still a negative value indicating failure.
DSJ
September 19th, 2001, 04:25 PM
As soon as you call the function and get the return value, take a look at the Err object in the debugger and see what the value of Err.LastDLLError (or something like that)is, it'll help track down what the exact error is.
Drew A
September 19th, 2001, 04:36 PM
The error code is 87 which is ERROR_INVALID_PARAMETER
DSJ
September 19th, 2001, 04:45 PM
OK, I think I may see it now... the pInput will also need to be passed as a bytearray, try:
private Sub Command2_Click()
Dim lret as Long
Dim FilePath as string
Dim FileName as string
dim pcbInput as long
Dim ppInput(100) as byte
Dim ppOutput(100) as Byte
Dim pcbOutput as Long
Dim find
Data as CE_FIND_DATA
pcbInput = 100
pcbOutput = 100'Initialize RAPIFileSelBackupCEInitFilePath = "FFX1HwRev.dll"
FileName = "RaeGetHw"
lret = CeFindFirstFile(FilePath, findData)
lret = CeRapiInvoke(FilePath, FileName, pcbInput, pInput(0), pcbOutput, ppOutput(0), 0, 0)
FileSelBackupCEUnInit
End Sub
Drew A
September 20th, 2001, 08:00 AM
I'm still getting the Error 87 code for Invalid Parameter. Is there anyway to figure out which argument type I'm failing on. I know with the C version of my program all I have to do is define the Output variables to capture the return value. Thanks for all of your help by the way DSJ. You seem to be the only one reading any of my questions.
sb1423ul
September 20th, 2001, 08:18 AM
Hi,
Quick comment ...
"\\FFX1\\HwRev.dll" is different of "FFX1\HwRev". They don't refer to the same place and one has an extension.
Drew A
September 20th, 2001, 09:13 AM
The output arguments are explained like this in MSDEV:
pcbOutput :
[out] Pointer to a variable that is set to the number of bytes in the output buffer ppOutput when the function returns.
ppOutput :
[out] Pointer to a variable that is set to the location of the output buffer upon return.
Drew A
September 20th, 2001, 09:18 AM
I'm sure of the path name because of the CeFindFirstFile returns a valid handle to the file. But thanks anyway.
Drew A
September 20th, 2001, 09:19 AM
Here is all of the information on this RAPI Function that I can find.
CeRapiInvoke
This function can be used as a general-purpose mechanism to remotely execute a routine on the Windows CE device.
HRESULT CeRapiInvoke(
LPCWSTR pDllPath,
LPCWSTR pFunctionName,
DWORD cbInput,
BYTE *pInput,
DWORD *pcbOutput,
BYTE **ppOutput,
IRAPIStream **ppIRAPIStream,
DWORD dwReserved);
Parameters
pDllPath
[in] Pointer to a buffer containing the name of a DLL on the Windows CE device containing pFunctionName.
pFunctionName
[in] Pointer to a buffer containing the name of the function that RAPI should call on the Windows CE device.
cbInput
[in] Number of bytes in the input buffer *pInput.
pInput
[in] Pointer to a buffer containing the input data.
pcbOutput
[out] Pointer to a variable that is set to the number of bytes in the output buffer ppOutput when the function returns.
ppOutput
[out] Pointer to a variable that is set to the location of the output buffer upon return.
ppIRAPIStream
[out] Pointer to a variable that is set to the address of the IRAPIStream interface.
dwReserved
Reserved.
Return Values
DSJ
September 20th, 2001, 10:46 AM
Give this a shot...
private Sub Command2_Click()
Dim lret as Long
Dim FilePath as string
Dim FileName as string
dim pcbInput as long
Dim ppInput(100) as byte
Dim ppOutput as Byte
Dim pcbOutput as Long
Dim findData as CE_FIND_DATA
pcbInput = 100
RAPIFileSelBackupCEInitFilePath = "FFX1HwRev.dll"FileName = "RaeGetHw"
lret = CeFindFirstFile(FilePath, findData)
lret = CeRapiInvoke(FilePath, FileName, pcbInput, pInput(0), pcbOutput, ppOutput(0), 0, 0)
FileSelBackupCEUnInit
End Sub
Drew A
September 20th, 2001, 11:11 AM
Without ppOutput(100) As Byte I keep getting an expected array error and without the (0) in front of ppOutput in the CeRapiInvoke statement I just get the same Error 87. I think the major problem is the fact that these 2 output variables are not being implemented correctly they are defined as follows:
pcbOutput
[out] Pointer to a variable that is set to the number of bytes in the output buffer ppOutput when the function returns.
ppOutput
[out] Pointer to a variable that is set to the location of the output buffer upon return.
Again thanks for all of your help in this
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.