CeRapiInvoke (rapi)
Last changed: -129.115.64.14

.
Summary
Call custom function contained in DLL on Windows CE Device via the RAPI.

C# Signature:

[DllImport("rapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]

internal extern static int CeRapiInvoke(

   string pDllPath,
   string pFunctionName,
   uint cbInput,
   IntPtr pInput,
   out uint pcbOutput,
   out IntPtr ppOutput,
   IntPtr ppIRAPIStream,
   uint dwReserved);

User-Defined Types:

None.

Notes:

sDllPath must be in the MSDOS 8.3 filename format. Any other format that results in a larger filename will

fail. You can use this to access records in databases on the Windows CE Device. Therefore, no platform

invoke for the CeDatabase functions are needed.

Sample Code: [C#]

string sDllPath = @"\dbaccess.dll";

string sFunction = @"MyFunction";

int hResult = CeRapiInvoke(sDllPath, sFunction, 0, IntPtr.Zero, out uiOutput, out pOutput, IntPtr.Zero, 0);

if ( hResult != 0 )

{

   // Execution Failed

}

unsafe

{

   retOutput = new string((char*)pOutput.ToPointer());

}

Sample DLL: [C++]

[dbaccess.h]

#ifndef DBACCESS_H

#define DBACCESS_H

#ifndef RAPISTREAMFLAG

typedef enum tagRAPISTREAMFLAG

{

    STREAM_TIMEOUT_READ

} RAPISTREAMFLAG;

DECLARE_INTERFACE_ (IRAPIStream, IStream )

{

    STDMETHOD(SetRapiStat)(THIS_ RAPISTREAMFLAG Flag, DWORD dwValue) PURE;
    STDMETHOD(GetRapiStat)(THIS_ RAPISTREAMFLAG Flag, DWORD *pdwValue) PURE;

};

#endif

#ifdef __cplusplus

extern "C"{

#endif

__declspec (dllexport) INT MyFunction( DWORD, BYTE*, DWORD*, BYTE*, IRAPIStream *, PVOID );

#ifdef __cplusplus

}

#endif

#endif

[dbaccess.cpp]

#include "dbaccess.h"

#define MAXSTRINGLENGTH 1024

BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)

{

    return TRUE;

}

INT MyFunction( DWORD cbInput, BYTE pInput, DWORD pcbOutput, BYTE *ppOutput, IRAPIStream *pStream, PVOID reserved )

{

    LPTSTR outBuffer;

    outBuffer = (LPTSTR) LocalAlloc( LPTR, sizeof(TCHAR) * MAXSTRINGLENGTH );

    wsprintf( outBuffer, _T("This is just a Test!") );

pcbOutput = sizeof(TCHAR) MAXSTRINGLENGTH;

    LocalFree( pInput );
    return 0;

}

Documentation