home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #1
/
monster.zip
/
monster
/
OS2
/
CENV2_19.ZIP
/
WIN_BOSS.LIB
< prev
next >
Wrap
Text File
|
1994-03-08
|
8KB
|
242 lines
// WIN_Boss.lib - Functions for controlling a Windows session. This library
// ver.1 works hand-in-hand with a session running ServeOS2.cmm via
// CEnvi for Windows.
//
//
#define WCF_TEXT 1 // format for clipboard text in Windows clipboard calls
#define WVK_LBUTTON 0x01
#define WVK_RBUTTON 0x02
#define WVK_CANCEL 0x03
#define WVK_MBUTTON 0x04
#define WVK_BACK 0x08
#define WVK_TAB 0x09
#define WVK_CLEAR 0x0C
#define WVK_RETURN 0x0D
#define WVK_SHIFT 0x10
#define WVK_CONTROL 0x11
#define WVK_MENU 0x12
#define WVK_ALT WVK_MENU
#define WVK_PAUSE 0x13
#define WVK_CAPITAL 0x14
#define WVK_ESCAPE 0x1B
#define WVK_SPACE 0x20
#define WVK_PRIOR 0x21
#define WVK_NEXT 0x22
#define WVK_END 0x23
#define WVK_HOME 0x24
#define WVK_LEFT 0x25
#define WVK_UP 0x26
#define WVK_RIGHT 0x27
#define WVK_DOWN 0x28
#define WVK_SELECT 0x29
#define WVK_PRINT 0x2A
#define WVK_EXECUTE 0x2B
#define WVK_SNAPSHOT 0x2C
#define WVK_INSERT 0x2D
#define WVK_DELETE 0x2E
#define WVK_HELP 0x2F
/* WVK_A thru WVK_Z are the same as their ASCII equivalents: 'A' thru 'Z' */
/* WVK_0 thru WVK_9 are the same as their ASCII equivalents: '0' thru '9' */
#define WVK_NUMPAD0 0x60
#define WVK_NUMPAD1 0x61
#define WVK_NUMPAD2 0x62
#define WVK_NUMPAD3 0x63
#define WVK_NUMPAD4 0x64
#define WVK_NUMPAD5 0x65
#define WVK_NUMPAD6 0x66
#define WVK_NUMPAD7 0x67
#define WVK_NUMPAD8 0x68
#define WVK_NUMPAD9 0x69
#define WVK_MULTIPLY 0x6A
#define WVK_ADD 0x6B
#define WVK_SEPARATOR 0x6C
#define WVK_SUBTRACT 0x6D
#define WVK_DECIMAL 0x6E
#define WVK_DIVIDE 0x6F
#define WVK_F1 0x70
#define WVK_F2 0x71
#define WVK_F3 0x72
#define WVK_F4 0x73
#define WVK_F5 0x74
#define WVK_F6 0x75
#define WVK_F7 0x76
#define WVK_F8 0x77
#define WVK_F9 0x78
#define WVK_F10 0x79
#define WVK_F11 0x7A
#define WVK_F12 0x7B
#define WVK_F13 0x7C
#define WVK_F14 0x7D
#define WVK_F15 0x7E
#define WVK_F16 0x7F
#define WVK_NUMLOCK 0x90
#include <PMdll.lib>
#include <FileIO.lib>
#include <NamePipe.lib>
#define CDECL_DLL_CALL 55
#define PASCAL_DLL_CALL 77
WinBossQuit()
{
return WinVoidFunction("ServeOS2Exit");
}
WinBossSelect(pPipeName) // True if exists, else false
{
sprintf(lFindName,"ServeOS2: %s",pPipeName);
// create list of switchable windows
lSwitchList = WinQuerySwitchList(Info().hab);
assert( lSwitchList != NULL );
lSwitchCount = 1 + GetArraySpan(lSwitchList);
for ( li = 0; li < lSwitchCount; li++ ) {
if ( 0 == WinQuerySwitchEntry(lSwitchList[li],lSwEntry)
&& lSwEntry.title && !stricmp(lSwEntry.title,lFindName) ) {
strcpy(gPipeName,pPipeName);
return(True);
}
}
return(False);
}
gPipeName = "ServeOS2"; // initialize to default
#define NO_WAIT_FOR_RETURN 0
#define WAIT_FOR_VOID_RETURN 1
#define WAIT_FOR_RETURN 2
WinFunction(pFunctionName,pReturnVar/*,Arg1,Arg2,Arg3...*/)
{
va_start(lVaList,pReturnVar);
lRetBLOb = WinBossExecuteFunction(pFunctionName,WAIT_FOR_RETURN,lVaList,va_arg()-2);
va_end(lVaList);
if ( lRetBLOb ) {
// convert the return from BLOb to real variable. The first SWORD32 is
// the variable type, the next SWORD32 is a dimension, then length
// (only good for buffers) and then the actual variable, data types are
switch ( lTypeOrLen = BLObGet(lRetBLOb,0,SWORD32) ) {
case (-CMM_BYTE): pReturnVar = BLObGet(lRetBLOb,4,UWORD8); break;
case (-CMM_INT): pReturnVar = BLObGet(lRetBLOb,4,SWORD32); break;
case (-CMM_FLOAT):pReturnVar = BLObGet(lRetBLOb,4,FLOAT64); break;
default: pReturnVar = BLObGet(lRetBLOb,4,lTypeOrLen); break;
}
}
return ( lRetBlob ? True : False );
}
WinVoidFunction(pFunctionName/*,Arg1,Arg2,Arg3...*/)
{
va_start(lVaList,pFunctionName);
lRetBLOb = WinBossExecuteFunction(pFunctionName,WAIT_FOR_VOID_RETURN,lVaList,va_arg()-1);
va_end(lVaList);
return ( lRetBlob ? True : False );
}
WinNoWaitFunction(pFunctionName/*,Arg1,Arg2,Arg3...*/)
{
va_start(lVaList,pFunctionName);
lRetBLOb = WinBossExecuteFunction(pFunctionName,NO_WAIT_FOR_RETURN,lVaList,va_arg()-1);
va_end(lVaList);
return ( lRetBlob ? True : False );
}
WinBossExecuteFunction(pFunctionName,pExpectReturnValue,pVaList,pVaListVarCount)
{
// first item is 0 for no wait for return, 1 to wait but void return, else 2 to wait for return
BLObPut(lSendBLOb,pExpectReturnValue,SWORD32);
// next item in BLOb is name of the function to call, put length first
BLObPut(lSendBLOb,1+strlen(pFunctionName),UWORD32);
BLObPut(lSendBLOb,pFunctionName,1+strlen(pFunctionName));
// next item is variable count
BLObPut(lSendBLOb,pVaListVarCount,UWORD32);
// finally, for each variable, send the var type then the variable
for ( lVarCount = 0; lVarCount < pVaListVarCount; lVarCount++ ) {
lVar = va_arg(pVaList,lVarCount);
if ( 1 == DataDimension(lVar) ) {
if ( CMM_BYTE != DataType(lVar) ) {
printf("\nWinBoss arrays may only be byte-type and 1 dimensional.\a\n");
abort();
}
lVarLen = 1+GetArraySpan(lVar);
BLObPut(lSendBLOb,lVarLen,SWORD32);
BLObPut(lSendBLOb,lVar,lVarLen);
} else {
lDataType = DataType(lVar);
BLObPut(lSendBLOb,-lDataType,SWORD32);
switch ( lDataType ) {
case CMM_BYTE: BLObPut(lSendBLOb,lVar,UWORD8); break;
case CMM_INT: BLObPut(lSendBLOb,lVar,SWORD32); break;
case CMM_FLOAT: BLObPut(lSendBLOb,lVar,FLOAT64); break;
default:
printf("\nWinBoss data type must be byte, integer, or float.\n\a");
abort();
}
}
}
// send blob is created. pass on return blob
return WinBossTransactBLObs(lSendBLOb);
}
WinBossTransactBLObs(pSendBLOb)
{
bool lSuccess = False; // assume failure
sprintf(lFullPipeName,"\\PIPE\\%s",gPipeName);
if ( !DosCreateNPipe(lFullPipeName,lPipeHandle,
NP_ACCESS_DUPLEX | NP_NOINHERIT,
NP_NOWAIT | NP_TYPE_BYTE | NP_UNLIMITED_INSTANCES | NP_READMODE_BYTE,
4096, 4096, 0) ) {
// Give the Windows program up to 10 seconds to open the file
for ( lRepeat = 10 * 10; lRepeat--; ) {
suspend(100);
if ( !DosConnectNPipe(lPipeHandle) ) {
lSuccess = True;
break;
}
}
if ( lSuccess ) {
lSuccess = False;
// change pipe to blocking state to make sure reads and writes are
// finished
DosSetNPHState(lPipeHandle,NP_WAIT | NP_READMODE_BYTE);
// write the output blob length as four bytes
BLObPut(lLenBLOb,BLObSize(pSendBLOb),UWORD32);
if ( !DosWrite(lPipeHandle,lLenBLOb,BLObSize(lLenBLOb),lBytesSent)
&& lBytesSent == BLObSize(lLenBLOb) ) {
// transact, which writes this command and waits for two-byte response size
if ( !DosWrite(lPipeHandle,pSendBLOb,BLObSize(pSendBLOb),lBytesSent)
&& BLObSize(pSendBLOb) == lBytesSent ) {
// Read return blob size
BLObPut(lReadCount,0,UWORD32);
if ( !DosRead(lPipeHandle,lReadCount,BLObSize(lReadCount),lBytesRead)
&& BLObSize(lReadCount) == lBytesRead ) {
// read in the result string
lResultLen = BLObGet(lReadCount,0,UWORD32);
BLObSize(lReceiveBLOb,lResultLen);
if ( !DosRead(lPipeHandle,lReceiveBLOb,lResultLen,lBytesRead)
&& lResultLen == lBytesRead ) {
lSuccess = True;
}
}
}
}
DosDisconnectNPipe(lPipeHandle);
}
DosClose(lPipeHandle);
}
return( lSuccess ? lReceiveBLOb : NULL );
}