Files
TeslaRel410/BORLAND/BDE/EXAMPLES/C/DBPING/DBPING.C
T
CydandClaude Fable 5 63312e07f9 source410: literal 4.10 source reconstruction + BC++ 4.52 fleet toolchain archived
- BORLAND/: Borland C++ 4.52 (chosen over 4.5 by byte-match: CODE/RP/CW32.LIB
  is identical to 4.52's install lib). BCC32/TLINK32/TLIB/MAKE run natively on
  Win11; CODE/BT/OPT.MAK is the shipped BTL4OPT.EXE's exact flag recipe
  (extender = Borland PowerPack DPMI32, not Phar Lap TNT).
- restoration/source410/: the literal 1995-form reconstruction of the missing
  BT game source (never mixed into CODE/). Round 1-3 state:
  * 6 of 10 surviving original TUs COMPILE CLEAN under the period toolchain
    (BTMSSN, BTCNSL, BTSCNRL, BTTEAM, BTL4MODE, BTL4ARND) - first builds
    since 1996.
  * BT_L4/BTL4APP.CPP pilot reconstruction: 12/12 functions, Fail() lands on
    its binary-recorded line 400 exactly.
  * BT/BTCNSL.HPP: console wire IDs recovered from the binary's ctors
    (Killed=9, Damaged=10, ScoreUpdate=13, DeathWithoutHonor=15 [T1];
    TeamScore=12 flagged [T4]).
  * MUNGA/: 8 engine-header backfills back-dated from the BT412 WinTesla tree
    (VDATA numbering decomp-verified; AUDREND's OpenAL-era virtual removed -
    the period compiler is the drift detector).
  * Tooling: backdate.py (WinTesla->1995 header transform), compile410.sh
    (per-TU verification sweep under authentic OPT.MAK flags).
  * README: corrected roadmap - MECH.HPP is the capstone grown with the mech
    TU reconstructions; BTREG.CPP green = the header-family milestone.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-19 07:33:26 -05:00

501 lines
16 KiB
C++

// BDE - (C) Copyright 1994 by Borland International
#include <windows.h>
#include <ctl3d.h>
#include <idapi.h>
#include <malloc.h>
#include <string.h>
#include "dbping.h"
// Declaration of global data
HINSTANCE hInst;
HWND hMainWnd;
HCURSOR hArrow, hWait;
// Function prototypes
static BOOL InitApp(int nCmdShow);
void reset_connect_dialog(HWND hWnd, BOOL bFirstReset, BOOL bResetAll);
void try_to_connect(HWND hWnd);
long FAR PASCAL _export MainWndProc(HWND, UINT, UINT, LONG);
BOOL FAR PASCAL _export About(HWND, WORD, WORD, LONG);
//===============================================================
// Name: WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
//
// Input: hInstance - The handle that represents the applications
// unique instance ID.
// hPrevInstance - Indicates if this is the first instance of
// the app.
// lpCmdLine - Command line parameters (up to the app to
// parse).
// nCmdShow - TRUE = Show as non-icon application
//
// Desc: Application entry point. Init the app, main
// window, and global variables.
//================================================================
int PASCAL
WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
DBIResult rslt; // IDAPI return values
// Avoid warning re: Parameter is never used
lpCmdLine = lpCmdLine;
// Register CTL3D
Ctl3dRegister(hInstance);
Ctl3dAutoSubclass(hInstance);
Ctl3dColorChange();
// Make this a single instance program
if (hPrevInstance)
{
MessageBox(GetFocus(), "This application is already running!",
"PING Utility", MB_OK);
return FALSE;
}
// Init ODAPI (quit if failure occurs)
SetCursor(hWait);
if ((rslt = DbiInit(NULL)) != DBIERR_NONE)
{
if (rslt == DBIERR_CANTFINDODAPI)
{
MessageBox(GetFocus(), "Init( ) failed - DLL's not found."
"\r\nCheck your path.", "PING Utility", MB_OK);
}
else
{
MessageBox(GetFocus(), "Init( ) failed!", "PING Utility",
MB_OK);
}
return FALSE;
}
// Enable trace info if the debugging layer is enabled.
DbiDebugLayerOptions(DEBUGON | OUTPUTTOFILE, "DBPING.INF");
SetCursor(hArrow);
// Start the application
hInst = hInstance;
hWait = LoadCursor(NULL, IDC_WAIT);
hArrow = LoadCursor(NULL, IDC_ARROW);
if (InitApp(nCmdShow) == FALSE)
{
return FALSE;
}
// Process all event driven messages...
while (GetMessage(&msg, NULL, NULL, NULL))
{
if (!IsDialogMessage(hMainWnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
// Clean up and return
SetCursor(hWait);
DbiDebugLayerOptions(0, NULL);
DbiExit();
DestroyWindow(hMainWnd);
SetCursor(hArrow);
// Unregister CTL3D
Ctl3dUnregister(hInstance);
return msg.wParam;
}
//=================================================================
// Name: InitApp(nCmdShow);
//
// Input: nCmdShow - Whether to show the window after it is created
//
// Return: TRUE - Init worked
// FALSE - Init failed
//
// Desc: Create the application window (in this case a
// dialog).
//================================================================
static BOOL
InitApp (int nCmdShow)
{
WNDCLASS wc;
BOOL ret = TRUE;
// Init the application & create the needed windows
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = DLGWINDOWEXTRA;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(1100));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
wc.lpszMenuName = NULL;
wc.lpszClassName = "ConnectClass";
if(!RegisterClass(&wc))
{
MessageBox(NULL, "RegisterClass failed!", "System Error",
MB_OK | MB_ICONHAND);
return FALSE;
}
hMainWnd = CreateDialog(hInst, "MainDialog", NULL, NULL);
if (hMainWnd == NULL)
{
MessageBox(NULL, "CreateDialog failed!", "System Error",
MB_OK | MB_ICONHAND);
return FALSE;
}
ShowWindow(hMainWnd, nCmdShow);
reset_connect_dialog(hMainWnd, TRUE, TRUE);
SetFocus(GetDlgItem(hMainWnd, IDL_DRIVERS));
return ret;
}
//===============================================================
// Name: reset_connect_dialog(hWnd, bFirstReset, bResetAll);
//
// Input: hWnd - The dialog handle
// bFirstReset - TRUE means to fill the driver listbox
// bResetAll - TRUE means to repaint the entire dialog
// FALSE means to repaint alias information
//
// Return: None.
//
// Desc: Reset the "connect to the database" dialog based
// on the current driver selected.
//================================================================
void
reset_connect_dialog (HWND hWnd, BOOL bFirstReset, BOOL bResetAll)
{
hDBICur hList;
DBDesc DbData;
pFLDDesc pCfgInfo;
WORD ListIndex;
pCHAR pCfgRecBuf;
pCHAR Driver;
pCHAR Alias;
// Allocate resources
Alias = (pCHAR)malloc(DBIMAXSCFLDLEN);
Driver = (pCHAR)malloc(DBIMAXSCFLDLEN);
pCfgRecBuf = (pCHAR)malloc(DBIMAXSCRECSIZE);
pCfgInfo = (pFLDDesc) malloc(sizeof(FLDDesc) * DBIMAXSCFIELDS);
if (bFirstReset)
{
// Fill the listbox with the drivers available
SendDlgItemMessage(hWnd, IDL_DRIVERS, LB_RESETCONTENT, 0, 0);
if (DbiOpenDriverList(&hList) == DBIERR_NONE)
{
while (DbiGetNextRecord(hList, dbiNOLOCK, (pBYTE)Driver, NULL)
== DBIERR_NONE)
{
SendDlgItemMessage(hWnd, IDL_DRIVERS, LB_INSERTSTRING, 0,
(LPARAM) Driver);
}
DbiCloseCursor(&hList);
}
// Select the first item of the list boxes
SendDlgItemMessage(hWnd, IDL_DRIVERS, LB_SETCURSEL, 0, 0);
}
// Get the driver currently selected
ListIndex = (WORD) SendDlgItemMessage(hWnd, IDL_DRIVERS, LB_GETCURSEL,
0, 0);
SendDlgItemMessage(hWnd, IDL_DRIVERS, LB_GETTEXT, (WPARAM) ListIndex,
(LPARAM) Driver);
// Reset the driver to "STANDARD" if Paradox or dBASE
if ((strcmp(Driver, szDBASE) == GOOD_STR_COMPARE) ||
(strcmp(Driver, szPARADOX) == GOOD_STR_COMPARE))
{
strcpy(Driver, "STANDARD");
}
// Leave the alias list alone if not resetting the listbox
if (bResetAll)
{
// Reset info displayed (based on the driver type)
if (strcmp(Driver, "STANDARD") == GOOD_STR_COMPARE)
{
// Remove the user name & password if alias is STANDARD
ShowWindow(GetDlgItem(hWnd, IDE_PASSWORD), SW_HIDE);
ShowWindow(GetDlgItem(hWnd, IDT_PASSWORD_HDR), SW_HIDE);
}
else
{
// Make sure all is displayed
ShowWindow(GetDlgItem(hWnd, IDE_PASSWORD), SW_SHOW);
ShowWindow(GetDlgItem(hWnd, IDT_PASSWORD_HDR), SW_SHOW);
}
// Clear & fill the alias listbox
SendDlgItemMessage(hWnd, IDL_ALIASES, LB_RESETCONTENT, 0, 0);
if (DbiOpenDatabaseList(&hList) == DBIERR_NONE)
{
// Scan the list of aliases for matching drivers
while (DbiGetNextRecord(hList, dbiNOLOCK, (pBYTE) &DbData,
NULL) == DBIERR_NONE)
{
if (strcmp(DbData.szDbType, Driver) == GOOD_STR_COMPARE)
{
SendDlgItemMessage(hWnd, IDL_ALIASES, LB_INSERTSTRING,
0, (LPARAM) DbData.szName);
}
}
DbiCloseCursor(&hList);
SendDlgItemMessage(hWnd, IDL_ALIASES, LB_SETCURSEL, 0, 0);
}
}
// Reset the connection results list box
SendDlgItemMessage(hWnd, IDL_RESULTS, LB_RESETCONTENT, 0, 0);
// Don't forget to free up resources
free(Alias);
free(Driver);
free(pCfgRecBuf);
free((pCHAR) pCfgInfo);
}
//===============================================================
// Name: try_to_connect(hWnd);
//
// Input: hWnd - The dialog handle
//
// Return: None.
//
// Desc: Try to connect to a database based on the data
// selected in the main window.
//================================================================
void
try_to_connect (HWND hWnd)
{
hDBIDb hDb;
DBIResult rslt;
DBIErrInfo ErrInfo;
WORD ListIndex;
CHAR Msg[DBIMAXMSGLEN+1];
pCHAR Driver;
pCHAR Alias;
pCHAR Password;
// Init the strings
SetCursor(hWait);
Alias = (pCHAR)malloc(DBIMAXSCFLDLEN);
Driver = (pCHAR)malloc(DBIMAXSCFLDLEN);
Password = (pCHAR)malloc(DBIMAXSCFLDLEN);
Alias[0] = '\0';
Driver[0] = '\0';
Password[0] = '\0';
// Get the selected driver
ListIndex = (WORD) SendDlgItemMessage(hWnd, IDL_DRIVERS, LB_GETCURSEL,
0, 0);
SendDlgItemMessage(hWnd, IDL_DRIVERS, LB_GETTEXT, (WPARAM) ListIndex,
(LPARAM) Driver);
// Reset the driver type to NULL if standard database
if ((strcmp(Driver, szDBASE) == GOOD_STR_COMPARE) ||
(strcmp(Driver, szPARADOX) == GOOD_STR_COMPARE))
{
Driver[0] = '\0';
}
else // SQL database...
{
// SQL database needs the alias & password
ListIndex =
(WORD) SendDlgItemMessage(hWnd, IDL_ALIASES, LB_GETCURSEL, 0,
0);
SendDlgItemMessage(hWnd, IDL_ALIASES, LB_GETTEXT, (WPARAM)
ListIndex, (LPARAM) Alias);
SendDlgItemMessage(hWnd, IDE_PASSWORD, WM_GETTEXT, 80,
(LPARAM) Password);
}
// Try to open the database
hDb = NULL;
SendDlgItemMessage(hWnd, IDL_RESULTS, LB_RESETCONTENT, 0, 0);
rslt = DbiOpenDatabase(Alias, Driver, dbiREADWRITE, dbiOPENSHARED,
Password, 0, NULL, NULL, &hDb);
if (rslt == DBIERR_NONE)
{
DbiCloseDatabase(&hDb);
SendDlgItemMessage(hWnd, IDL_RESULTS, LB_ADDSTRING, 0,
(LPARAM) "Connection is available!");
}
else
{
// Failed to connect
DbiGetErrorInfo(TRUE, &ErrInfo);
SendDlgItemMessage(hWnd, IDL_RESULTS, LB_ADDSTRING, 0,
(LPARAM) "ERROR - Failed to connect");
wsprintf(Msg, " Error Category = %d Error Code = %d",
ErrCat(rslt), ErrCode(rslt));
SendDlgItemMessage(hWnd, IDL_RESULTS, LB_ADDSTRING, 0,
(LPARAM)Msg);
if (ErrInfo.szErrCode[0] != '\0')
{
wsprintf(Msg, " -> ErrCode: %s", ErrInfo.szErrCode);
SendDlgItemMessage(hWnd, IDL_RESULTS, LB_ADDSTRING, 0,
(LPARAM)Msg);
}
if (ErrInfo.szContext1[0] != '\0')
{
wsprintf(Msg, " -> Context1: %s", ErrInfo.szContext1);
SendDlgItemMessage(hWnd, IDL_RESULTS, LB_ADDSTRING, 0,
(LPARAM)Msg);
}
if (ErrInfo.szContext2[0] != '\0')
{
wsprintf(Msg, " -> Context2: %s", ErrInfo.szContext2);
SendDlgItemMessage(hWnd, IDL_RESULTS, LB_ADDSTRING, 0,
(LPARAM)Msg);
}
if (ErrInfo.szContext3[0] != '\0')
{
wsprintf(Msg, " -> Context3: %s", ErrInfo.szContext3);
SendDlgItemMessage(hWnd, IDL_RESULTS, LB_ADDSTRING, 0,
(LPARAM)Msg);
}
if (ErrInfo.szContext4[0] != '\0')
{
wsprintf(Msg, " -> Context4: %s", ErrInfo.szContext4);
SendDlgItemMessage(hWnd, IDL_RESULTS, LB_ADDSTRING, 0,
(LPARAM)Msg);
}
}
// Free up resources
free(Alias);
free(Driver);
free(Password);
SetCursor(hArrow);
}
//==============================================================
// Name: MainWndProc(hWnd, msg, wParam, lParam);
//
// Desc: This routine will process all messaged for
// the primary application window. Included in this are all
// menu commands.
//==============================================================
long FAR PASCAL _export
MainWndProc (HWND hWnd, UINT msg, UINT wParam, LONG lParam)
{
HWND hFocus;
FARPROC lpTempProc;
INT32 ret = FALSE;
HWND hwnd;
switch (msg)
{
case WM_CREATE:
PostMessage(hWnd, WM_COMMAND, ID_SUBCLASS, NULL);
ShowWindow(hWnd, FALSE);
break;
case WM_CTLCOLOR:
return (long)(WORD)Ctl3dCtlColorEx(msg, wParam, lParam);
case WM_SYSCOLORCHANGE:
Ctl3dColorChange();
break;
case WM_SETFOCUS:
SetFocus(GetDlgItem(hWnd, IDL_DRIVERS));
case WM_COMMAND:
hFocus = GetFocus();
switch(wParam)
{
case IDL_DRIVERS:
if (HIWORD(lParam) == LBN_SELCHANGE)
{
reset_connect_dialog(hWnd, FALSE, TRUE);
}
break;
case IDL_ALIASES:
if (HIWORD(lParam) == LBN_SELCHANGE)
{
reset_connect_dialog(hWnd, FALSE, FALSE);
}
break;
case IDM_ABOUT:
lpTempProc = MakeProcInstance((FARPROC) About, hInst);
DialogBox(hInst, "About", hMainWnd, (DLGPROC)lpTempProc);
FreeProcInstance((FARPROC) lpTempProc);
break;
case IDOK:
try_to_connect(hWnd);
break;
case ID_SUBCLASS:
// Can't do this within WM_CREATE
hwnd = GetWindow(hWnd, GW_CHILD);
while (hwnd != NULL)
{
Ctl3dSubclassCtl(hwnd);
hwnd = GetWindow(hwnd, GW_HWNDNEXT);
}
// Set a width for the horrizontal scroll bar
SendMessage(GetDlgItem(hWnd, IDL_RESULTS),
LB_SETHORIZONTALEXTENT,
2000, NULL);
ShowWindow(hWnd, TRUE);
break;
case IDCANCEL:
PostQuitMessage(0);
break;
default:
ret = DefWindowProc(hWnd, msg, wParam, lParam);
break;
}
SetFocus(hFocus);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
ret = DefWindowProc(hWnd, msg, wParam, lParam);
break;
}
return ret;
}
//==============================================================
// Name: About(hDlg, msg, wParam, lParam);
//
// Desc: This routine will process all I/O for the
// ABOUT dialog.
//==============================================================
BOOL FAR PASCAL _export
About (HWND hDlg, WORD msg, WORD wParam, LONG lParam)
{
int ret = FALSE;
switch (msg)
{
case WM_COMMAND:
switch (wParam)
{
case IDOK:
case IDCANCEL:
// Avoid warning re: parameter not used
lParam = lParam;
EndDialog(hDlg, TRUE);
ret = TRUE;
break;
}
break;
}
return ret;
}