📄 mswin.cxx
字号:
}
BYTE PSerialChannel::GetDataBits() const
{
return deviceControlBlock.ByteSize;
}
BOOL PSerialChannel::SetParity(Parity parity)
{
return SetCommsParam(0,0, parity, 0, DefaultFlowControl, DefaultFlowControl);
}
PSerialChannel::Parity PSerialChannel::GetParity() const
{
switch (deviceControlBlock.Parity) {
case ODDPARITY :
return OddParity;
case EVENPARITY :
return EvenParity;
case MARKPARITY :
return MarkParity;
case SPACEPARITY :
return SpaceParity;
}
return NoParity;
}
BOOL PSerialChannel::SetStopBits(BYTE stop)
{
return SetCommsParam(0,
0, DefaultParity, stop, DefaultFlowControl, DefaultFlowControl);
}
BYTE PSerialChannel::GetStopBits() const
{
return (BYTE)(deviceControlBlock.StopBits == ONESTOPBIT ? 1 : 2);
}
BOOL PSerialChannel::SetInputFlowControl(FlowControl flowControl)
{
return SetCommsParam(0,0, DefaultParity, 0, flowControl, DefaultFlowControl);
}
PSerialChannel::FlowControl PSerialChannel::GetInputFlowControl() const
{
if (deviceControlBlock.fRtsflow)
return RtsCts;
if (deviceControlBlock.fInX != 0)
return XonXoff;
return NoFlowControl;
}
BOOL PSerialChannel::SetOutputFlowControl(FlowControl flowControl)
{
return SetCommsParam(0,0, DefaultParity, 0, DefaultFlowControl, flowControl);
}
PSerialChannel::FlowControl PSerialChannel::GetOutputFlowControl() const
{
if (deviceControlBlock.fOutxCtsFlow != 0)
return RtsCts;
if (deviceControlBlock.fOutX != 0)
return XonXoff;
return NoFlowControl;
}
void PSerialChannel::SetDTR(BOOL state)
{
if (!IsOpen()) {
osError = EBADF;
lastError = NotOpen;
return;
}
PAssert(EscapeCommFunction(os_handle, state ? SETDTR : CLRDTR) == 0,
POperatingSystemError);
}
void PSerialChannel::SetRTS(BOOL state)
{
if (!IsOpen()) {
osError = EBADF;
lastError = NotOpen;
return;
}
PAssert(EscapeCommFunction(os_handle, state ? SETRTS : CLRRTS) == 0,
POperatingSystemError);
}
void PSerialChannel::SetBreak(BOOL state)
{
if (!IsOpen()) {
osError = EBADF;
lastError = NotOpen;
return;
}
if (state)
PAssert(SetCommBreak(os_handle), POperatingSystemError);
else
PAssert(ClearCommBreak(os_handle), POperatingSystemError);
}
BOOL PSerialChannel::GetCTS()
{
if (!IsOpen()) {
osError = EBADF;
lastError = NotOpen;
return FALSE;
}
return (GetCommEventMask(os_handle, 0)&EV_CTSS) != 0;
}
BOOL PSerialChannel::GetDSR()
{
if (!IsOpen()) {
osError = EBADF;
lastError = NotOpen;
return FALSE;
}
return (GetCommEventMask(os_handle, 0)&EV_DSR) != 0;
}
BOOL PSerialChannel::GetDCD()
{
if (!IsOpen()) {
osError = EBADF;
lastError = NotOpen;
return FALSE;
}
return (GetCommEventMask(os_handle, 0)&EV_RLSDS) != 0;
}
BOOL PSerialChannel::GetRing()
{
if (!IsOpen()) {
osError = EBADF;
lastError = NotOpen;
return FALSE;
}
return (GetCommEventMask(os_handle, 0)&EV_RING) != 0;
}
PStringList PSerialChannel::GetPortNames()
{
static char buf[] = "COM ";
PStringList ports;
for (char p = '1'; p <= '4'; p++) {
buf[3] = p;
ports.Append(new PString(buf));
}
return ports;
}
///////////////////////////////////////////////////////////////////////////////
// PPipeChannel
BOOL PPipeChannel::Execute()
{
if (hasRun)
return FALSE;
flush();
if (os_handle >= 0) {
_close(os_handle);
os_handle = -1;
}
static struct {
DWORD pifFlags;
DWORD displayFlags;
struct {
DWORD offset;
WORD selector;
} exePath, programArguments, workingDirectory;
WORD desiredV86Pages;
WORD minimumV86Pages;
WORD foregroundPriority;
WORD backgroundPriority;
WORD maximumEMS;
WORD minimumEMS;
WORD maximumXMS;
WORD minimumXMS;
DWORD unknown;
char windowTitle[128];
} seb = {
0x40000006, // Runs in background, runs in window, close on exit
0x0000001f, // Emulate text mode, no monitor ports
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
0xffff, // desired memory
0xffff, // minimum memory
100, // foreground priority
50, // background priority
0x0400, // maximum EMS
0, // minimum EMS
0x4000, // maximum XMS
0, // minimum XMS
0, // unknown
"PWLib Pipe Channel Process"
};
char * commandDotCom = getenv("COMSPEC");
if (commandDotCom == NULL)
commandDotCom = "C:\\COMMAND.COM";
seb.exePath.selector = SELECTOROF(commandDotCom);
seb.exePath.offset = OFFSETOF (commandDotCom);
PString commandArguments = " /c " + subProgName;
const char * argumentPointer = commandArguments;
seb.programArguments.selector = SELECTOROF(argumentPointer);
seb.programArguments.offset = OFFSETOF (argumentPointer);
static char * currentDirectory = ".";
seb.workingDirectory.selector = SELECTOROF(currentDirectory);
seb.workingDirectory.offset = OFFSETOF (currentDirectory);
void (FAR * shellEntry)();
_asm mov ax,1684h; //Get Shell VXDs protected mode entry point
_asm mov bx,0017h;
_asm int 2fh;
_asm mov word ptr [shellEntry], di;
_asm mov word ptr [shellEntry+2], es;
if (shellEntry == NULL)
return FALSE;
_asm lea di, word ptr seb;
_asm mov dx, 3;
_asm push es;
_asm push ss;
_asm pop es;
shellEntry();
_asm pop es;
DWORD hVirtualMachine;
#if defined(_MSC_VER)
_asm _emit 66h;
#else
_asm db 66h;
#endif
_asm mov word ptr hVirtualMachine, ax; // Really EAX
if (hVirtualMachine == 0)
return FALSE;
if (fromChild.IsEmpty())
return TRUE;
// Wait for child to complete
os_handle = _open(fromChild, _O_RDONLY);
return ConvertOSError(os_handle);
}
///////////////////////////////////////////////////////////////////////////////
// Configuration files
void PConfig::Construct(Source src)
{
switch (src) {
case System :
location = "WIN.INI";
break;
case Application :
PFilePath appFile = PProcess::Current()->GetFile();
location = appFile.GetDirectory() + appFile.GetTitle() + ".INI";
break;
}
source = src;
}
void PConfig::Construct(const PFilePath & filename)
{
location = filename;
source = NumSources;
}
PStringList PConfig::GetSections()
{
PStringList sections;
if (source != Environment) {
PString buf;
char * ptr = buf.GetPointer(10000);
GetPrivateProfileString(NULL, NULL, "", ptr, 9999, location);
while (*ptr != '\0') {
sections.AppendString(ptr);
ptr += strlen(ptr)+1;
}
}
return sections;
}
PStringList PConfig::GetKeys(const PString & section) const
{
PStringList keys;
if (source == Environment) {
char ** ptr = _environ;
while (*ptr != NULL) {
PString buf = *ptr++;
keys.AppendString(buf.Left(buf.Find('=')));
}
}
else {
PString buf;
char * ptr = buf.GetPointer(10000);
GetPrivateProfileString(section, NULL, "", ptr, 9999, location);
while (*ptr != '\0') {
keys.AppendString(ptr);
ptr += strlen(ptr)+1;
}
}
return keys;
}
void PConfig::DeleteSection(const PString & section)
{
if (source == Environment)
return;
PAssert(!section.IsEmpty(), PInvalidParameter);
PAssertOS(WritePrivateProfileString(section, NULL, NULL, location));
}
void PConfig::DeleteKey(const PString & section, const PString & key)
{
PAssert(!key.IsEmpty(), PInvalidParameter);
if (source == Environment) {
PString str = key;
PAssert(str.Find('=') == P_MAX_INDEX, PInvalidParameter);
_putenv(str + "=");
}
else {
PAssert(!section.IsEmpty(), PInvalidParameter);
PAssertOS(WritePrivateProfileString(section, key, NULL, location));
}
}
PString PConfig::GetString(const PString & section,
const PString & key, const PString & dflt)
{
PString str;
PAssert(!key.IsEmpty(), PInvalidParameter);
if (source == Environment) {
PAssert(key.Find('=') == P_MAX_INDEX, PInvalidParameter);
char * env = getenv(key);
if (env != NULL)
str = env;
else
str = dflt;
}
else {
PAssert(!section.IsEmpty(), PInvalidParameter);
GetPrivateProfileString(section, key, dflt,
str.GetPointer(1000), 999, location);
str.MakeMinimumSize();
}
return str;
}
void PConfig::SetString(const PString & section,
const PString & key, const PString & value)
{
PAssert(!key.IsEmpty(), PInvalidParameter);
if (source == Environment) {
PString str = key;
PAssert(str.Find('=') == P_MAX_INDEX, PInvalidParameter);
_putenv(str + "=" + value);
}
else {
PAssert(!section.IsEmpty(), PInvalidParameter);
PAssertOS(WritePrivateProfileString(section, key, value, location));
}
}
///////////////////////////////////////////////////////////////////////////////
// Threads
static char NEAR * NEAR * const StackBase = (char NEAR * NEAR *)0xa;
static char NEAR * NEAR * const StackUsed = (char NEAR * NEAR *)0xc;
static char NEAR * NEAR * const StackTop = (char NEAR * NEAR *)0xe;
void PThread::SwitchContext(PThread * from)
{
if (from == this) // Switching to itself, ie is only thread
return;
if (setjmp(from->context) != 0) // Are being reactivated from previous yield
return;
// Save some magic global variables in MS-Windows DGROUP segment
from->stackBase = *StackBase;
from->stackTop = *StackTop;
from->stackUsed = *StackTop - *StackUsed;
if (status == Starting) {
if (setjmp(context) != 0)
BeginThread();
context[3] = (int)stackTop-16; // Change the stack pointer in jmp_buf
}
// Restore those MS-Windows magic global for the next context
*StackBase = stackBase;
*StackTop = stackTop;
*StackUsed = stackTop - stackUsed;
longjmp(context, TRUE);
PAssertAlways("longjmp failed"); // Should never get here
}
///////////////////////////////////////////////////////////////////////////////
// PDynaLink
PDynaLink::PDynaLink()
{
_hDLL = NULL;
}
PDynaLink::PDynaLink(const PString & name)
{
Open(name);
}
PDynaLink::~PDynaLink()
{
Close();
}
BOOL PDynaLink::Open(const PString & name)
{
if ((_hDLL = LoadLibrary(name)) < HINSTANCE_ERROR)
_hDLL = NULL;
return _hDLL != NULL;
}
void PDynaLink::Close()
{
if (_hDLL != NULL) {
FreeLibrary(_hDLL);
_hDLL = NULL;
}
}
BOOL PDynaLink::IsLoaded() const
{
return _hDLL != NULL;
}
BOOL PDynaLink::GetFunction(PINDEX index, Function & func)
{
if (_hDLL == NULL)
return FALSE;
FARPROC p = GetProcAddress(_hDLL, (LPSTR)(DWORD)LOWORD(index));
if (p == NULL)
return FALSE;
func = (Function)p;
return TRUE;
}
BOOL PDynaLink::GetFunction(const PString & name, Function & func)
{
if (_hDLL == NULL)
return FALSE;
FARPROC p = GetProcAddress(_hDLL, name);
if (p == NULL)
return FALSE;
func = (Function)p;
return TRUE;
}
// End Of File ///////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -