Win32OperatingSystem.st
changeset 9100 0ebdc95e88ff
parent 9094 c4d084167915
child 9108 b67a03ebcf56
--- a/Win32OperatingSystem.st	Wed Feb 08 16:33:20 2006 +0100
+++ b/Win32OperatingSystem.st	Wed Feb 08 19:26:59 2006 +0100
@@ -28,6 +28,20 @@
 	privateIn:Win32OperatingSystem
 !
 
+OSHandle subclass:#Win32Handle
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	privateIn:Win32OperatingSystem
+!
+
+Win32OperatingSystem::Win32Handle subclass:#ITypeLib
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	privateIn:Win32OperatingSystem
+!
+
 Object subclass:#OSProcessStatus
 	instanceVariableNames:'pid status code core'
 	classVariableNames:''
@@ -44,14 +58,21 @@
 	privateIn:Win32OperatingSystem
 !
 
-OSFileHandle subclass:#Win32FILEHandle
+Object subclass:#TYPEATTR
 	instanceVariableNames:''
 	classVariableNames:''
 	poolDictionaries:''
 	privateIn:Win32OperatingSystem
 !
 
-OSFileHandle subclass:#Win32Handle
+Win32OperatingSystem::Win32Handle subclass:#ITypeInfo
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	privateIn:Win32OperatingSystem
+!
+
+OSHandle subclass:#Win32IOHandle
 	instanceVariableNames:''
 	classVariableNames:'Lobby'
 	poolDictionaries:''
@@ -65,35 +86,14 @@
 	privateIn:Win32OperatingSystem
 !
 
-Win32OperatingSystem::Win32Handle subclass:#Win32SerialPortHandle
-	instanceVariableNames:''
-	classVariableNames:''
-	poolDictionaries:''
-	privateIn:Win32OperatingSystem
-!
-
-Win32OperatingSystem::Win32Handle subclass:#Win32SocketHandle
+Win32OperatingSystem::Win32IOHandle subclass:#Win32SerialPortHandle
 	instanceVariableNames:''
 	classVariableNames:''
 	poolDictionaries:''
 	privateIn:Win32OperatingSystem
 !
 
-Win32OperatingSystem::Win32Handle subclass:#ITypeLib
-	instanceVariableNames:''
-	classVariableNames:''
-	poolDictionaries:''
-	privateIn:Win32OperatingSystem
-!
-
-Win32OperatingSystem::Win32Handle subclass:#ITypeInfo
-	instanceVariableNames:''
-	classVariableNames:''
-	poolDictionaries:''
-	privateIn:Win32OperatingSystem
-!
-
-Object subclass:#TYPEATTR
+Win32OperatingSystem::Win32IOHandle subclass:#Win32SocketHandle
 	instanceVariableNames:''
 	classVariableNames:''
 	poolDictionaries:''
@@ -5323,6 +5323,14 @@
     "Modified: 28.1.1998 / 14:27:18 / md"
 ! !
 
+!Win32OperatingSystem class methodsFor:'ole/com support'!
+
+iTypeLibAccessor
+    "provide access to the type library class"
+
+    ^ ITypeLib
+! !
+
 !Win32OperatingSystem class methodsFor:'os queries'!
 
 executableFileExtensions
@@ -6800,14 +6808,6 @@
     ^ Win32SerialPortHandle
 ! !
 
-!Win32OperatingSystem class methodsFor:'ole/com support'!
-
-iTypeLibAccessor
-    "provide access to the type library class"
-
-    ^ ITypeLib
-! !
-
 !Win32OperatingSystem class methodsFor:'socket support'!
 
 socketAccessor
@@ -8334,6 +8334,197 @@
     ^ type == #unknown
 ! !
 
+!Win32OperatingSystem::Win32Handle class methodsFor:'documentation'!
+
+documentation
+"
+    I represent a non-I/O HANDLE.
+"
+! !
+
+!Win32OperatingSystem::Win32Handle methodsFor:'release'!
+
+closeHandle
+    "close the handle"
+
+%{
+    HANDLE h = (HANDLE)(__externalAddressVal(self));
+
+    if (h) {
+        __externalAddressVal(self) = (HANDLE)0;
+        CloseHandle(h);
+    }
+%}.
+!
+
+finalize
+    "a filedescriptor was garbage collected - close the underlying handle"
+
+    self closeHandle
+! !
+
+!Win32OperatingSystem::ITypeLib class methodsFor:'instance creation'!
+
+loadTypeLib:pathName
+    |errorNumber newHandle|
+%{
+#ifdef WANT_OLE
+    if ( __isString(pathName) || __isUnicode16String(pathName)) {
+        OLECHAR __olePathNameBuffer[MAX_PATH+1];
+        OLECHAR *__olePathName;
+        ITypeLib *pTypeLib;
+        HRESULT rslt;
+
+        if (__isString(pathName)) {
+            char *__pathName = __stringVal(pathName);
+
+            /* convert to widechar */
+            {
+                int i = 0;
+                char *cp;
+
+                for (cp = __pathName; i<MAX_PATH; i++) {
+                    __olePathNameBuffer[i] = cp[i];
+                    if (cp[i] == 0) break;
+                }
+                __olePathName[MAX_PATH] = 0;
+            }
+            __olePathName = __olePathNameBuffer;
+        } else {
+            __olePathName = __unicode16StringVal(pathName);
+        }
+        rslt = LoadTypeLib(__olePathName, &pTypeLib);
+# ifdef OLE_DEBUG
+        fprintf(stderr, "rslt: 0x%x handle: %x\n", rslt, pTypeLib);
+        switch (rslt) {
+            case S_OK:
+                fprintf(stderr, "OK\n");
+                break;
+
+            case E_OUTOFMEMORY:
+                fprintf(stderr, "Out of memory\n");
+                break;
+
+            case E_INVALIDARG:
+                fprintf(stderr, "One or more arguments is invalid\n");
+                break;
+
+            case TYPE_E_IOERROR:
+                fprintf(stderr, "The function could not write to the file\n");
+                break;
+
+            case TYPE_E_INVALIDSTATE:
+                fprintf(stderr, "The type library could not be opened\n");
+                break;
+
+            case TYPE_E_INVDATAREAD:
+                fprintf(stderr, "The function could not read from the file\n");
+                break;
+
+            case TYPE_E_UNSUPFORMAT:
+                fprintf(stderr, "The type library has an older format\n");
+                break;
+
+            case TYPE_E_UNKNOWNLCID:
+                fprintf(stderr, "The LCID could not be found in the OLE-supported DLLs\n");
+                break;
+
+            case TYPE_E_CANTLOADLIBRARY:
+                fprintf(stderr, "The type library or DLL could not be loaded\n");
+                break;
+
+            default:
+                fprintf(stderr, "other error\n");
+                break;
+        }
+# endif /* OLE_DEBUG */
+        if (rslt == S_OK) {
+            if (pTypeLib) {
+                newHandle = __MKEXTERNALADDRESS(pTypeLib);
+                __qClass(newHandle) = self; __STORE(newHandle, self);
+            }
+        } else {
+            errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) );
+        }
+    }
+#endif /* WANT_OLE */
+%}.
+    newHandle notNil ifTrue:[
+        newHandle registerForFinalization.
+        ^ newHandle.
+    ].
+
+    errorNumber isNil ifTrue:[
+        self error:'invalid argument(s)'.
+    ] ifFalse:[
+        (OperatingSystem errorHolderForNumber:errorNumber) reportError
+    ].
+! !
+
+!Win32OperatingSystem::ITypeLib methodsFor:'accessing'!
+
+getTypeInfo:index
+    |errorNumber newHandle|
+%{
+#ifdef WANT_OLE
+    ITypeLib *pTypeLib = (ITypeLib *)(__externalAddressVal(self));
+
+    if (pTypeLib && __isSmallInteger(index)) {
+        int __index = __intVal(index);
+        if (__index >= 0) {
+            HRESULT rslt;
+            ITypeInfo *pTypeInfo;
+
+#ifdef DOES_NOT_WORK
+            rslt = ITypeLib_GetTypeInfo(pTypeLib, __index, &pTypeInfo);
+#else
+            rslt = pTypeLib->lpVtbl->GetTypeInfo(pTypeLib, __index, &pTypeInfo);
+#endif
+            if (rslt == S_OK) {
+                if (pTypeLib) {
+                    newHandle = __MKEXTERNALADDRESS(pTypeLib);
+                    __qClass(newHandle) = @global(Win32OperatingSystem::ITypeInfo);
+                    __STORE(newHandle, self);
+                }
+            } else {
+                errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) );
+            }
+        }
+    }
+#endif /* WANT_OLE */
+%}.
+    newHandle notNil ifTrue:[
+        newHandle registerForFinalization.
+        ^ newHandle.
+    ].
+
+    errorNumber isNil ifTrue:[
+        self error:'invalid argument(s)'.
+    ] ifFalse:[
+        (OperatingSystem errorHolderForNumber:errorNumber) reportError
+    ].
+!
+
+getTypeInfoCount
+%{
+#ifdef WANT_OLE
+    ITypeLib *pTypeLib = (ITypeLib *)(__externalAddressVal(self));
+
+    if (pTypeLib) {
+	int typeInfoCount;
+
+#ifdef DOES_NOT_WORK
+	typeInfoCount = ITypeLib_GetTypeInfoCount(pTypeLib);
+#else
+	typeInfoCount = pTypeLib->lpVtbl->GetTypeInfoCount(pTypeLib);
+#endif
+	return (__mkSmallInteger( typeInfoCount ));
+    }
+#endif /* WANT_OLE */
+%}.
+    self error:'invalid argument(s)'.
+! !
+
 !Win32OperatingSystem::OSProcessStatus class methodsFor:'documentation'!
 
 documentation
@@ -9567,57 +9758,116 @@
     "Created: / 19.5.1999 / 21:45:05 / cg"
 ! !
 
-!Win32OperatingSystem::Win32FILEHandle class methodsFor:'documentation'!
+!Win32OperatingSystem::ITypeInfo methodsFor:'accessing'!
+
+getDocumentation:memberID
+    |errorNumber ok name docString helpContext helpFile|
+%{
+#ifdef WANT_OLE
+    ITypeInfo *pTypeInfo = (ITypeInfo *)(__externalAddressVal(self));
+
+    if (pTypeInfo) {
+	HRESULT rslt;
+	TYPEATTR *pTypeAttr;
+	MEMBERID __memberID = (MEMBERID)-1;
+	BSTR __name;
+	BSTR __docString;
+	DWORD __helpContext;
+	BSTR __helpFile;
+
+	if (__isSmallInteger(memberID)) {
+	    __memberID = __intVal(memberID);
+	}
+
+#ifdef DOES_NOT_WORK
+	rslt = ITypeInfo_GetDocumentation(pTypeInfo, __memberID, &__name, &__docString, &__helpContext, &__helpFile);
+#else
+	rslt = pTypeInfo->lpVtbl->GetDocumentation(pTypeInfo, __memberID, &__name, &__docString, &__helpContext, &__helpFile);
+#endif
+	if (rslt == S_OK) {
+	    if (pTypeAttr) {
+		extern OBJ __MKU16STRING(short *);
+
+		name = __MKU16STRING(__name);
+		docString = __MKU16STRING(__docString);
+		helpFile = __MKU16STRING(__helpFile);
+		helpContext = __mkSmallInteger(__helpContext);
+		ok = true;
+	    }
+	} else {
+	    errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) );
+	}
+    }
+#endif /* WANT_OLE */
+%}.
+    ok == true ifTrue:[
+	^ Array with:name with:docString with:helpContext with:helpFile.
+    ].
+
+    errorNumber isNil ifTrue:[
+	self error:'invalid argument(s)'.
+    ] ifFalse:[
+	(OperatingSystem errorHolderForNumber:errorNumber) reportError
+    ].
+!
+
+getTypeAttr
+    |errorNumber newHandle|
+%{
+#ifdef WANT_OLE
+    ITypeInfo *pTypeInfo = (ITypeInfo *)(__externalAddressVal(self));
+
+    if (pTypeInfo) {
+        HRESULT rslt;
+        TYPEATTR *pTypeAttr;
+
+#ifdef DOES_NOT_WORK
+        rslt = ITypeInfo_GetTypeAttr(pTypeInfo, &pTypeAttr);
+#else
+        rslt = pTypeInfo->lpVtbl->GetTypeAttr(pTypeInfo, &pTypeAttr);
+#endif
+        if (rslt == S_OK) {
+            if (pTypeAttr) {
+                newHandle = __MKEXTERNALADDRESS(pTypeAttr);
+                __qClass(newHandle) = @global(Win32OperatingSystem::TYPEATTR);
+                __STORE(newHandle, self);
+            }
+        } else {
+            errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) );
+        }
+    }
+#endif /* WANT_OLE */
+%}.
+    newHandle notNil ifTrue:[
+        newHandle registerForFinalization.
+        ^ newHandle.
+    ].
+
+    errorNumber isNil ifTrue:[
+        self error:'invalid argument(s)'.
+    ] ifFalse:[
+        (OperatingSystem errorHolderForNumber:errorNumber) reportError
+    ].
+! !
+
+!Win32OperatingSystem::Win32IOHandle class methodsFor:'documentation'!
 
 documentation
 "
-    I represent a FILE*, as used in the stdio library.
-    Since most stdio libs are inherently buggy, thread-unsave
-    and hard to use in a multithreading environment,
-    these will no longer be used in future ST/X versions.
-    However, they may be useful when interfacing to external
-    libraries...
+    I represent a handle on which I/O is possible.
+    Typical instances are File-Handles, Socket-Handles etc.
 "
-!
-
-version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.196 2006-02-08 12:11:34 cg Exp $'
 ! !
 
-!Win32OperatingSystem::Win32FILEHandle methodsFor:'release'!
-
-closeFile
-    "close the file"
-
-%{
-    FILE *f = (FILE *)(__externalAddressVal(self));
-
-    if (f) {
-	__externalAddressVal(self) = NULL;
-	fclose(f);
-    }
-%}.
+!Win32OperatingSystem::Win32IOHandle methodsFor:'finalization'!
+
+finalize
+    "a handle was garbage collected - close the underlying file"
+
+    self closeFile
 ! !
 
-!Win32OperatingSystem::Win32Handle class methodsFor:'documentation'!
-
-documentation
-"
-    I represent a generic HANDLE, which can be closed via CloseHandle.
-"
-!
-
-version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.196 2006-02-08 12:11:34 cg Exp $'
-! !
-
-!Win32OperatingSystem::Win32Handle class methodsFor:'initialization'!
-
-initialize
-    Lobby := Registry new.
-! !
-
-!Win32OperatingSystem::Win32Handle methodsFor:'io'!
+!Win32OperatingSystem::Win32IOHandle methodsFor:'io'!
 
 readBytes:count into:aByteBuffer startingAt:firstIndex
     "read count bytes into a byte-buffer;
@@ -9637,88 +9887,88 @@
     BOOL ok;
 
     if ((hFile == 0) || (hFile == INVALID_HANDLE_VALUE)) {
-	errSym = @symbol(errorNotOpen);
-	goto bad;
+        errSym = @symbol(errorNotOpen);
+        goto bad;
     }
     if (! __bothSmallInteger(count, firstIndex)) {
-	errSym = @symbol(badArgument);
-	goto bad;
+        errSym = @symbol(badArgument);
+        goto bad;
     }
     cntWanted = __smallIntegerVal(count);
     if (cntWanted <= 0) {
-	errSym = @symbol(badCount);
-	goto bad;
+        errSym = @symbol(badCount);
+        goto bad;
     }
     offs = __smallIntegerVal(firstIndex) - 1;
     if (offs < 0) {
-	errSym = @symbol(badOffset);
-	goto bad;
+        errSym = @symbol(badOffset);
+        goto bad;
     }
 
     bufferIsExternalBytes = __isExternalBytesLike(aByteBuffer);
     if (! bufferIsExternalBytes) {
-	if (__isByteArray(aByteBuffer)) {
-	    bufferSize = __byteArraySize(aByteBuffer);
-	} else if (__isString(aByteBuffer)) {
-	    bufferSize = __stringSize(aByteBuffer);
-	} else {
-	    errSym = @symbol(badBuffer);
-	    goto bad;
-	}
-	if (bufferSize < (cntWanted + offs)) {
-	    errSym = @symbol(badBufferSize);
-	    goto bad;
-	}
-	if (cntWanted <= sizeof(miniBuffer)) {
-	    extPtr = miniBuffer;
-	} else {
-	    extPtr = malloc(cntWanted);
-	    mustFreeBuffer = 1;
-	}
+        if (__isByteArray(aByteBuffer)) {
+            bufferSize = __byteArraySize(aByteBuffer);
+        } else if (__isString(aByteBuffer)) {
+            bufferSize = __stringSize(aByteBuffer);
+        } else {
+            errSym = @symbol(badBuffer);
+            goto bad;
+        }
+        if (bufferSize < (cntWanted + offs)) {
+            errSym = @symbol(badBufferSize);
+            goto bad;
+        }
+        if (cntWanted <= sizeof(miniBuffer)) {
+            extPtr = miniBuffer;
+        } else {
+            extPtr = malloc(cntWanted);
+            mustFreeBuffer = 1;
+        }
     } else {
-	OBJ sz;
-
-	extPtr = (char *)(__externalBytesAddress(aByteBuffer));
-	sz = __externalBytesSize(aByteBuffer);
-	if (! __isSmallInteger(sz)) {
-	    errSym = @symbol(badBufferSize);
-	    goto bad;
-	}
-	bufferSize = __smallIntegerVal(sz);
-	if (bufferSize < (cntWanted + offs)) {
-	    errSym = @symbol(badBufferSize);
-	    goto bad;
-	}
-	extPtr = extPtr + offs;
+        OBJ sz;
+
+        extPtr = (char *)(__externalBytesAddress(aByteBuffer));
+        sz = __externalBytesSize(aByteBuffer);
+        if (! __isSmallInteger(sz)) {
+            errSym = @symbol(badBufferSize);
+            goto bad;
+        }
+        bufferSize = __smallIntegerVal(sz);
+        if (bufferSize < (cntWanted + offs)) {
+            errSym = @symbol(badBufferSize);
+            goto bad;
+        }
+        extPtr = extPtr + offs;
     }
 
     do {
-	__threadErrno = 0;
-	ok = STX_API_CALL5( "ReadFile", ReadFile, hFile, extPtr, cntWanted, &cntRead, 0 /* lpOverlapped */);
+        __threadErrno = 0;
+        ok = STX_API_CALL5( "ReadFile", ReadFile, hFile, extPtr, cntWanted, &cntRead, 0 /* lpOverlapped */);
     } while(__threadErrno == EINTR);
 
     if (ok == TRUE) {
-	if (! bufferIsExternalBytes) {
-	    /* copy over */
-	    memcpy(__byteArrayVal(aByteBuffer)+offs, extPtr, cntRead);
-	    if (mustFreeBuffer) {
-		free(extPtr);
-	    }
-	}
-	RETURN (__mkSmallInteger(cntRead));
+        if (! bufferIsExternalBytes) {
+            /* copy over */
+            memcpy(__byteArrayVal(aByteBuffer)+offs, extPtr, cntRead);
+            if (mustFreeBuffer) {
+                free(extPtr);
+            }
+        }
+        RETURN (__mkSmallInteger(cntRead));
     }
     errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) );
 
 bad: ;
     if (mustFreeBuffer) {
-	free(extPtr);
+        free(extPtr);
     }
 %}.
 
     errorNumber isNil ifTrue:[
-	self error:'invalid argument(s): ', errSym.
+        self error:'invalid argument(s): ', errSym.
     ] ifFalse:[
-	(OperatingSystem errorHolderForNumber:errorNumber) reportError
+        (OperatingSystem errorHolderForNumber:errorNumber) reportError
     ].
 
     "
@@ -9727,7 +9977,7 @@
      h := self basicNew.
      buff := ByteArray new:10.
      n := h readBytes:10 into:buff startingAt:1.
-     Transcript show:n; space; showCR:buff.
+     Transcript show:n; show:' '; showCR:buff.
     "
 !
 
@@ -9969,13 +10219,14 @@
     "
 ! !
 
-!Win32OperatingSystem::Win32Handle methodsFor:'queries'!
-
-isValid
-     ^ self address ~~0
-! !
-
-!Win32OperatingSystem::Win32Handle methodsFor:'release'!
+!Win32OperatingSystem::Win32IOHandle methodsFor:'release'!
+
+close
+    "close the file"
+
+    self closeFile.
+    self unregisterForFinalization.
+!
 
 closeFile
     "close the handle"
@@ -9984,8 +10235,8 @@
     HANDLE h = (HANDLE)(__externalAddressVal(self));
 
     if (h) {
-	__externalAddressVal(self) = (HANDLE)0;
-	CloseHandle(h);
+        __externalAddressVal(self) = (HANDLE)0;
+        CloseHandle(h);
     }
 %}.
 ! !
@@ -9996,120 +10247,6 @@
     ^ pid
 ! !
 
-!Win32OperatingSystem::Win32SerialPortHandle methodsFor:'setup'!
-
-baudRate:newRate
-%{
-    HANDLE port = (HANDLE)(__externalAddressVal(self));
-
-    if (port
-     && __isSmallInteger(newRate)) {
-	DCB dcb;
-
-	ZeroMemory(&dcb, sizeof(dcb));
-	dcb.DCBlength = sizeof(dcb);
-	GetCommState(port, &dcb);
-
-	dcb.BaudRate = __intVal(newRate);
-
-	if (! SetCommState(port, &dcb)) {
-	    RETURN(false);
-	}
-	RETURN(true);
-    }
-%}.
-    self primitiveFailed.
-!
-
-dataBits:newNumberOfBits
-%{
-    HANDLE port = (HANDLE)(__externalAddressVal(self));
-
-    if (port
-     && __isSmallInteger(newNumberOfBits)) {
-	DCB dcb;
-
-	ZeroMemory(&dcb, sizeof(dcb));
-	dcb.DCBlength = sizeof(dcb);
-	GetCommState(port, &dcb);
-
-	dcb.ByteSize = __intVal(newNumberOfBits);
-
-	if (! SetCommState(port, &dcb)) {
-	    RETURN(false);
-	}
-	RETURN(true);
-    }
-%}.
-    self primitiveFailed.
-!
-
-stopBitsType:newStopBitsSymbol
-    "newParityTypeSymbol must be one of #stop1, #stop2 or #stop1_5"
-%{
-    HANDLE port = (HANDLE)(__externalAddressVal(self));
-
-    if (port) {
-	DCB dcb;
-
-	ZeroMemory(&dcb, sizeof(dcb));
-	dcb.DCBlength = sizeof(dcb);
-	GetCommState(port, &dcb);
-
-	if (newStopBitsSymbol == @symbol(stop1)) {
-	    dcb.Parity = 0 /* STOP1 */;
-	} else if (newStopBitsSymbol == @symbol(stop2)) {
-	    dcb.Parity = 2 /* STOP2 */;
-	} else if (newStopBitsSymbol == @symbol(stop1_5)) {
-	    dcb.Parity = 1 /* STOP1_5 */;
-	} else {
-	    goto failure;
-	}
-
-	if (! SetCommState(port, &dcb)) {
-	    RETURN(false);
-	}
-	RETURN(true);
-    }
-  failure: ;
-%}.
-    self primitiveFailed.
-!
-
-parityType:newParityTypeSymbol
-    "newParityTypeSymbol must be one of #odd, #even or #none (or nil)"
-
-%{
-    HANDLE port = (HANDLE)(__externalAddressVal(self));
-
-    if (port) {
-	DCB dcb;
-
-	ZeroMemory(&dcb, sizeof(dcb));
-	dcb.DCBlength = sizeof(dcb);
-	GetCommState(port, &dcb);
-
-
-	if ((newParityTypeSymbol == nil) || (newParityTypeSymbol == @symbol(none))) {
-	    dcb.Parity = NOPARITY;
-	} else if (newParityTypeSymbol == @symbol(odd)) {
-	    dcb.Parity = ODDPARITY;
-	} else if (newParityTypeSymbol == @symbol(even)) {
-	    dcb.Parity = EVENPARITY;
-	} else {
-	    goto failure;
-	}
-
-	if (! SetCommState(port, &dcb)) {
-	    RETURN(false);
-	}
-	RETURN(true);
-    }
-  failure: ;
-%}.
-    self primitiveFailed.
-! !
-
 !Win32OperatingSystem::Win32SerialPortHandle methodsFor:'opening'!
 
 open:portName baudRate:baudRate stopBitsType:stopBitsType
@@ -10342,258 +10479,118 @@
 %}.
 ! !
 
-!Win32OperatingSystem::ITypeLib class methodsFor:'instance creation'!
-
-loadTypeLib:pathName
-    |errorNumber newHandle|
+!Win32OperatingSystem::Win32SerialPortHandle methodsFor:'setup'!
+
+baudRate:newRate
 %{
-#ifdef WANT_OLE
-    if ( __isString(pathName) || __isUnicode16String(pathName)) {
-	OLECHAR __olePathNameBuffer[MAX_PATH+1];
-	OLECHAR *__olePathName;
-	ITypeLib *pTypeLib;
-	HRESULT rslt;
-
-	if (__isString(pathName)) {
-	    char *__pathName = __stringVal(pathName);
-
-	    /* convert to widechar */
-	    {
-		int i = 0;
-		char *cp;
-
-		for (cp = __pathName; i<MAX_PATH; i++) {
-		    __olePathNameBuffer[i] = cp[i];
-		    if (cp[i] == 0) break;
-		}
-		__olePathName[MAX_PATH] = 0;
-	    }
-	    __olePathName = __olePathNameBuffer;
-	} else {
-	    __olePathName = __unicode16StringVal(pathName);
-	}
-	rslt = LoadTypeLib(__olePathName, &pTypeLib);
-# ifdef OLE_DEBUG
-	fprintf(stderr, "rslt: 0x%x handle: %x\n", rslt, pTypeLib);
-	switch (rslt) {
-	    case S_OK:
-		fprintf(stderr, "OK\n");
-		break;
-
-	    case E_OUTOFMEMORY:
-		fprintf(stderr, "Out of memory\n");
-		break;
-
-	    case E_INVALIDARG:
-		fprintf(stderr, "One or more arguments is invalid\n");
-		break;
-
-	    case TYPE_E_IOERROR:
-		fprintf(stderr, "The function could not write to the file\n");
-		break;
-
-	    case TYPE_E_INVALIDSTATE:
-		fprintf(stderr, "The type library could not be opened\n");
-		break;
-
-	    case TYPE_E_INVDATAREAD:
-		fprintf(stderr, "The function could not read from the file\n");
-		break;
-
-	    case TYPE_E_UNSUPFORMAT:
-		fprintf(stderr, "The type library has an older format\n");
-		break;
-
-	    case TYPE_E_UNKNOWNLCID:
-		fprintf(stderr, "The LCID could not be found in the OLE-supported DLLs\n");
-		break;
-
-	    case TYPE_E_CANTLOADLIBRARY:
-		fprintf(stderr, "The type library or DLL could not be loaded\n");
-		break;
-
-	    default:
-		fprintf(stderr, "other error\n");
-		break;
-	}
-# endif /* OLE_DEBUG */
-	if (rslt == S_OK) {
-	    if (pTypeLib) {
-		newHandle = __MKEXTERNALADDRESS(pTypeLib);
-		__qClass(newHandle) = self; __STORE(newHandle, self);
-	    }
-	} else {
-	    errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) );
-	}
-    }
-#endif /* WANT_OLE */
+    HANDLE port = (HANDLE)(__externalAddressVal(self));
+
+    if (port
+     && __isSmallInteger(newRate)) {
+	DCB dcb;
+
+	ZeroMemory(&dcb, sizeof(dcb));
+	dcb.DCBlength = sizeof(dcb);
+	GetCommState(port, &dcb);
+
+	dcb.BaudRate = __intVal(newRate);
+
+	if (! SetCommState(port, &dcb)) {
+	    RETURN(false);
+	}
+	RETURN(true);
+    }
 %}.
-    newHandle notNil ifTrue:[
-	Lobby register:newHandle.
-	^ newHandle.
-    ].
-
-    errorNumber isNil ifTrue:[
-	self error:'invalid argument(s)'.
-    ] ifFalse:[
-	(OperatingSystem errorHolderForNumber:errorNumber) reportError
-    ].
-! !
-
-!Win32OperatingSystem::ITypeLib methodsFor:'accessing'!
-
-getTypeInfoCount
+    self primitiveFailed.
+!
+
+dataBits:newNumberOfBits
 %{
-#ifdef WANT_OLE
-    ITypeLib *pTypeLib = (ITypeLib *)(__externalAddressVal(self));
-
-    if (pTypeLib) {
-	int typeInfoCount;
-
-#ifdef DOES_NOT_WORK
-	typeInfoCount = ITypeLib_GetTypeInfoCount(pTypeLib);
-#else
-	typeInfoCount = pTypeLib->lpVtbl->GetTypeInfoCount(pTypeLib);
-#endif
-	return (__mkSmallInteger( typeInfoCount ));
-    }
-#endif /* WANT_OLE */
+    HANDLE port = (HANDLE)(__externalAddressVal(self));
+
+    if (port
+     && __isSmallInteger(newNumberOfBits)) {
+	DCB dcb;
+
+	ZeroMemory(&dcb, sizeof(dcb));
+	dcb.DCBlength = sizeof(dcb);
+	GetCommState(port, &dcb);
+
+	dcb.ByteSize = __intVal(newNumberOfBits);
+
+	if (! SetCommState(port, &dcb)) {
+	    RETURN(false);
+	}
+	RETURN(true);
+    }
 %}.
-    self error:'invalid argument(s)'.
-!
-
-getTypeInfo:index
-    |errorNumber newHandle|
+    self primitiveFailed.
+!
+
+parityType:newParityTypeSymbol
+    "newParityTypeSymbol must be one of #odd, #even or #none (or nil)"
+
 %{
-#ifdef WANT_OLE
-    ITypeLib *pTypeLib = (ITypeLib *)(__externalAddressVal(self));
-
-    if (pTypeLib && __isSmallInteger(index)) {
-	int __index = __intVal(index);
-	if (__index >= 0) {
-	    HRESULT rslt;
-	    ITypeInfo *pTypeInfo;
-
-#ifdef DOES_NOT_WORK
-	    rslt = ITypeLib_GetTypeInfo(pTypeLib, __index, &pTypeInfo);
-#else
-	    rslt = pTypeLib->lpVtbl->GetTypeInfo(pTypeLib, __index, &pTypeInfo);
-#endif
-	    if (rslt == S_OK) {
-		if (pTypeLib) {
-		    newHandle = __MKEXTERNALADDRESS(pTypeLib);
-		    __qClass(newHandle) = @global(Win32OperatingSystem::ITypeInfo);
-		    __STORE(newHandle, self);
-		}
-	    } else {
-		errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) );
-	    }
-	}
-    }
-#endif /* WANT_OLE */
-%}.
-    newHandle notNil ifTrue:[
-	Lobby register:newHandle.
-	^ newHandle.
-    ].
-
-    errorNumber isNil ifTrue:[
-	self error:'invalid argument(s)'.
-    ] ifFalse:[
-	(OperatingSystem errorHolderForNumber:errorNumber) reportError
-    ].
-! !
-
-!Win32OperatingSystem::ITypeInfo methodsFor:'accessing'!
-
-getTypeAttr
-    |errorNumber newHandle|
-%{
-#ifdef WANT_OLE
-    ITypeInfo *pTypeInfo = (ITypeInfo *)(__externalAddressVal(self));
-
-    if (pTypeInfo) {
-	HRESULT rslt;
-	TYPEATTR *pTypeAttr;
-
-#ifdef DOES_NOT_WORK
-	rslt = ITypeInfo_GetTypeAttr(pTypeInfo, &pTypeAttr);
-#else
-	rslt = pTypeInfo->lpVtbl->GetTypeAttr(pTypeInfo, &pTypeAttr);
-#endif
-	if (rslt == S_OK) {
-	    if (pTypeAttr) {
-		newHandle = __MKEXTERNALADDRESS(pTypeAttr);
-		__qClass(newHandle) = @global(Win32OperatingSystem::TYPEATTR);
-		__STORE(newHandle, self);
-	    }
+    HANDLE port = (HANDLE)(__externalAddressVal(self));
+
+    if (port) {
+	DCB dcb;
+
+	ZeroMemory(&dcb, sizeof(dcb));
+	dcb.DCBlength = sizeof(dcb);
+	GetCommState(port, &dcb);
+
+
+	if ((newParityTypeSymbol == nil) || (newParityTypeSymbol == @symbol(none))) {
+	    dcb.Parity = NOPARITY;
+	} else if (newParityTypeSymbol == @symbol(odd)) {
+	    dcb.Parity = ODDPARITY;
+	} else if (newParityTypeSymbol == @symbol(even)) {
+	    dcb.Parity = EVENPARITY;
 	} else {
-	    errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) );
-	}
-    }
-#endif /* WANT_OLE */
+	    goto failure;
+	}
+
+	if (! SetCommState(port, &dcb)) {
+	    RETURN(false);
+	}
+	RETURN(true);
+    }
+  failure: ;
 %}.
-    newHandle notNil ifTrue:[
-	Lobby register:newHandle.
-	^ newHandle.
-    ].
-
-    errorNumber isNil ifTrue:[
-	self error:'invalid argument(s)'.
-    ] ifFalse:[
-	(OperatingSystem errorHolderForNumber:errorNumber) reportError
-    ].
-!
-
-getDocumentation:memberID
-    |errorNumber ok name docString helpContext helpFile|
+    self primitiveFailed.
+!
+
+stopBitsType:newStopBitsSymbol
+    "newParityTypeSymbol must be one of #stop1, #stop2 or #stop1_5"
 %{
-#ifdef WANT_OLE
-    ITypeInfo *pTypeInfo = (ITypeInfo *)(__externalAddressVal(self));
-
-    if (pTypeInfo) {
-	HRESULT rslt;
-	TYPEATTR *pTypeAttr;
-	MEMBERID __memberID = (MEMBERID)-1;
-	BSTR __name;
-	BSTR __docString;
-	DWORD __helpContext;
-	BSTR __helpFile;
-
-	if (__isSmallInteger(memberID)) {
-	    __memberID = __intVal(memberID);
-	}
-
-#ifdef DOES_NOT_WORK
-	rslt = ITypeInfo_GetDocumentation(pTypeInfo, __memberID, &__name, &__docString, &__helpContext, &__helpFile);
-#else
-	rslt = pTypeInfo->lpVtbl->GetDocumentation(pTypeInfo, __memberID, &__name, &__docString, &__helpContext, &__helpFile);
-#endif
-	if (rslt == S_OK) {
-	    if (pTypeAttr) {
-		extern OBJ __MKU16STRING(short *);
-
-		name = __MKU16STRING(__name);
-		docString = __MKU16STRING(__docString);
-		helpFile = __MKU16STRING(__helpFile);
-		helpContext = __mkSmallInteger(__helpContext);
-		ok = true;
-	    }
+    HANDLE port = (HANDLE)(__externalAddressVal(self));
+
+    if (port) {
+	DCB dcb;
+
+	ZeroMemory(&dcb, sizeof(dcb));
+	dcb.DCBlength = sizeof(dcb);
+	GetCommState(port, &dcb);
+
+	if (newStopBitsSymbol == @symbol(stop1)) {
+	    dcb.Parity = 0 /* STOP1 */;
+	} else if (newStopBitsSymbol == @symbol(stop2)) {
+	    dcb.Parity = 2 /* STOP2 */;
+	} else if (newStopBitsSymbol == @symbol(stop1_5)) {
+	    dcb.Parity = 1 /* STOP1_5 */;
 	} else {
-	    errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) );
-	}
-    }
-#endif /* WANT_OLE */
+	    goto failure;
+	}
+
+	if (! SetCommState(port, &dcb)) {
+	    RETURN(false);
+	}
+	RETURN(true);
+    }
+  failure: ;
 %}.
-    ok == true ifTrue:[
-	^ Array with:name with:docString with:helpContext with:helpFile.
-    ].
-
-    errorNumber isNil ifTrue:[
-	self error:'invalid argument(s)'.
-    ] ifFalse:[
-	(OperatingSystem errorHolderForNumber:errorNumber) reportError
-    ].
+    self primitiveFailed.
 ! !
 
 !Win32OperatingSystem::Win32SocketHandle class methodsFor:'constants'!
@@ -11234,7 +11231,7 @@
 !Win32OperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.196 2006-02-08 12:11:34 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.197 2006-02-08 18:26:59 cg Exp $'
 ! !
 
 Win32OperatingSystem initialize!