*
* only1run.prg
*
#define CLASS_NAME [pipetest]
#define INVALID_HANDLE_VALUE (-1)
*#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)
* dwOpenMode
#define PIPE_ACCESS_DUPLEX 0x00000003
#define PIPE_ACCESS_INBOUND 0x00000001
#define PIPE_ACCESS_OUTBOUND 0x00000002
#define FILE_FLAG_FIRST_PIPE_INSTANCE 0x00080000
#define FILE_FLAG_WRITE_THROUGH 0x80000000
#define FILE_FLAG_OVERLAPPED 0x40000000
#define WRITE_DAC 0x00040000
#define WRITE_OWNER 0x00080000
#define ACCESS_SYSTEM_SECURITY 0x01000000
* dwPipeMode
#define PIPE_TYPE_BYTE 0x00000000
#define PIPE_TYPE_MESSAGE 0x00000004
#define PIPE_READMODE_BYTE 0x00000000
#define PIPE_READMODE_MESSAGE 0x00000002
#define PIPE_WAIT 0x00000000
#define PIPE_NOWAIT 0x00000001
#define PIPE_ACCEPT_REMOTE_CLIENTS 0x00000000
#define PIPE_REJECT_REMOTE_CLIENTS 0x00000008
* nMaxInstances (1-)
#define PIPE_UNLIMITED_INSTANCES 0xff
*----------------------------------------------------------------------
parameters pipeGid
private o
m.o=createobject(CLASS_NAME)
if !empty(m.pipeGid)
if !m.o.createPipe(m.pipeGid)
return null
endif
endif
return m.o
*----------------------------------------------------------------------
define class CLASS_NAME as session
hPipe=INVALID_HANDLE_VALUE
w32lastError=0
function init
declare long CreateNamedPipe in kernel32 as w32_CreateNamedPipe;
string @ lpName,;
integer dwOpenMode,;
integer dwPipeMode,;
integer nMaxInstances,;
integer nOutBufferSize,;
integer nInBufferSize,;
integer nDefaultTimeOut,;
string @ lpSecurityAttribute
declare long GetLastError in kernel32 as w32_getlasterror
declare integer CloseHandle in kernel32 as w32_closehandle;
long hObject
function destroy
if this.hPipe!=INVALID_HANDLE_VALUE
=w32_closeHandle(this.hPipe)
this.hPipe=0
endif
function createPipe(name)
this.hPipe=w32_createNamedPipe(;
[\\.\pipe\]+m.name+chr(0),;
PIPE_ACCESS_DUPLEX+FILE_FLAG_FIRST_PIPE_INSTANCE,;
PIPE_TYPE_BYTE+PIPE_WAIT,;
1,;
500,;
500,;
2000,;
0;
)
if this.hPipe=INVALID_HANDLE_VALUE
this.w32lastError=w32_getlasterror()
return .f.
else
this.w32lastError=0
return .t.
endif
function connectPipe(name)
enddefine