From 8c8a42af369d421dbcea23ea68c633b82dde8794 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Wed, 4 Mar 2026 17:33:52 -0600 Subject: [PATCH] Removed unused files. --- drivers/CYBERCOM.DRV | 3 - drivers/CYBERCOM.TXT | 101 ---- vbx/kpcomctl.bmp | 3 - vbx/kpcomctl.c | 1104 ------------------------------------------ vbx/kpcomctl.def | 16 - vbx/kpcomctl.h | 145 ------ vbx/kpcomctl.rc | 36 -- vbx/makefile | 81 ---- vbx/serial.c | 253 ---------- vbx/serial.h | 110 ----- vbx/vbapi.def | 29 -- vbx/vbapi.h | 290 ----------- 12 files changed, 2171 deletions(-) delete mode 100644 drivers/CYBERCOM.DRV delete mode 100644 drivers/CYBERCOM.TXT delete mode 100644 vbx/kpcomctl.bmp delete mode 100644 vbx/kpcomctl.c delete mode 100644 vbx/kpcomctl.def delete mode 100644 vbx/kpcomctl.h delete mode 100644 vbx/kpcomctl.rc delete mode 100644 vbx/makefile delete mode 100644 vbx/serial.c delete mode 100644 vbx/serial.h delete mode 100644 vbx/vbapi.def delete mode 100644 vbx/vbapi.h diff --git a/drivers/CYBERCOM.DRV b/drivers/CYBERCOM.DRV deleted file mode 100644 index 87b3b4a..0000000 --- a/drivers/CYBERCOM.DRV +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:168792609a46054b46247941eda877d51c728f4e3d1439be180eb20ae2b888db -size 9264 diff --git a/drivers/CYBERCOM.TXT b/drivers/CYBERCOM.TXT deleted file mode 100644 index e586edc..0000000 --- a/drivers/CYBERCOM.TXT +++ /dev/null @@ -1,101 +0,0 @@ -CyberCom V1.1.0.0P - -CYBERCOM.DRV 9264 11-26-93 1:06p - -The High Speed Serial Communications Driver for Windows 3.1 -Designed for 386 (and above) systems using the 16550 serial port -chip. (C) CyberSoft Corp 1993 - -Requires Windows 3.1, Enhanced Mode, a 16550 UART - - -INTRODUCTION. -------------- -CyberCom is a direct replacement for the standard Windows -Communications Driver (COMM.DRV). - -* Transfer at up to 115,200 KB with a 16550 serial port chip -* Great for V.FAST and Voice modems that require 57,600 Kb -* More reliable Transfer with less overhead on your system - Better - background operation. -* Fewer (if any) over/under runs. - - -HOW DOES IT WORK? ------------------ -Don't worry if the following sounds too complicated - just skip over -it and move on to the Installation... - -* CyberCom enables the FIFO buffer on the 16550 to be enabled for both -receive AND transmit - COMM.DRV only enables the FIFO for receive. - -* The 'interrupt trigger level' has been set to 8 for both transmit and -receive. This gives your applications a lot more time to process -incoming information. COMM.DRV sets the trigger level to 14 which -means that your application only has 2 characters in which read from -the FIFO buffer. - -What this means is that your communications applications will get far -fewer (if any) 'under runs' or 'over runs' when sending or receiving. - - -INSTALLATION ------------- -1. Copy CYBERCOM.DRV into your Windows\System directory. - -Edit the Windows\SYSTEM.INI file and change the following line: - -From comm.drv=comm.drv -To comm.drv=cybercom.drv - -2. If you previously have not taken advantage of the 16550 installed -in your computer then ensure that the Windows\SYSTEM.INI file has the -following information: - -[386Enh] -COMnFIFO=1 - -where n is the number of the COM port. - -if your 16550 is installed on, say, COM 1 then - -[386Enh] -COM1FIFO=1 - -3. Start or Restart windows. - - -LICENCE -------- -CyberCom is provided free for non-commercial use. - -You may not distribute CyberCom for profit. If you wish to include -CyberCom with your applications then contact CyberSoft at the address -below for details about royalty-free licences. - ----------------------------------------------------------------------- -For further information, upgrades, problems etc please contact us at: - -Attention: Douglas I. Scadlock -CyberSoft Corporation Pty Ltd, -PO BOX 407 Vaucluse, -New South Wales -2030 Australia -Phone +61 2 805 1077 -Fax +61 2 805 0897 -CIS 100033,1723 - - -CAVEAT ------- -THE INFORMATION AND COMMUNICATIONS DRIVER PROVIDED HEREUNDER -(COLLECTIVELY REFERRED TO AS "SOFTWARE") IS PROVIDED AS IS WITHOUT -WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT -LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE. - -(C) CyberSoft Corp 1993 -(C) Microsoft Corp - -********************************************************************** - Sydney 2000 - Home of the Millennium Games diff --git a/vbx/kpcomctl.bmp b/vbx/kpcomctl.bmp deleted file mode 100644 index 303e6fd..0000000 --- a/vbx/kpcomctl.bmp +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:c876f98c830c8c3e17bba2418a421699b77f391507583406e74058071e067b46 -size 174 diff --git a/vbx/kpcomctl.c b/vbx/kpcomctl.c deleted file mode 100644 index 66862de..0000000 --- a/vbx/kpcomctl.c +++ /dev/null @@ -1,1104 +0,0 @@ -// kpcomctl.c - KPComCtl VBX control implementation -// -// Provides high-speed serial communications for 16-bit Visual Basic 4. -// Implements MODEL, control procedure, property/event handling, and -// WM_COMMNOTIFY dispatch via hidden notification windows. -// -// IMPORTANT: VBDerefControl() returns a pointer into VB's compacting heap. -// Any VB API call (VBCreateHsz, VBDestroyHsz, VBFireEvent, etc.) can -// trigger heap compaction and invalidate the pointer. All code must -// re-deref after such calls before accessing control data again. - -#include -#include -#include "vbapi.h" -#include "serial.h" -#include "kpcomctl.h" - -// ----------------------------------------------------------------------- -// Debug logging via OutputDebugString -// ----------------------------------------------------------------------- -#define DBG_ENABLED 1 - -#if DBG_ENABLED -static void dbgStr(const char FAR *msg) -{ - OutputDebugString(msg); -} - -// Log a label and a 16-bit hex value: "label: 0xNNNN\r\n" -static void dbgHex16(const char FAR *label, uint16_t val) -{ - static const char hex[] = "0123456789ABCDEF"; - char buf[48]; - int i; - - for (i = 0; i < 40 && label[i]; i++) { - buf[i] = label[i]; - } - buf[i++] = ':'; - buf[i++] = ' '; - buf[i++] = '0'; - buf[i++] = 'x'; - buf[i++] = hex[(val >> 12) & 0xF]; - buf[i++] = hex[(val >> 8) & 0xF]; - buf[i++] = hex[(val >> 4) & 0xF]; - buf[i++] = hex[val & 0xF]; - buf[i++] = '\r'; - buf[i++] = '\n'; - buf[i] = '\0'; - OutputDebugString(buf); -} - -// Log a label and a signed 16-bit value: "label: -NNNN\r\n" -static void dbgInt16(const char FAR *label, int16_t val) -{ - char buf[48]; - int i; - uint16_t uv; - - for (i = 0; i < 40 && label[i]; i++) { - buf[i] = label[i]; - } - buf[i++] = ':'; - buf[i++] = ' '; - - if (val < 0) { - buf[i++] = '-'; - uv = (uint16_t)(-(int)val); - } else { - uv = (uint16_t)val; - } - - // Print decimal (up to 5 digits) - { - char digits[6]; - int n = 0; - do { - digits[n++] = (char)('0' + (uv % 10)); - uv /= 10; - } while (uv > 0); - while (n > 0) { - buf[i++] = digits[--n]; - } - } - - buf[i++] = '\r'; - buf[i++] = '\n'; - buf[i] = '\0'; - OutputDebugString(buf); -} -#else -#define dbgStr(msg) ((void)0) -#define dbgHex16(label, val) ((void)0) -#define dbgInt16(label, val) ((void)0) -#endif - -// ----------------------------------------------------------------------- -// Global data -// ----------------------------------------------------------------------- -HANDLE ghInstance = NULL; -static BOOL gModelInfoCalled = FALSE; - -// ----------------------------------------------------------------------- -// Convenience macro for re-dereferencing control data after VB API calls -// ----------------------------------------------------------------------- -#define DEREF(hctl) ((KpComCtlDataT FAR *)VBDerefControl(hctl)) - -// ----------------------------------------------------------------------- -// Forward declarations - Control procedure -// ----------------------------------------------------------------------- -LONG FAR PASCAL _export KpComCtlProc(HCTL hctl, HWND hwnd, USHORT msg, USHORT wp, LONG lp); -LRESULT FAR PASCAL _export NotifyWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp); - -// ----------------------------------------------------------------------- -// Forward declarations - Internal functions (alphabetical) -// ----------------------------------------------------------------------- -static void closePort(HCTL hctl, KpComCtlDataT FAR *pData); -static void fireOnComm(HCTL hctl, KpComCtlDataT FAR *pData, int16_t eventCode); -static LONG handleGetProperty(HCTL hctl, KpComCtlDataT FAR *pData, USHORT iProp); -static LONG handleSetProperty(HCTL hctl, KpComCtlDataT FAR *pData, USHORT iProp, LONG lp); -static void initControlData(HCTL hctl); -static int16_t openPort(HCTL hctl, KpComCtlDataT FAR *pData); -static void processEventNotify(HCTL hctl, int16_t commId); -static void processReceiveNotify(HCTL hctl, int16_t commId); -static void processTransmitNotify(HCTL hctl, int16_t commId); -static BOOL registerNotifyClass(HANDLE hInstance); - -// ----------------------------------------------------------------------- -// Forward declarations - DLL entry points -// ----------------------------------------------------------------------- -int FAR PASCAL LibMain(HANDLE hInstance, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine); -BOOL FAR PASCAL _export VBINITCC(USHORT usVersion, BOOL fRuntime); -void FAR PASCAL _export VBTERMCC(void); -LPMODELINFO FAR PASCAL _export VBGetModelInfo(USHORT usVersion); -void FAR PASCAL _export WEP(int nParam); - -// ----------------------------------------------------------------------- -// Enum value lists (null-separated, double-null terminated by compiler) -// ----------------------------------------------------------------------- -static char szHandshaking[] = "None\0XonXoff\0RtsCts\0Both"; -static char szInputMode[] = "Text\0Binary"; - -// ----------------------------------------------------------------------- -// Property descriptors -// ----------------------------------------------------------------------- -// offset default enum list enumMax -static PROPINFO propCommPort = { "CommPort", PF_fSetMsg | PF_fGetData | DT_SHORT, OFFSETIN(KpComCtlDataT, commPort), 0, 1L, NULL, 0 }; -static PROPINFO propSettings = { "Settings", PF_fSetMsg | PF_fGetMsg | DT_HSZ, 0, 0, 0L, NULL, 0 }; -static PROPINFO propPortOpen = { "PortOpen", PF_fSetMsg | PF_fGetData | DT_BOOL, OFFSETIN(KpComCtlDataT, portOpen), 0, 0L, NULL, 0 }; -static PROPINFO propInput = { "Input", PF_fGetMsg | PF_fNoShow | DT_HSZ, 0, 0, 0L, NULL, 0 }; -static PROPINFO propOutput = { "Output", PF_fSetMsg | PF_fNoShow | DT_HSZ, 0, 0, 0L, NULL, 0 }; -static PROPINFO propInBufferSize = { "InBufferSize", PF_fSetMsg | PF_fGetData | DT_SHORT, OFFSETIN(KpComCtlDataT, inBufferSize), 0, 4096L, NULL, 0 }; -static PROPINFO propOutBufferSize = { "OutBufferSize", PF_fSetMsg | PF_fGetData | DT_SHORT, OFFSETIN(KpComCtlDataT, outBufferSize), 0, 4096L, NULL, 0 }; -static PROPINFO propInBufferCount = { "InBufferCount", PF_fGetMsg | PF_fNoShow | DT_SHORT, 0, 0, 0L, NULL, 0 }; -static PROPINFO propOutBufferCount= { "OutBufferCount",PF_fGetMsg | PF_fNoShow | DT_SHORT, 0, 0, 0L, NULL, 0 }; -static PROPINFO propRThreshold = { "RThreshold", PF_fSetData| PF_fGetData | DT_SHORT, OFFSETIN(KpComCtlDataT, rThreshold), 0, 0L, NULL, 0 }; -static PROPINFO propSThreshold = { "SThreshold", PF_fSetData| PF_fGetData | DT_SHORT, OFFSETIN(KpComCtlDataT, sThreshold), 0, 0L, NULL, 0 }; -static PROPINFO propHandshaking = { "Handshaking", PF_fSetMsg | PF_fGetData | DT_ENUM, OFFSETIN(KpComCtlDataT, handshaking), 0, 0L, szHandshaking, 3 }; -static PROPINFO propInputLen = { "InputLen", PF_fSetData| PF_fGetData | DT_SHORT, OFFSETIN(KpComCtlDataT, inputLen), 0, 0L, NULL, 0 }; -static PROPINFO propInputMode = { "InputMode", PF_fSetData| PF_fGetData | DT_ENUM, OFFSETIN(KpComCtlDataT, inputMode), 0, 0L, szInputMode, 1 }; -static PROPINFO propDTREnable = { "DTREnable", PF_fSetMsg | PF_fGetData | DT_BOOL, OFFSETIN(KpComCtlDataT, dtrEnable), 0, 1L, NULL, 0 }; -static PROPINFO propRTSEnable = { "RTSEnable", PF_fSetMsg | PF_fGetData | DT_BOOL, OFFSETIN(KpComCtlDataT, rtsEnable), 0, 1L, NULL, 0 }; -static PROPINFO propCDHolding = { "CDHolding", PF_fGetMsg | PF_fNoShow | DT_BOOL, 0, 0, 0L, NULL, 0 }; -static PROPINFO propCTSHolding = { "CTSHolding", PF_fGetMsg | PF_fNoShow | DT_BOOL, 0, 0, 0L, NULL, 0 }; -static PROPINFO propDSRHolding = { "DSRHolding", PF_fGetMsg | PF_fNoShow | DT_BOOL, 0, 0, 0L, NULL, 0 }; -static PROPINFO propBreak = { "Break", PF_fSetMsg | PF_fGetData | DT_BOOL, OFFSETIN(KpComCtlDataT, breakState), 0, 0L, NULL, 0 }; -static PROPINFO propCommEvent = { "CommEvent", PF_fGetData| PF_fNoShow | DT_SHORT, OFFSETIN(KpComCtlDataT, commEvent), 0, 0L, NULL, 0 }; -static PROPINFO propNullDiscard = { "NullDiscard", PF_fSetMsg | PF_fGetData | DT_BOOL, OFFSETIN(KpComCtlDataT, nullDiscard), 0, 0L, NULL, 0 }; -static PROPINFO propEOFEnable = { "EOFEnable", PF_fSetData| PF_fGetData | DT_BOOL, OFFSETIN(KpComCtlDataT, eofEnable), 0, 0L, NULL, 0 }; -static PROPINFO propParityReplace = { "ParityReplace", PF_fSetMsg | PF_fGetMsg | DT_HSZ, 0, 0, 0L, NULL, 0 }; - -// ----------------------------------------------------------------------- -// Property list (NULL-terminated, order must match IPROP_* indices) -// ----------------------------------------------------------------------- -static PPROPINFO propList[] = { - PPROPINFO_STD_CTLNAME, // 0 - Name - PPROPINFO_STD_INDEX, // 1 - Index - PPROPINFO_STD_TAG, // 2 - Tag - &propCommPort, // 3 - &propSettings, // 4 - &propPortOpen, // 5 - &propInput, // 6 - &propOutput, // 7 - &propInBufferSize, // 8 - &propOutBufferSize, // 9 - &propInBufferCount, // 10 - &propOutBufferCount, // 11 - &propRThreshold, // 12 - &propSThreshold, // 13 - &propHandshaking, // 14 - &propInputLen, // 15 - &propInputMode, // 16 - &propDTREnable, // 17 - &propRTSEnable, // 18 - &propCDHolding, // 19 - &propCTSHolding, // 20 - &propDSRHolding, // 21 - &propBreak, // 22 - &propCommEvent, // 23 - &propNullDiscard, // 24 - &propEOFEnable, // 25 - &propParityReplace, // 26 - NULL -}; - -// ----------------------------------------------------------------------- -// Event descriptors -// ----------------------------------------------------------------------- -static EVENTINFO eventOnComm = { "OnComm", 0, 0, NULL, "", 0 }; - -// ----------------------------------------------------------------------- -// Event list (NULL-terminated) -// ----------------------------------------------------------------------- -static PEVENTINFO eventList[] = { - &eventOnComm, // 0 - OnComm - NULL -}; - -// ----------------------------------------------------------------------- -// MODEL definition -// ----------------------------------------------------------------------- -static char szCtlName[] = "KPComCtl"; - -MODEL modelKpComCtl = { - VB300_VERSION, // usVersion - MODEL_fInitMsg, // fl - (PCTLPROC)KpComCtlProc, // pctlproc - 0, // fsClassStyle - WS_CHILD, // flWndStyle - sizeof(KpComCtlDataT), // cbCtlExtra - IDB_KPCOMCTL, // idBmpPalette - szCtlName, // npszDefCtlName - NULL, // npszClassName - NULL, // npszParentClassName - propList, // npproplist - eventList, // npeventlist - IPROP_COMMPORT, // nDefProp - IEVENT_ONCOMM, // nDefEvent - 0, // nValueProp - 0x0100 // usCtlVersion (1.00) -}; - -// ----------------------------------------------------------------------- -// MODELINFO for VBGetModelInfo (CIRC3 CDK pattern) -// -// File-scope globals with static initialization, exactly matching the -// CDK sample pattern. VB4 may call VBGetModelInfo after VBINITCC returns. -// ----------------------------------------------------------------------- -LPMODEL gModelList[] = { - &modelKpComCtl, - NULL -}; - -MODELINFO gModelInfo = { - VB300_VERSION, - gModelList -}; - - -// ======================================================================= -// Internal helper functions (alphabetical) -// ======================================================================= - -// ----------------------------------------------------------------------- -// closePort - Close the serial port and destroy notification window -// -// No VB API calls here, so pData remains valid throughout. -// ----------------------------------------------------------------------- -static void closePort(HCTL hctl, KpComCtlDataT FAR *pData) -{ - dbgInt16("KPCOMCTL: closePort commId", pData->commId); - - if (pData->commId >= 0) { - if (pData->breakState) { - serialEscape(pData->commId, SERIAL_CLRBREAK); - pData->breakState = FALSE; - } - - serialClose(pData->commId); - pData->commId = -1; - } - - if (pData->hwndNotify != NULL) { - DestroyWindow(pData->hwndNotify); - pData->hwndNotify = NULL; - } - - pData->portOpen = FALSE; - pData->ctsState = FALSE; - pData->dsrState = FALSE; - pData->cdState = FALSE; -} - - -// ----------------------------------------------------------------------- -// fireOnComm - Set commEvent and fire OnComm event to VB -// -// WARNING: After this function returns, any previously obtained pData -// pointer is INVALID. Callers must re-deref via DEREF(hctl). -// ----------------------------------------------------------------------- -static void fireOnComm(HCTL hctl, KpComCtlDataT FAR *pData, int16_t eventCode) -{ - dbgInt16("KPCOMCTL: fireOnComm code", eventCode); - - pData->commEvent = eventCode; - VBFireEvent(hctl, IEVENT_ONCOMM, NULL); - // pData is now stale - caller must re-deref -} - - -// ----------------------------------------------------------------------- -// handleGetProperty - Process VBM_GETPROPERTY for message-based props -// ----------------------------------------------------------------------- -static LONG handleGetProperty(HCTL hctl, KpComCtlDataT FAR *pData, USHORT iProp) -{ - dbgInt16("KPCOMCTL: getProp iProp", (int16_t)iProp); - - switch (iProp) { - case IPROP_SETTINGS: - return (LONG)pData->hszSettings; - - case IPROP_INPUT: { - COMSTAT stat; - int16_t bytesToRead; - int16_t bytesRead; - int16_t commId; - int16_t inputLen; - HGLOBAL hMem; - char FAR *buf; - HSZ hsz; - - if (!pData->portOpen || pData->commId < 0) { - return (LONG)VBCreateHsz((HANDLE)0, ""); - } - - // Save values to locals before any VB API calls - commId = pData->commId; - inputLen = pData->inputLen; - - serialGetStatus(commId, &stat); - bytesToRead = (int16_t)stat.cbInQue; - - if (inputLen > 0 && bytesToRead > inputLen) { - bytesToRead = inputLen; - } - - if (bytesToRead <= 0) { - return (LONG)VBCreateHsz((HANDLE)0, ""); - } - - // Use GlobalAlloc for potentially large buffers (DLL local heap is small) - hMem = GlobalAlloc(GMEM_MOVEABLE, (DWORD)bytesToRead + 1); - if (hMem == NULL) { - return (LONG)VBCreateHsz((HANDLE)0, ""); - } - - buf = (char FAR *)GlobalLock(hMem); - bytesRead = serialRead(commId, buf, bytesToRead); - if (bytesRead <= 0) { - GlobalUnlock(hMem); - GlobalFree(hMem); - return (LONG)VBCreateHsz((HANDLE)0, ""); - } - - buf[bytesRead] = '\0'; - hsz = VBCreateHsz((HANDLE)0, buf); - GlobalUnlock(hMem); - GlobalFree(hMem); - // pData is stale after VBCreateHsz, but we just return the HSZ - return (LONG)hsz; - } - - case IPROP_INBUFFERCOUNT: { - COMSTAT stat; - if (!pData->portOpen || pData->commId < 0) { - return 0L; - } - serialGetStatus(pData->commId, &stat); - return (LONG)(int16_t)stat.cbInQue; - } - - case IPROP_OUTBUFFERCOUNT: { - COMSTAT stat; - if (!pData->portOpen || pData->commId < 0) { - return 0L; - } - serialGetStatus(pData->commId, &stat); - return (LONG)(int16_t)stat.cbOutQue; - } - - // Modem line status: return shadow state maintained by processEventNotify. - // The 16-bit comm API only provides transition events (GetCommEventMask), - // not current line levels. Shadow state is toggled on each transition. - case IPROP_CDHOLDING: - return (LONG)(BOOL)pData->cdState; - - case IPROP_CTSHOLDING: - return (LONG)(BOOL)pData->ctsState; - - case IPROP_DSRHOLDING: - return (LONG)(BOOL)pData->dsrState; - - case IPROP_PARITYREPLACE: - return (LONG)pData->hszParityReplace; - } - - return 0L; -} - - -// ----------------------------------------------------------------------- -// handleSetProperty - Process VBM_SETPROPERTY for message-based props -// ----------------------------------------------------------------------- -static LONG handleSetProperty(HCTL hctl, KpComCtlDataT FAR *pData, USHORT iProp, LONG lp) -{ - int16_t val; - - dbgInt16("KPCOMCTL: setProp iProp", (int16_t)iProp); - dbgHex16("KPCOMCTL: setProp lp.hi", (uint16_t)(lp >> 16)); - dbgHex16("KPCOMCTL: setProp lp.lo", (uint16_t)(lp & 0xFFFF)); - - switch (iProp) { - case IPROP_COMMPORT: - val = (int16_t)lp; - if (val < 1 || val > 16) { - return (LONG)ERR_InvPropVal; - } - if (pData->portOpen) { - return (LONG)ERR_InvPropSet; - } - pData->commPort = val; - return 0L; - - case IPROP_SETTINGS: { - HSZ oldHsz; - HSZ newHsz; - LPSTR lpstr; - int16_t commId; - int16_t port; - - // Deref the incoming HSZ (VBDerefHsz does not compact) - lpstr = VBDerefHsz((HSZ)lp); - if (lpstr == NULL) { - return (LONG)ERR_InvPropVal; - } - - // Save old HSZ, create new one - oldHsz = pData->hszSettings; - newHsz = VBCreateHsz((HANDLE)0, lpstr); - // pData may be stale after VBCreateHsz - re-deref - pData = DEREF(hctl); - pData->hszSettings = newHsz; - - if (oldHsz) { - VBDestroyHsz(oldHsz); - // pData may be stale after VBDestroyHsz - re-deref - pData = DEREF(hctl); - } - - // If port is open, reconfigure immediately - if (pData->portOpen && pData->commId >= 0) { - commId = pData->commId; - port = pData->commPort; - lpstr = VBDerefHsz(pData->hszSettings); - if (serialConfigure(commId, port, lpstr) != 0) { - return (LONG)ERR_InvPropVal; - } - } - return 0L; - } - - case IPROP_PORTOPEN: - if ((BOOL)lp) { - if (pData->portOpen) { - return 0L; - } - if (openPort(hctl, pData) != 0) { - return (LONG)ERR_InvPropVal; - } - } else { - if (!pData->portOpen) { - return 0L; - } - closePort(hctl, pData); - } - return 0L; - - case IPROP_OUTPUT: { - int16_t commId; - LPSTR lpstr; - - if (!pData->portOpen || pData->commId < 0) { - return (LONG)ERR_InvPropSet; - } - - // Save commId before VB API call - commId = pData->commId; - lpstr = VBDerefHsz((HSZ)lp); - if (lpstr != NULL) { - int16_t len = (int16_t)lstrlen(lpstr); - if (len > 0) { - int16_t written = serialWrite(commId, lpstr, len); - if (written < 0) { - // Re-deref before fireOnComm since pData may be stale - pData = DEREF(hctl); - fireOnComm(hctl, pData, COM_EVT_TXFULL); - // pData stale after fireOnComm, but we just return - } - } - } - return 0L; - } - - case IPROP_INBUFFERSIZE: - val = (int16_t)lp; - if (val < 64) { - return (LONG)ERR_InvPropVal; - } - if (pData->portOpen) { - return (LONG)ERR_InvPropSet; - } - pData->inBufferSize = val; - return 0L; - - case IPROP_OUTBUFFERSIZE: - val = (int16_t)lp; - if (val < 64) { - return (LONG)ERR_InvPropVal; - } - if (pData->portOpen) { - return (LONG)ERR_InvPropSet; - } - pData->outBufferSize = val; - return 0L; - - case IPROP_HANDSHAKING: - pData->handshaking = (int16_t)lp; - if (pData->portOpen && pData->commId >= 0) { - serialSetHandshaking(pData->commId, pData->handshaking); - } - return 0L; - - case IPROP_DTRENABLE: - pData->dtrEnable = (BOOL)lp; - if (pData->portOpen && pData->commId >= 0) { - serialEscape(pData->commId, pData->dtrEnable ? SERIAL_SETDTR : SERIAL_CLRDTR); - } - return 0L; - - case IPROP_RTSENABLE: - pData->rtsEnable = (BOOL)lp; - if (pData->portOpen && pData->commId >= 0) { - serialEscape(pData->commId, pData->rtsEnable ? SERIAL_SETRTS : SERIAL_CLRRTS); - } - return 0L; - - case IPROP_BREAK: - pData->breakState = (BOOL)lp; - if (pData->portOpen && pData->commId >= 0) { - serialEscape(pData->commId, pData->breakState ? SERIAL_SETBREAK : SERIAL_CLRBREAK); - } - return 0L; - - case IPROP_NULLDISCARD: { - int16_t commId; - BOOL nullDiscard; - LPSTR lpstr; - - pData->nullDiscard = (BOOL)lp; - if (pData->portOpen && pData->commId >= 0) { - // Save locals before VBDerefHsz - commId = pData->commId; - nullDiscard = pData->nullDiscard; - lpstr = VBDerefHsz(pData->hszParityReplace); - serialSetOptions(commId, nullDiscard, lpstr); - } - return 0L; - } - - case IPROP_PARITYREPLACE: { - HSZ oldHsz; - HSZ newHsz; - int16_t commId; - BOOL nullDiscard; - LPSTR lpstr; - - lpstr = VBDerefHsz((HSZ)lp); - oldHsz = pData->hszParityReplace; - newHsz = VBCreateHsz((HANDLE)0, lpstr ? lpstr : ""); - // Re-deref after VBCreateHsz - pData = DEREF(hctl); - pData->hszParityReplace = newHsz; - - if (oldHsz) { - VBDestroyHsz(oldHsz); - // Re-deref after VBDestroyHsz - pData = DEREF(hctl); - } - - if (pData->portOpen && pData->commId >= 0) { - commId = pData->commId; - nullDiscard = pData->nullDiscard; - lpstr = VBDerefHsz(pData->hszParityReplace); - serialSetOptions(commId, nullDiscard, lpstr); - } - return 0L; - } - } - - return 0L; -} - - -// ----------------------------------------------------------------------- -// initControlData - Initialize per-instance control data -// -// Re-derefs after each VBCreateHsz to avoid stale pointers. -// ----------------------------------------------------------------------- -static void initControlData(HCTL hctl) -{ - KpComCtlDataT FAR *pData; - HSZ hsz; - - dbgStr("KPCOMCTL: initControlData\r\n"); - - pData = DEREF(hctl); - pData->commId = -1; - pData->hwndNotify = NULL; - pData->commPort = 1; - pData->inBufferSize = 4096; - pData->outBufferSize = 4096; - pData->rThreshold = 0; - pData->sThreshold = 0; - pData->handshaking = HS_NONE; - pData->inputLen = 0; - pData->inputMode = INPUT_TEXT; - pData->commEvent = 0; - pData->portOpen = FALSE; - pData->dtrEnable = TRUE; - pData->rtsEnable = TRUE; - pData->breakState = FALSE; - pData->nullDiscard = FALSE; - pData->eofEnable = FALSE; - pData->ctsState = FALSE; - pData->dsrState = FALSE; - pData->cdState = FALSE; - - // VBCreateHsz may compact VB's heap - re-deref after each call - hsz = VBCreateHsz((HANDLE)0, "9600,N,8,1"); - pData = DEREF(hctl); - pData->hszSettings = hsz; - - hsz = VBCreateHsz((HANDLE)0, "?"); - pData = DEREF(hctl); - pData->hszParityReplace = hsz; -} - - -// ----------------------------------------------------------------------- -// openPort - Open serial port and set up notification window -// -// Saves all needed control data to locals before VB API calls to avoid -// stale pointer issues. Re-derefs when writing results back. -// ----------------------------------------------------------------------- -static int16_t openPort(HCTL hctl, KpComCtlDataT FAR *pData) -{ - int16_t commId; - int16_t port; - int16_t inBufSize; - int16_t outBufSize; - int16_t handshaking; - int16_t rThreshold; - int16_t sThreshold; - BOOL dtrEnable; - BOOL rtsEnable; - BOOL nullDiscard; - HSZ hszSettings; - HSZ hszParityReplace; - HWND hwndNotify; - LPSTR lpstr; - - dbgInt16("KPCOMCTL: openPort port", pData->commPort); - dbgInt16("KPCOMCTL: openPort inBuf", pData->inBufferSize); - dbgInt16("KPCOMCTL: openPort outBuf", pData->outBufferSize); - - // Snapshot all values we need (pData may become stale after VB API calls) - port = pData->commPort; - inBufSize = pData->inBufferSize; - outBufSize = pData->outBufferSize; - handshaking = pData->handshaking; - rThreshold = pData->rThreshold; - sThreshold = pData->sThreshold; - dtrEnable = pData->dtrEnable; - rtsEnable = pData->rtsEnable; - nullDiscard = pData->nullDiscard; - hszSettings = pData->hszSettings; - hszParityReplace = pData->hszParityReplace; - - // Open the comm port - commId = serialOpen(port, inBufSize, outBufSize); - if (commId < 0) { - dbgInt16("KPCOMCTL: openPort serialOpen FAIL", commId); - return -1; - } - dbgInt16("KPCOMCTL: openPort commId", commId); - - // Configure baud/parity/data/stop - lpstr = VBDerefHsz(hszSettings); - if (serialConfigure(commId, port, lpstr) != 0) { - dbgStr("KPCOMCTL: openPort configure FAIL\r\n"); - serialClose(commId); - return -1; - } - - // Apply handshaking - serialSetHandshaking(commId, handshaking); - - // Apply null-discard and parity-replace - lpstr = VBDerefHsz(hszParityReplace); - serialSetOptions(commId, nullDiscard, lpstr); - - // Set DTR and RTS lines - serialEscape(commId, dtrEnable ? SERIAL_SETDTR : SERIAL_CLRDTR); - serialEscape(commId, rtsEnable ? SERIAL_SETRTS : SERIAL_CLRRTS); - - // Create hidden notification window - hwndNotify = CreateWindow( - NOTIFY_CLASS, - "", - WS_POPUP, - 0, 0, 0, 0, - NULL, - NULL, - ghInstance, - NULL - ); - - if (hwndNotify == NULL) { - dbgStr("KPCOMCTL: openPort CreateWindow FAIL\r\n"); - serialClose(commId); - return -1; - } - - // Store HCTL in notification window for message dispatch - SetWindowLong(hwndNotify, 0, (LONG)hctl); - - // Enable comm notifications - serialEnableNotify(commId, hwndNotify, - rThreshold > 0 ? rThreshold : -1, - sThreshold > 0 ? sThreshold : -1); - - // Re-deref to write results back to control data - pData = DEREF(hctl); - pData->commId = commId; - pData->hwndNotify = hwndNotify; - pData->portOpen = TRUE; - pData->ctsState = FALSE; - pData->dsrState = FALSE; - pData->cdState = FALSE; - - dbgStr("KPCOMCTL: openPort OK\r\n"); - return 0; -} - - -// ----------------------------------------------------------------------- -// processEventNotify - Handle CN_EVENT notification -// -// Takes commId as a stable local value. Re-derefs pData after every -// fireOnComm call since VBFireEvent can trigger heap compaction. -// Updates modem line shadow state on CTS/DSR/CD transitions. -// ----------------------------------------------------------------------- -static void processEventNotify(HCTL hctl, int16_t commId) -{ - KpComCtlDataT FAR *pData; - UINT evtMask; - - evtMask = serialGetEventMask(commId, EV_CTS | EV_DSR | EV_RLSD | EV_RING | EV_ERR | EV_BREAK); - dbgHex16("KPCOMCTL: eventNotify mask", (uint16_t)evtMask); - - if (evtMask & EV_BREAK) { - pData = DEREF(hctl); - fireOnComm(hctl, pData, COM_EVT_BREAK); - } - - if (evtMask & EV_CTS) { - pData = DEREF(hctl); - pData->ctsState = !pData->ctsState; - fireOnComm(hctl, pData, COM_EV_CTS); - } - - if (evtMask & EV_DSR) { - pData = DEREF(hctl); - pData->dsrState = !pData->dsrState; - fireOnComm(hctl, pData, COM_EV_DSR); - } - - if (evtMask & EV_RLSD) { - pData = DEREF(hctl); - pData->cdState = !pData->cdState; - fireOnComm(hctl, pData, COM_EV_CD); - } - - if (evtMask & EV_RING) { - pData = DEREF(hctl); - fireOnComm(hctl, pData, COM_EV_RING); - } - - if (evtMask & EV_ERR) { - COMSTAT stat; - int16_t errFlags; - - errFlags = serialGetStatus(commId, &stat); - - if (errFlags & CE_FRAME) { - pData = DEREF(hctl); - fireOnComm(hctl, pData, COM_EVT_FRAME); - } - if (errFlags & CE_OVERRUN) { - pData = DEREF(hctl); - fireOnComm(hctl, pData, COM_EVT_OVERRUN); - } - if (errFlags & CE_RXOVER) { - pData = DEREF(hctl); - fireOnComm(hctl, pData, COM_EVT_RXOVER); - } - if (errFlags & CE_RXPARITY) { - pData = DEREF(hctl); - fireOnComm(hctl, pData, COM_EVT_RXPARITY); - } - if (errFlags & CE_TXFULL) { - pData = DEREF(hctl); - fireOnComm(hctl, pData, COM_EVT_TXFULL); - } - } -} - - -// ----------------------------------------------------------------------- -// processReceiveNotify - Handle CN_RECEIVE notification -// ----------------------------------------------------------------------- -static void processReceiveNotify(HCTL hctl, int16_t commId) -{ - KpComCtlDataT FAR *pData; - COMSTAT stat; - - dbgStr("KPCOMCTL: receiveNotify\r\n"); - - pData = DEREF(hctl); - - if (pData->rThreshold <= 0) { - return; - } - - serialGetStatus(commId, &stat); - - if ((int16_t)stat.cbInQue >= pData->rThreshold) { - fireOnComm(hctl, pData, COM_EV_RECEIVE); - // pData stale after fireOnComm, but we just return - } -} - - -// ----------------------------------------------------------------------- -// processTransmitNotify - Handle CN_TRANSMIT notification -// ----------------------------------------------------------------------- -static void processTransmitNotify(HCTL hctl, int16_t commId) -{ - KpComCtlDataT FAR *pData; - COMSTAT stat; - - dbgStr("KPCOMCTL: transmitNotify\r\n"); - - pData = DEREF(hctl); - - if (pData->sThreshold <= 0) { - return; - } - - serialGetStatus(commId, &stat); - - if ((int16_t)stat.cbOutQue <= pData->sThreshold) { - fireOnComm(hctl, pData, COM_EV_SEND); - // pData stale after fireOnComm, but we just return - } -} - - -// ----------------------------------------------------------------------- -// registerNotifyClass - Register hidden notification window class -// -// Tolerant of already-registered class (VB4 may call VBINITCC multiple -// times without VBTERMCC, or UnregisterClass may fail if windows exist). -// ----------------------------------------------------------------------- -static BOOL registerNotifyClass(HANDLE hInstance) -{ - WNDCLASS wc; - - // If class is already registered, treat as success - if (GetClassInfo(hInstance, NOTIFY_CLASS, &wc)) { - dbgStr("KPCOMCTL: notifyClass already registered\r\n"); - return TRUE; - } - - wc.style = 0; - wc.lpfnWndProc = NotifyWndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = sizeof(LONG); // Room for HCTL (far pointer) - wc.hInstance = hInstance; - wc.hIcon = NULL; - wc.hCursor = NULL; - wc.hbrBackground = NULL; - wc.lpszMenuName = NULL; - wc.lpszClassName = NOTIFY_CLASS; - - return RegisterClass(&wc); -} - - -// ======================================================================= -// Hidden notification window procedure -// -// Receives WM_COMMNOTIFY from the comm driver. Saves commId to a local -// variable and passes it to process* functions, which independently -// deref the control data (avoiding stale pointer chains across VBFireEvent). -// ======================================================================= - -LRESULT FAR PASCAL _export NotifyWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) -{ - if (msg == WM_COMMNOTIFY) { - HCTL hctl; - KpComCtlDataT FAR *pData; - int16_t commId; - UINT notifyCode; - - hctl = (HCTL)GetWindowLong(hwnd, 0); - if (hctl == NULL) { - return 0L; - } - - pData = DEREF(hctl); - if (pData == NULL || pData->commId < 0) { - return 0L; - } - - // Save commId to local - stable across VBFireEvent calls - commId = pData->commId; - notifyCode = LOWORD(lp); - - dbgInt16("KPCOMCTL: WM_COMMNOTIFY commId", commId); - dbgHex16("KPCOMCTL: WM_COMMNOTIFY code", (uint16_t)notifyCode); - - // Each process* function independently derefs and re-derefs as needed - if (notifyCode & CN_RECEIVE) { - processReceiveNotify(hctl, commId); - } - if (notifyCode & CN_TRANSMIT) { - processTransmitNotify(hctl, commId); - } - if (notifyCode & CN_EVENT) { - processEventNotify(hctl, commId); - } - - return 0L; - } - - return DefWindowProc(hwnd, msg, wp, lp); -} - - -// ======================================================================= -// VBX Control procedure -// ======================================================================= - -LONG FAR PASCAL _export KpComCtlProc(HCTL hctl, HWND hwnd, USHORT msg, USHORT wp, LONG lp) -{ - KpComCtlDataT FAR *pData; - - switch (msg) { - case VBM_INITIALIZE: - dbgStr("KPCOMCTL: VBM_INITIALIZE\r\n"); - initControlData(hctl); - return 0L; - - case VBM_SETPROPERTY: - pData = DEREF(hctl); - return handleSetProperty(hctl, pData, wp, lp); - - case VBM_GETPROPERTY: - pData = DEREF(hctl); - return handleGetProperty(hctl, pData, wp); - - case WM_DESTROY: { - HSZ hszSettings; - HSZ hszParityReplace; - - dbgStr("KPCOMCTL: WM_DESTROY\r\n"); - - pData = DEREF(hctl); - - // Close port if open - if (pData->portOpen) { - closePort(hctl, pData); - } - - // Save HSZ handles to locals, then destroy them. - // VBDestroyHsz may compact the heap, so don't access pData after. - hszSettings = pData->hszSettings; - hszParityReplace = pData->hszParityReplace; - pData->hszSettings = NULL; - pData->hszParityReplace = NULL; - - if (hszSettings) { - VBDestroyHsz(hszSettings); - } - if (hszParityReplace) { - VBDestroyHsz(hszParityReplace); - } - break; - } - } - - return VBDefControlProc(hctl, hwnd, msg, wp, lp); -} - - -// ======================================================================= -// DLL entry points -// ======================================================================= - -// ----------------------------------------------------------------------- -// LibMain - DLL initialization -// ----------------------------------------------------------------------- -int FAR PASCAL LibMain(HANDLE hInstance, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine) -{ - dbgStr("KPCOMCTL: LibMain\r\n"); - dbgHex16("KPCOMCTL: hInstance", (uint16_t)hInstance); - - ghInstance = hInstance; - - if (wHeapSize > 0) { - UnlockData(0); - } - - return 1; -} - - -// ----------------------------------------------------------------------- -// VBINITCC - Called by VB to register the control -// ----------------------------------------------------------------------- -BOOL FAR PASCAL _export VBINITCC(USHORT usVersion, BOOL fRuntime) -{ - BOOL rc; - - dbgHex16("KPCOMCTL: VBINITCC ver", (uint16_t)usVersion); - dbgInt16("KPCOMCTL: VBINITCC runtime", (int16_t)fRuntime); - dbgInt16("KPCOMCTL: VBINITCC modelInfoCalled", (int16_t)gModelInfoCalled); - - if (!registerNotifyClass(ghInstance)) { - dbgStr("KPCOMCTL: VBINITCC registerNotifyClass FAILED\r\n"); - return FALSE; - } - dbgStr("KPCOMCTL: VBINITCC notifyClass OK\r\n"); - - rc = VBRegisterModel(ghInstance, &modelKpComCtl); - dbgInt16("KPCOMCTL: VBRegisterModel", (int16_t)rc); - - return TRUE; -} - - -// ----------------------------------------------------------------------- -// VBTERMCC - Called by VB when unloading the control -// ----------------------------------------------------------------------- -void FAR PASCAL _export VBTERMCC(void) -{ - dbgStr("KPCOMCTL: VBTERMCC\r\n"); - dbgInt16("KPCOMCTL: VBTERMCC modelInfoCalled", (int16_t)gModelInfoCalled); - UnregisterClass(NOTIFY_CLASS, ghInstance); -} - - -// ----------------------------------------------------------------------- -// VBGetModelInfo - VB4+ model discovery -// -// Returns a MODELINFO containing a null-terminated list of MODEL pointers. -// VB4 calls this instead of relying on VBRegisterModel in VBINITCC. -// ----------------------------------------------------------------------- -LPMODELINFO FAR PASCAL _export VBGetModelInfo(USHORT usVersion) -{ - dbgHex16("KPCOMCTL: VBGetModelInfo ver", usVersion); - gModelInfoCalled = TRUE; - return &gModelInfo; -} - - -// ----------------------------------------------------------------------- -// WEP - DLL termination (required for 16-bit Windows DLLs) -// ----------------------------------------------------------------------- -void FAR PASCAL _export WEP(int nParam) -{ - (void)nParam; -} diff --git a/vbx/kpcomctl.def b/vbx/kpcomctl.def deleted file mode 100644 index e9364aa..0000000 --- a/vbx/kpcomctl.def +++ /dev/null @@ -1,16 +0,0 @@ -; kpcomctl.def - Module definition for KPComCtl VBX control - -LIBRARY KPCOMCTL -DESCRIPTION 'KPComCtl Serial Communications Control for VB4' -EXETYPE WINDOWS - -CODE PRELOAD MOVEABLE DISCARDABLE -DATA PRELOAD MOVEABLE SINGLE - -HEAPSIZE 1024 - -EXPORTS - WEP @1 RESIDENTNAME - VBINITCC @2 - VBTERMCC @3 - VBGetModelInfo @4 diff --git a/vbx/kpcomctl.h b/vbx/kpcomctl.h deleted file mode 100644 index 0f50e74..0000000 --- a/vbx/kpcomctl.h +++ /dev/null @@ -1,145 +0,0 @@ -// kpcomctl.h - KPComCtl VBX control definitions -// -// Property/event IDs, comm event constants, and control instance data. - -#ifndef KPCOMCTL_H -#define KPCOMCTL_H - -// ----------------------------------------------------------------------- -// Resource IDs -// ----------------------------------------------------------------------- -#define IDB_KPCOMCTL 8000 - -#ifndef RC_INVOKED - -#include "vbapi.h" -#include "serial.h" - -// ----------------------------------------------------------------------- -// stdint types for MSVC 1.52 (shared with serial.h) -// ----------------------------------------------------------------------- -#ifndef _STDINT_DEFINED -typedef short int16_t; -typedef unsigned short uint16_t; -typedef long int32_t; -typedef unsigned long uint32_t; -typedef unsigned char uint8_t; -typedef signed char int8_t; -#define _STDINT_DEFINED -#endif - -// ----------------------------------------------------------------------- -// Property indices (position in npproplist array) -// ----------------------------------------------------------------------- -#define IPROP_CTLNAME 0 -#define IPROP_INDEX 1 -#define IPROP_TAG 2 -#define IPROP_COMMPORT 3 -#define IPROP_SETTINGS 4 -#define IPROP_PORTOPEN 5 -#define IPROP_INPUT 6 -#define IPROP_OUTPUT 7 -#define IPROP_INBUFFERSIZE 8 -#define IPROP_OUTBUFFERSIZE 9 -#define IPROP_INBUFFERCOUNT 10 -#define IPROP_OUTBUFFERCOUNT 11 -#define IPROP_RTHRESHOLD 12 -#define IPROP_STHRESHOLD 13 -#define IPROP_HANDSHAKING 14 -#define IPROP_INPUTLEN 15 -#define IPROP_INPUTMODE 16 -#define IPROP_DTRENABLE 17 -#define IPROP_RTSENABLE 18 -#define IPROP_CDHOLDING 19 -#define IPROP_CTSHOLDING 20 -#define IPROP_DSRHOLDING 21 -#define IPROP_BREAK 22 -#define IPROP_COMMEVENT 23 -#define IPROP_NULLDISCARD 24 -#define IPROP_EOFENABLE 25 -#define IPROP_PARITYREPLACE 26 - -// ----------------------------------------------------------------------- -// Event indices (position in npeventlist array) -// ----------------------------------------------------------------------- -#define IEVENT_ONCOMM 0 - -// ----------------------------------------------------------------------- -// CommEvent constants - Communication events -// ----------------------------------------------------------------------- -#define COM_EV_RECEIVE 1 // Received RThreshold bytes -#define COM_EV_SEND 2 // Transmit buffer has SThreshold space -#define COM_EV_CTS 3 // CTS line changed -#define COM_EV_DSR 4 // DSR line changed -#define COM_EV_CD 5 // CD (RLSD) line changed -#define COM_EV_RING 6 // Ring indicator detected -#define COM_EV_EOF 7 // EOF character received - -// ----------------------------------------------------------------------- -// CommEvent constants - Error events -// ----------------------------------------------------------------------- -#define COM_EVT_BREAK 1001 // Break signal received -#define COM_EVT_FRAME 1004 // Framing error -#define COM_EVT_OVERRUN 1006 // Hardware overrun -#define COM_EVT_RXOVER 1008 // Receive buffer overflow -#define COM_EVT_RXPARITY 1009 // Parity error -#define COM_EVT_TXFULL 1010 // Transmit buffer full - -// ----------------------------------------------------------------------- -// Handshaking enum values -// ----------------------------------------------------------------------- -#define HS_NONE 0 -#define HS_XONXOFF 1 -#define HS_RTSCTS 2 -#define HS_BOTH 3 - -// ----------------------------------------------------------------------- -// InputMode enum values -// ----------------------------------------------------------------------- -#define INPUT_TEXT 0 -#define INPUT_BINARY 1 - -// ----------------------------------------------------------------------- -// Control instance data -// -// Allocated by VB as cbCtlExtra bytes per control instance. -// Accessed via VBDerefControl(hctl). -// ----------------------------------------------------------------------- -typedef struct { - int16_t commId; // OpenComm handle (-1 = closed) - HWND hwndNotify; // Hidden notification window - int16_t commPort; // COM port number (1-16) - HSZ hszSettings; // Settings string "baud,parity,data,stop" - int16_t inBufferSize; // Receive buffer size in bytes - int16_t outBufferSize; // Transmit buffer size in bytes - int16_t rThreshold; // Receive event threshold (0=disabled) - int16_t sThreshold; // Send event threshold (0=disabled) - int16_t handshaking; // Handshaking mode (HS_*) - int16_t inputLen; // Bytes to read per Input (0=all) - int16_t inputMode; // Input mode (INPUT_TEXT/INPUT_BINARY) - int16_t commEvent; // Last comm event code - BOOL portOpen; // Port open state - BOOL dtrEnable; // DTR line enable - BOOL rtsEnable; // RTS line enable - BOOL breakState; // Break signal active - BOOL nullDiscard; // Discard null characters - BOOL eofEnable; // Watch for EOF character - BOOL ctsState; // Shadow state: CTS line level - BOOL dsrState; // Shadow state: DSR line level - BOOL cdState; // Shadow state: CD (RLSD) line level - HSZ hszParityReplace; // Parity error replacement character -} KpComCtlDataT; - -// ----------------------------------------------------------------------- -// Hidden notification window class name -// ----------------------------------------------------------------------- -#define NOTIFY_CLASS "KpComCtlNotify" - -// ----------------------------------------------------------------------- -// Global instance handle (set in LibMain) -// ----------------------------------------------------------------------- -extern HANDLE ghInstance; - -#endif // RC_INVOKED - -#endif // KPCOMCTL_H diff --git a/vbx/kpcomctl.rc b/vbx/kpcomctl.rc deleted file mode 100644 index c908592..0000000 --- a/vbx/kpcomctl.rc +++ /dev/null @@ -1,36 +0,0 @@ -// kpcomctl.rc - KPComCtl VBX resource script -// -// Defines the toolbox bitmap and version information for the VB IDE. - -#include "kpcomctl.h" -#include - -IDB_KPCOMCTL BITMAP kpcomctl.bmp - -VS_VERSION_INFO VERSIONINFO -FILEVERSION 1,0,0,0 -PRODUCTVERSION 1,0,0,0 -FILEFLAGSMASK VS_FFI_FILEFLAGSMASK -FILEFLAGS 0 -FILEOS VOS__WINDOWS16 -FILETYPE VFT_DLL -FILESUBTYPE VFT2_UNKNOWN -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904E4" - BEGIN - VALUE "CompanyName", "KP Software\0" - VALUE "FileDescription", "KPComCtl Serial Communications Control\0" - VALUE "FileVersion", "1.00\0" - VALUE "InternalName", "KPCOMCTL\0" - VALUE "OriginalFilename", "KPCOMCTL.VBX\0" - VALUE "ProductName", "KPComCtl\0" - VALUE "ProductVersion", "1.00\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0409, 1252 - END -END diff --git a/vbx/makefile b/vbx/makefile deleted file mode 100644 index cad4f88..0000000 --- a/vbx/makefile +++ /dev/null @@ -1,81 +0,0 @@ -# makefile - KPComCtl VBX control for MSVC 1.52 -# -# Build: nmake -# Clean: nmake clean -# -# Prerequisites: -# - MSVC 1.52 (cl, link, rc in PATH) -# - VBAPI.LIB (from VBX CDK - contains thunk stubs, NOT an import library) -# -# High-speed serial note: -# The stock Windows 3.1 COMM.DRV enables the 16550 FIFO for receive only, -# with a trigger level of 14 (leaving only 2 bytes of headroom). This causes -# overruns at baud rates above 9600 under load. For reliable operation at -# 57600 or 115200, install KPCOMM.DRV (built from ..\drv\) or CyberCom -# V1.1.0.0P (..\drivers\CYBERCOM.DRV). -# -# Install (KPCOMM): -# 1. Copy ..\drv\KPCOMM.DRV to \WINDOWS\SYSTEM -# 2. Edit SYSTEM.INI [boot] section: comm.drv=kpcomm.drv -# 3. Add to [386Enh] section: COM1FIFO=1 (for each port in use) -# 4. Restart Windows - -CC = cl -LINK = link -RC = rc - -# Compiler flags: -# -c Compile only -# -W3 Warning level 3 -# -ASw Small model, SS!=DS (Windows DLL) -# -Gsw No stack probes, Windows prolog/epilog -# -Ow Safe optimizations for Windows -# -Zp2 Pack structures on 2-byte boundaries -# -Ze Enable Microsoft extensions -CFLAGS = -c -W3 -ASw -Gsw -Ow -Zp2 -Ze -IC:\MSVC\INCLUDE - -# Linker flags: -# /NOD No default libraries -# /NOE No extended dictionary search -# /AL:16 Segment alignment 16 -LFLAGS = /NOD /NOE /AL:16 /LI:C:\MSVC\LIB - -# Libraries -# sdllcew Small model DLL C runtime (emulated math, Windows) -# libw Windows API import library -# commdlg Common dialog import library -# vbapi VB API thunk library (from VBX CDK) -LIBS = sdllcew libw commdlg vbapi - -# Output -TARGET = kpcomctl.vbx - -# Objects -OBJS = kpcomctl.obj serial.obj - -# ----------------------------------------------------------------------- -# Build rules -# ----------------------------------------------------------------------- -all: $(TARGET) - -$(TARGET): $(OBJS) kpcomctl.def kpcomctl.res - $(LINK) $(LFLAGS) $(OBJS), $(TARGET),,$(LIBS), kpcomctl.def - $(RC) kpcomctl.res $(TARGET) - -kpcomctl.obj: kpcomctl.c kpcomctl.h vbapi.h serial.h - $(CC) $(CFLAGS) kpcomctl.c - -serial.obj: serial.c serial.h - $(CC) $(CFLAGS) serial.c - -kpcomctl.res: kpcomctl.rc kpcomctl.h kpcomctl.bmp - $(RC) -r -iC:\MSVC\INCLUDE kpcomctl.rc - -# ----------------------------------------------------------------------- -# Clean -# ----------------------------------------------------------------------- -clean: - -del *.obj - -del *.res - -del *.vbx - -del *.map diff --git a/vbx/serial.c b/vbx/serial.c deleted file mode 100644 index 0cb2845..0000000 --- a/vbx/serial.c +++ /dev/null @@ -1,253 +0,0 @@ -// serial.c - Serial port abstraction layer -// -// Wraps Windows 3.1 comm API for use by the MSComm VBX control. -// All functions operate on a comm ID returned by serialOpen(). - -#include -#include -#include "serial.h" - -// ----------------------------------------------------------------------- -// Prototypes -// ----------------------------------------------------------------------- -int16_t serialClose(int16_t commId); -int16_t serialConfigure(int16_t commId, int16_t port, const char FAR *settings); -BOOL serialEnableNotify(int16_t commId, HWND hwnd, int16_t rxThreshold, int16_t txThreshold); -int16_t serialEscape(int16_t commId, int16_t func); -int16_t serialFlush(int16_t commId, int16_t queue); -UINT serialGetEventMask(int16_t commId, UINT mask); -int16_t serialGetStatus(int16_t commId, COMSTAT FAR *stat); -int16_t serialOpen(int16_t port, int16_t inBufSize, int16_t outBufSize); -int16_t serialRead(int16_t commId, char FAR *buf, int16_t len); -int16_t serialSetHandshaking(int16_t commId, int16_t mode); -int16_t serialSetOptions(int16_t commId, BOOL nullDiscard, const char FAR *parityReplace); -int16_t serialWrite(int16_t commId, const char FAR *buf, int16_t len); - - -// ----------------------------------------------------------------------- -// serialClose - Close an open comm port -// ----------------------------------------------------------------------- -int16_t serialClose(int16_t commId) -{ - // Drop DTR and RTS before closing - EscapeCommFunction(commId, CLRDTR); - EscapeCommFunction(commId, CLRRTS); - - return (int16_t)CloseComm(commId); -} - - -// ----------------------------------------------------------------------- -// serialConfigure - Set baud, parity, data bits, stop bits -// ----------------------------------------------------------------------- -int16_t serialConfigure(int16_t commId, int16_t port, const char FAR *settings) -{ - DCB dcb; - char buf[64]; - int rc; - - // Get current state to preserve existing settings - rc = GetCommState(commId, &dcb); - if (rc != 0) { - return -1; - } - - // Build DCB from "COMn:baud,parity,data,stop" string - wsprintf(buf, "COM%d:%s", (int)port, (LPSTR)settings); - rc = BuildCommDCB(buf, &dcb); - if (rc != 0) { - return -1; - } - - // Ensure binary mode for reliable operation - dcb.fBinary = 1; - - // Ensure comm ID matches our open port - dcb.Id = (BYTE)commId; - - rc = SetCommState(&dcb); - if (rc != 0) { - return -1; - } - - return 0; -} - - -// ----------------------------------------------------------------------- -// serialEnableNotify - Enable WM_COMMNOTIFY messages -// ----------------------------------------------------------------------- -BOOL serialEnableNotify(int16_t commId, HWND hwnd, int16_t rxThreshold, int16_t txThreshold) -{ - // Enable event mask for modem status line changes, errors, and breaks - SetCommEventMask(commId, EV_CTS | EV_DSR | EV_RLSD | EV_RING | EV_ERR | EV_BREAK | EV_RXCHAR); - - return EnableCommNotification(commId, hwnd, rxThreshold, txThreshold); -} - - -// ----------------------------------------------------------------------- -// serialEscape - Execute escape function (DTR, RTS, break control) -// ----------------------------------------------------------------------- -int16_t serialEscape(int16_t commId, int16_t func) -{ - LONG rc; - - rc = EscapeCommFunction(commId, func); - return (rc == 0) ? 0 : -1; -} - - -// ----------------------------------------------------------------------- -// serialFlush - Flush receive or transmit buffer -// ----------------------------------------------------------------------- -int16_t serialFlush(int16_t commId, int16_t queue) -{ - return (int16_t)FlushComm(commId, queue); -} - - -// ----------------------------------------------------------------------- -// serialGetEventMask - Get and clear event mask bits -// ----------------------------------------------------------------------- -UINT serialGetEventMask(int16_t commId, UINT mask) -{ - return GetCommEventMask(commId, mask); -} - - -// ----------------------------------------------------------------------- -// serialGetStatus - Get error status and buffer counts -// ----------------------------------------------------------------------- -int16_t serialGetStatus(int16_t commId, COMSTAT FAR *stat) -{ - return (int16_t)GetCommError(commId, stat); -} - - -// ----------------------------------------------------------------------- -// serialOpen - Open a COM port with specified buffer sizes -// ----------------------------------------------------------------------- -int16_t serialOpen(int16_t port, int16_t inBufSize, int16_t outBufSize) -{ - char name[8]; - int commId; - - wsprintf(name, "COM%d", (int)port); - commId = OpenComm(name, (UINT)inBufSize, (UINT)outBufSize); - - return (int16_t)commId; -} - - -// ----------------------------------------------------------------------- -// serialRead - Read data from receive buffer -// ----------------------------------------------------------------------- -int16_t serialRead(int16_t commId, char FAR *buf, int16_t len) -{ - return (int16_t)ReadComm(commId, (LPSTR)buf, len); -} - - -// ----------------------------------------------------------------------- -// serialSetHandshaking - Apply handshaking mode -// ----------------------------------------------------------------------- -int16_t serialSetHandshaking(int16_t commId, int16_t mode) -{ - DCB dcb; - int rc; - - rc = GetCommState(commId, &dcb); - if (rc != 0) { - return -1; - } - - // Clear all flow control settings - dcb.fOutxCtsFlow = 0; - dcb.fOutxDsrFlow = 0; - dcb.fOutX = 0; - dcb.fInX = 0; - dcb.fRtsDisable = 0; - dcb.fRtsflow = 0; - - switch (mode) { - case HANDSHAKE_XONXOFF: - dcb.fOutX = 1; - dcb.fInX = 1; - dcb.XonChar = 0x11; // Ctrl-Q - dcb.XoffChar = 0x13; // Ctrl-S - dcb.XonLim = 256; - dcb.XoffLim = 256; - break; - - case HANDSHAKE_RTSCTS: - dcb.fOutxCtsFlow = 1; - dcb.fRtsflow = 1; - break; - - case HANDSHAKE_BOTH: - dcb.fOutxCtsFlow = 1; - dcb.fRtsflow = 1; - dcb.fOutX = 1; - dcb.fInX = 1; - dcb.XonChar = 0x11; - dcb.XoffChar = 0x13; - dcb.XonLim = 256; - dcb.XoffLim = 256; - break; - - case HANDSHAKE_NONE: - default: - break; - } - - dcb.Id = (BYTE)commId; - rc = SetCommState(&dcb); - if (rc != 0) { - return -1; - } - - return 0; -} - - -// ----------------------------------------------------------------------- -// serialSetOptions - Apply null-discard and parity-replace settings -// ----------------------------------------------------------------------- -int16_t serialSetOptions(int16_t commId, BOOL nullDiscard, const char FAR *parityReplace) -{ - DCB dcb; - int rc; - - rc = GetCommState(commId, &dcb); - if (rc != 0) { - return -1; - } - - dcb.fNull = nullDiscard ? 1 : 0; - - if (parityReplace != NULL && parityReplace[0] != '\0') { - dcb.fParity = 1; - dcb.PeChar = parityReplace[0]; - } else { - dcb.fParity = 0; - dcb.PeChar = '\0'; - } - - dcb.Id = (BYTE)commId; - rc = SetCommState(&dcb); - if (rc != 0) { - return -1; - } - - return 0; -} - - -// ----------------------------------------------------------------------- -// serialWrite - Write data to transmit buffer -// ----------------------------------------------------------------------- -int16_t serialWrite(int16_t commId, const char FAR *buf, int16_t len) -{ - return (int16_t)WriteComm(commId, (LPSTR)buf, len); -} diff --git a/vbx/serial.h b/vbx/serial.h deleted file mode 100644 index 84bfc73..0000000 --- a/vbx/serial.h +++ /dev/null @@ -1,110 +0,0 @@ -// serial.h - Serial port abstraction header -// -// Wraps Windows 3.1 comm API (OpenComm, ReadComm, WriteComm, etc.) -// for use by the MSComm VBX control. - -#ifndef SERIAL_H -#define SERIAL_H - -#include - -// ----------------------------------------------------------------------- -// stdint types for MSVC 1.52 (no stdint.h available) -// ----------------------------------------------------------------------- -#ifndef _STDINT_DEFINED -typedef short int16_t; -typedef unsigned short uint16_t; -typedef long int32_t; -typedef unsigned long uint32_t; -typedef unsigned char uint8_t; -typedef signed char int8_t; -#define _STDINT_DEFINED -#endif - -// ----------------------------------------------------------------------- -// Handshaking modes -// ----------------------------------------------------------------------- -#define HANDSHAKE_NONE 0 -#define HANDSHAKE_XONXOFF 1 -#define HANDSHAKE_RTSCTS 2 -#define HANDSHAKE_BOTH 3 - -// ----------------------------------------------------------------------- -// Flush queue selectors -// ----------------------------------------------------------------------- -#define FLUSH_RX 0 -#define FLUSH_TX 1 - -// ----------------------------------------------------------------------- -// Escape function constants (mirrors EscapeCommFunction values) -// -// SETDTR through RESETDEV are defined by windows.h. -// SETBREAK/CLRBREAK are not in windows.h (SetCommBreak/ClearCommBreak -// are separate API functions), so we define numeric values directly. -// ----------------------------------------------------------------------- -#define SERIAL_SETDTR SETDTR -#define SERIAL_CLRDTR CLRDTR -#define SERIAL_SETRTS SETRTS -#define SERIAL_CLRRTS CLRRTS -#define SERIAL_SETBREAK 8 -#define SERIAL_CLRBREAK 9 - -// ----------------------------------------------------------------------- -// Function prototypes -// ----------------------------------------------------------------------- - -// Open a COM port with specified buffer sizes. -// Returns comm ID (>= 0) on success, negative on error. -int16_t serialOpen(int16_t port, int16_t inBufSize, int16_t outBufSize); - -// Close an open comm port. Drops DTR and RTS before closing. -// Returns 0 on success, negative on error. -int16_t serialClose(int16_t commId); - -// Configure baud, parity, data bits, stop bits from a settings string. -// settings format: "baud,parity,data,stop" (e.g., "9600,N,8,1") -// Returns 0 on success, negative on error. -int16_t serialConfigure(int16_t commId, int16_t port, const char FAR *settings); - -// Apply handshaking mode to an open port. -// mode: HANDSHAKE_NONE, HANDSHAKE_XONXOFF, HANDSHAKE_RTSCTS, HANDSHAKE_BOTH -// Returns 0 on success, negative on error. -int16_t serialSetHandshaking(int16_t commId, int16_t mode); - -// Apply null-discard and parity-replace settings to an open port. -// Returns 0 on success, negative on error. -int16_t serialSetOptions(int16_t commId, BOOL nullDiscard, const char FAR *parityReplace); - -// Read data from receive buffer. -// Returns number of bytes read, or negative on error. -int16_t serialRead(int16_t commId, char FAR *buf, int16_t len); - -// Write data to transmit buffer. -// Returns number of bytes written, or negative on error. -int16_t serialWrite(int16_t commId, const char FAR *buf, int16_t len); - -// Get comm error status and buffer counts. Clears the error state. -// Returns error flags, fills stat with buffer counts. -int16_t serialGetStatus(int16_t commId, COMSTAT FAR *stat); - -// Execute an escape function (DTR, RTS, break control). -// func: SERIAL_SETDTR, SERIAL_CLRDTR, SERIAL_SETRTS, etc. -// Returns 0 on success, negative on error. -int16_t serialEscape(int16_t commId, int16_t func); - -// Get modem status lines via GetCommEventMask. -// Returns event mask bits (EV_CTS, EV_DSR, EV_RLSD, EV_RING). -UINT serialGetEventMask(int16_t commId, UINT mask); - -// Enable WM_COMMNOTIFY messages to the specified window. -// rxThreshold: fire CN_RECEIVE when this many bytes available (-1=disable) -// txThreshold: fire CN_TRANSMIT when this much space free (-1=disable) -// Returns TRUE on success. -BOOL serialEnableNotify(int16_t commId, HWND hwnd, int16_t rxThreshold, int16_t txThreshold); - -// Flush receive and/or transmit buffers. -// queue: FLUSH_RX or FLUSH_TX -// Returns 0 on success, negative on error. -int16_t serialFlush(int16_t commId, int16_t queue); - -#endif // SERIAL_H diff --git a/vbx/vbapi.def b/vbx/vbapi.def deleted file mode 100644 index 458d00d..0000000 --- a/vbx/vbapi.def +++ /dev/null @@ -1,29 +0,0 @@ -; vbapi.def - VB API import library definition -; -; Defines the VB API functions exported by the VBAPI module. -; Use with IMPLIB to generate the import library: -; -; implib vbapi.lib vbapi.def -; -; The VBAPI module is the VB runtime that exports these functions. -; When VB loads a VBX, it resolves imports against this module. - -LIBRARY VBAPI - -EXPORTS - VBRegisterModel @100 - VBDefControlProc @101 - VBFireEvent @102 - VBCreateHsz @103 - VBDestroyHsz @104 - VBDerefHsz @105 - VBCreateHlstr @106 - VBDestroyHlstr @107 - VBGetHlstr @108 - VBSetHlstr @109 - VBDerefControl @110 - VBGetMode @111 - VBSetControlProperty @112 - VBGetControlProperty @113 - VBGetControlHwnd @114 - VBGetHInstance @115 diff --git a/vbx/vbapi.h b/vbx/vbapi.h deleted file mode 100644 index f315825..0000000 --- a/vbx/vbapi.h +++ /dev/null @@ -1,290 +0,0 @@ -// vbapi.h - Reconstructed VBX CDK header -// -// Reconstructed from the published Visual Basic Custom Control (VBX) -// specification for use with MSVC 1.52 targeting 16-bit Visual Basic 4. -// Types, structures, constants, and API prototypes match the VBX CDK. - -#ifndef VBAPI_H -#define VBAPI_H - -#include - -// ----------------------------------------------------------------------- -// Packing: VBX CDK structures use byte packing -// ----------------------------------------------------------------------- -#pragma pack(1) - -// ----------------------------------------------------------------------- -// Core types -// ----------------------------------------------------------------------- -#ifndef USHORT -typedef unsigned short USHORT; -#endif - -typedef LPVOID HCTL; // Handle to a VBX control instance -typedef LPSTR HSZ; // Handle to a VB-managed string -typedef LPVOID HLSTR; // Handle to a VB long string -typedef USHORT ERR; // Error code - -// Flag type -typedef DWORD FL; - -// ----------------------------------------------------------------------- -// Forward declarations and pointer types -// ----------------------------------------------------------------------- -typedef struct tagMODEL MODEL; -typedef struct tagPROPINFO PROPINFO; -typedef struct tagEVENTINFO EVENTINFO; - -typedef MODEL FAR *LPMODEL; -typedef PROPINFO *PPROPINFO; // Near pointer (DLL data segment) -typedef EVENTINFO *PEVENTINFO; // Near pointer (DLL data segment) - -// ----------------------------------------------------------------------- -// Control procedure type -// ----------------------------------------------------------------------- -typedef LONG (FAR PASCAL *PCTLPROC)(HCTL, HWND, USHORT, USHORT, LONG); - -// ----------------------------------------------------------------------- -// VB version constants -// ----------------------------------------------------------------------- -#define VB_VERSION 0x0300 -#define VB300_VERSION 0x0300 - -// ----------------------------------------------------------------------- -// Data types (bits 0-7 of PROPINFO.fl) -// ----------------------------------------------------------------------- -#define DT_HSZ 0x01 -#define DT_SHORT 0x02 -#define DT_LONG 0x03 -#define DT_BOOL 0x04 -#define DT_COLOR 0x05 -#define DT_ENUM 0x06 -#define DT_REAL 0x07 -#define DT_XPOS 0x08 -#define DT_XSIZE 0x09 -#define DT_YPOS 0x0A -#define DT_YSIZE 0x0B -#define DT_PICTURE 0x0C -#define DT_HLSTR 0x0D - -// ----------------------------------------------------------------------- -// Property flags (bits 8+ of PROPINFO.fl) -// ----------------------------------------------------------------------- -#define PF_datatype 0x000000FFL // Mask for data type field -#define PF_fPropArray 0x00000100L -#define PF_fSetData 0x00000200L -#define PF_fSetMsg 0x00000400L -#define PF_fNoShow 0x00000800L -#define PF_fNoRuntimeW 0x00001000L -#define PF_fGetData 0x00002000L -#define PF_fGetMsg 0x00004000L -#define PF_fSetCheck 0x00008000L -#define PF_fSaveData 0x00010000L -#define PF_fSaveMsg 0x00020000L -#define PF_fGetHszMsg 0x00040000L -#define PF_fUpdateOnEdit 0x00080000L -#define PF_fEditable 0x00100000L -#define PF_fPreHwnd 0x00200000L -#define PF_fDefVal 0x00400000L -#define PF_fNoInitDef 0x00800000L -#define PF_fNoRuntimeR 0x02000000L -#define PF_fNoMultiSelect 0x04000000L -#define PF_fLoadDataOnly 0x20010000L -#define PF_fLoadMsgOnly 0x20020000L - -// ----------------------------------------------------------------------- -// MODEL flags -// ----------------------------------------------------------------------- -#define MODEL_fArrows 0x00000001L -#define MODEL_fFocusOk 0x00000002L -#define MODEL_fMnemonic 0x00000004L -#define MODEL_fChildrenOk 0x00000008L -#define MODEL_fInitMsg 0x00000010L -#define MODEL_fLoadMsg 0x00000020L -#define MODEL_fDesInteract 0x00000040L -#define MODEL_fInvisAtRun 0x00000080L -#define MODEL_fGraphical 0x00000100L - -// ----------------------------------------------------------------------- -// VBX control messages -// ----------------------------------------------------------------------- -#define VBM__BASE (WM_USER + 0x0C00) -#define VBM_CREATED (VBM__BASE + 0x00) -#define VBM_LOADED (VBM__BASE + 0x01) -#define VBM_INITIALIZE (VBM__BASE + 0x02) -#define VBM_GETPROPERTY (VBM__BASE + 0x03) -#define VBM_CHECKPROPERTY (VBM__BASE + 0x04) -#define VBM_SETPROPERTY (VBM__BASE + 0x05) -#define VBM_SAVEPROPERTY (VBM__BASE + 0x06) -#define VBM_LOADPROPERTY (VBM__BASE + 0x07) -#define VBM_MNEMONIC (VBM__BASE + 0x0D) -#define VBM_METHOD (VBM__BASE + 0x11) - -// ----------------------------------------------------------------------- -// Error codes -// ----------------------------------------------------------------------- -#define ERR_None 0 -#define ERR_InvPropVal 380 // Invalid property value -#define ERR_InvPropSet 383 // Can't set property at this time - -// ----------------------------------------------------------------------- -// Standard property indices -// ----------------------------------------------------------------------- -#define IPROP_STD_NAME 0x0000 -#define IPROP_STD_CTLNAME IPROP_STD_NAME -#define IPROP_STD_INDEX 0x0001 -#define IPROP_STD_HWND 0x0002 -#define IPROP_STD_BACKCOLOR 0x0003 -#define IPROP_STD_FORECOLOR 0x0004 -#define IPROP_STD_LEFT 0x0005 -#define IPROP_STD_TOP 0x0006 -#define IPROP_STD_WIDTH 0x0007 -#define IPROP_STD_HEIGHT 0x0008 -#define IPROP_STD_ENABLED 0x0009 -#define IPROP_STD_VISIBLE 0x000A -#define IPROP_STD_PARENT 0x0014 -#define IPROP_STD_DRAGMODE 0x0015 -#define IPROP_STD_DRAGICON 0x0016 -#define IPROP_STD_TAG 0x0019 -#define IPROP_STD_NONE 0x001E - -// ----------------------------------------------------------------------- -// Standard property pointers -// -// Magic sentinel values recognized by VB as built-in properties. -// Uses bitwise NOT of standard property index. -// ----------------------------------------------------------------------- -#define PPROPINFO_STD_NAME ((PPROPINFO)~IPROP_STD_NAME) -#define PPROPINFO_STD_CTLNAME ((PPROPINFO)~IPROP_STD_CTLNAME) -#define PPROPINFO_STD_INDEX ((PPROPINFO)~IPROP_STD_INDEX) -#define PPROPINFO_STD_HWND ((PPROPINFO)~IPROP_STD_HWND) -#define PPROPINFO_STD_LEFT ((PPROPINFO)~IPROP_STD_LEFT) -#define PPROPINFO_STD_TOP ((PPROPINFO)~IPROP_STD_TOP) -#define PPROPINFO_STD_WIDTH ((PPROPINFO)~IPROP_STD_WIDTH) -#define PPROPINFO_STD_HEIGHT ((PPROPINFO)~IPROP_STD_HEIGHT) -#define PPROPINFO_STD_ENABLED ((PPROPINFO)~IPROP_STD_ENABLED) -#define PPROPINFO_STD_VISIBLE ((PPROPINFO)~IPROP_STD_VISIBLE) -#define PPROPINFO_STD_PARENT ((PPROPINFO)~IPROP_STD_PARENT) -#define PPROPINFO_STD_DRAGMODE ((PPROPINFO)~IPROP_STD_DRAGMODE) -#define PPROPINFO_STD_DRAGICON ((PPROPINFO)~IPROP_STD_DRAGICON) -#define PPROPINFO_STD_TAG ((PPROPINFO)~IPROP_STD_TAG) -#define PPROPINFO_STD_NONE ((PPROPINFO)~IPROP_STD_NONE) - -// ----------------------------------------------------------------------- -// PROPINFO - Property descriptor -// ----------------------------------------------------------------------- -struct tagPROPINFO { - PSTR npszName; // Property name (near pointer, DLL DS) - FL fl; // Data type (bits 0-7) | Property flags (bits 8+) - BYTE offsetData; // Byte offset in control's cbCtlExtra data - BYTE infoData; // Type-specific info (e.g., max string length) - LONG dataDefault; // Default value - PSTR npszEnumList; // DT_ENUM: null-separated, double-null terminated - BYTE enumMax; // DT_ENUM: maximum valid value -}; - -// ----------------------------------------------------------------------- -// EVENTINFO - Event descriptor -// ----------------------------------------------------------------------- -struct tagEVENTINFO { - PSTR npszName; // Event name - USHORT cParms; // Number of parameters - USHORT cwParms; // Size of parameters in words - PWORD npParmTypes; // Parameter type list (NULL if no params) - PSTR npszParmProf; // Parameter profile string (e.g., "value As Integer") - FL fl; // Event flags -}; - -// ----------------------------------------------------------------------- -// MODEL - Control model definition -// -// VB3+ version (usVersion = VB300_VERSION) for VB4 compatibility. -// Registered with VBRegisterModel() in VBINITCC. -// ----------------------------------------------------------------------- -struct tagMODEL { - USHORT usVersion; // VB_VERSION (0x0300) - FL fl; // MODEL_* flags - PCTLPROC pctlproc; // Control procedure - USHORT fsClassStyle; // Window class style bits - FL flWndStyle; // Window style bits - USHORT cbCtlExtra; // Bytes of per-instance data - USHORT idBmpPalette; // Toolbox bitmap resource ID - PSTR npszDefCtlName; // Default control name (near) - PSTR npszClassName; // Window class name (NULL = default) - PSTR npszParentClassName; // Parent class name (NULL = default) - PPROPINFO *npproplist; // Property list (NULL-terminated array) - PEVENTINFO *npeventlist; // Event list (NULL-terminated array) - BYTE nDefProp; // Default property index - BYTE nDefEvent; // Default event index - BYTE nValueProp; // Value property index - USHORT usCtlVersion; // Control version (BCD, user-defined) -}; - -// ----------------------------------------------------------------------- -// MODELINFO - Returned by VBGetModelInfo (VB4+ model discovery) -// ----------------------------------------------------------------------- -typedef struct tagMODELINFO { - USHORT usVersion; // VB_VERSION - LPMODEL FAR *lplpmodel; // Null-terminated list of LPMODEL -} MODELINFO; - -typedef MODELINFO FAR *LPMODELINFO; - -// ----------------------------------------------------------------------- -// Utility macro: byte offset of a field within a structure -// ----------------------------------------------------------------------- -#define OFFSETIN(type, field) ((BYTE)&(((type *)0)->field)) - -// ----------------------------------------------------------------------- -// VB API function prototypes -// -// These functions are exported by the VB runtime (VBAPI module) and -// resolved at load time when VB loads the VBX. -// ----------------------------------------------------------------------- - -// Control registration -BOOL FAR PASCAL VBRegisterModel(HANDLE hmodule, MODEL FAR *lpmodel); - -// Default control procedure -LONG FAR PASCAL VBDefControlProc(HCTL hctl, HWND hwnd, USHORT msg, USHORT wp, LONG lp); - -// Event firing -ERR FAR PASCAL VBFireEvent(HCTL hctl, USHORT iEvent, LPVOID lpparams); - -// String handle management -HSZ FAR PASCAL VBCreateHsz(HANDLE seg, LPSTR lpsz); -HSZ FAR PASCAL VBDestroyHsz(HSZ hsz); -LPSTR FAR PASCAL VBDerefHsz(HSZ hsz); - -// Long string handle management -HLSTR FAR PASCAL VBCreateHlstr(LPVOID lpdata, USHORT cbLen); -void FAR PASCAL VBDestroyHlstr(HLSTR hlstr); -USHORT FAR PASCAL VBGetHlstr(HLSTR hlstr, LPVOID pb, USHORT cbLen); -ERR FAR PASCAL VBSetHlstr(HLSTR FAR *phlstr, LPVOID lpdata, USHORT cbLen); - -// Control data access -LPVOID FAR PASCAL VBDerefControl(HCTL hctl); - -// Runtime mode query (MODE_DESIGN=1, MODE_RUN=2, MODE_BREAK=3) -USHORT FAR PASCAL VBGetMode(void); - -// Control property access -ERR FAR PASCAL VBSetControlProperty(HCTL hctl, USHORT iProp, LONG data); -ERR FAR PASCAL VBGetControlProperty(HCTL hctl, USHORT iProp, LPVOID pdata); - -// Control window handle -HWND FAR PASCAL VBGetControlHwnd(HCTL hctl); - -// Instance handle -HANDLE FAR PASCAL VBGetHInstance(void); - -// Runtime version -USHORT FAR PASCAL VBGetVersion(void); - -// ----------------------------------------------------------------------- -// Restore default packing -// ----------------------------------------------------------------------- -#pragma pack() - -#endif // VBAPI_H