File: invokeme.cc

package info (click to toggle)
librapi2 0.15-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,820 kB
  • ctags: 1,474
  • sloc: ansic: 14,036; sh: 10,572; cpp: 851; python: 338; makefile: 226
file content (95 lines) | stat: -rw-r--r-- 1,841 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <ole2.h>

#undef  INTERFACE
#define INTERFACE   IRAPIStream

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;
};

EXTERN_C __declspec(dllexport) HRESULT TestLastError(
    DWORD cbInput,
    BYTE* pInput, 
    DWORD* pcbOutput, 
    BYTE** ppOutput,
    IRAPIStream* pStream)
{
  if (cbInput != sizeof(DWORD))
    return E_FAIL;
  SetLastError(*(DWORD*)pInput);
  return S_OK;
}

EXTERN_C __declspec(dllexport) HRESULT PingResult(
    DWORD cbInput,
    BYTE* pInput, 
    DWORD* pcbOutput, 
    BYTE** ppOutput,
    IRAPIStream* pStream)
{
  if (cbInput != (sizeof(HRESULT)))
    return E_FAIL;
  return *(HRESULT*)pInput;
}

EXTERN_C __declspec(dllexport) HRESULT PingBuffer(
    DWORD cbInput,
    BYTE* pInput, 
    DWORD* pcbOutput, 
    BYTE** ppOutput,
    IRAPIStream* pStream)
{
  *pcbOutput = cbInput;
  *ppOutput = (BYTE*)LocalAlloc(0, cbInput);
  memcpy(*ppOutput, pInput, cbInput);
  return S_OK;
}

EXTERN_C __declspec(dllexport) HRESULT PingStream(
    DWORD cbInput,
    BYTE* pInput, 
    DWORD* pcbOutput, 
    BYTE** ppOutput,
    IRAPIStream* pStream)
{
  DWORD size;
  BYTE* buffer;
  HRESULT hr = E_UNEXPECTED;
  DWORD count;

  if (cbInput != sizeof(DWORD))
    return E_FAIL;

  size = *(DWORD*)pInput;

  *pcbOutput = size;
  buffer = (BYTE*)LocalAlloc(0, size);

  Sleep(1);

  hr = pStream->Read(buffer, size, &count);
  if (FAILED(hr) || size != count)
    goto exit;

  Sleep(1);

  hr = pStream->Write(buffer, size, &count);
  if (FAILED(hr) || size != count)
    goto exit;

  hr = S_OK;

exit:
  LocalFree(buffer);
  return hr;
}