CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Sep 2001
    Location
    Maine
    Posts
    15

    Re; Remote API calls with VB

    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


  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Re; Remote API calls with VB

    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!



  3. #3
    Join Date
    Sep 2001
    Location
    Maine
    Posts
    15

    Re: Re; Remote API calls with VB

    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.


  4. #4
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Re; Remote API calls with VB

    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.


  5. #5
    Join Date
    Sep 2001
    Location
    Maine
    Posts
    15

    Re: Re; Remote API calls with VB

    The error code is 87 which is ERROR_INVALID_PARAMETER


  6. #6
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Re; Remote API calls with VB

    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





  7. #7
    Join Date
    Sep 2001
    Location
    Maine
    Posts
    15

    Re: Remote API calls with VB

    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.


  8. #8
    Join Date
    Jul 2001
    Posts
    4

    Re: Re; Remote API calls with VB

    Hi,

    Quick comment ...

    "\\FFX1\\HwRev.dll" is different of "FFX1\HwRev". They don't refer to the same place and one has an extension.


  9. #9
    Join Date
    Sep 2001
    Location
    Maine
    Posts
    15

    Re: Remote API calls with VB

    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.


  10. #10
    Join Date
    Sep 2001
    Location
    Maine
    Posts
    15

    Re: Re; Remote API calls with VB

    I'm sure of the path name because of the CeFindFirstFile returns a valid handle to the file. But thanks anyway.


  11. #11
    Join Date
    Sep 2001
    Location
    Maine
    Posts
    15

    Re: Remote API calls with VB

    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


  12. #12
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Remote API calls with VB

    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





  13. #13
    Join Date
    Sep 2001
    Location
    Maine
    Posts
    15

    Re: Remote API calls with VB

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured