Category : Files from Magazines
Archive   : DDJ9403A.ZIP
Filename : DOS2WIN.ASC

 
Output of file : DOS2WIN.ASC contained in archive : DDJ9403A.ZIP
_PORTING FROM DOS TO WINDOWS_
by Walter Oney

Listing One

/**********************************************************************/
/* CLIENT.C -- Database client program (Windows app). By Walter Oney */
/**********************************************************************/

#include
#include
#include
#include

static HINSTANCE hInst;

LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);

#define arraysize(p) (sizeof(p)/sizeof((p)[0]))
/**********************************************************************/
int NEAR PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrev,
LPSTR lpCmd, int nShow) // WinMain
{ HWND hwnd; // main window handle
MSG msg; // current message
WNDCLASS wc; // window class descriptor

if (hPrev) // only allow 1 instance at a time
return 0;
hInst = hInstance;
memset(&wc, 0, sizeof(wc));
wc.lpszClassName = "clientwindow";
wc.hInstance = hInstance;
wc.lpfnWndProc = MainWndProc;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);

wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
if (!RegisterClass(&wc))
return 0;
hwnd = CreateWindow("clientwindow", "WINGate Database Demonstration",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, 0, NULL, hInstance, NULL);
if (!hwnd)
return 0;
ShowWindow(hwnd, nShow);

while (GetMessage(&msg, 0, 0, 0))
{ // process messages
TranslateMessage(&msg);
DispatchMessage(&msg);
} // process messages end
return msg.wParam;
} // WinMain end
/**********************************************************************/
LRESULT CALLBACK MainWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{ // MainWndProc
static char *country[] =
{ "Afghanistan","Algeria","Angola","Argentina","Australia","Austria"
};
static HWND hwndList; // list of countries
static BOOL bRegistered; // TRUE if registered with WINGate
switch (msg) // process message
{ case WM_CREATE: // WM_CREATE
{ int i;
if (WGRegisterClient("client"))
{ // couldn't initialize WINGate
MessageBox(hwnd, "Unable to initialize WINGate", "ERROR",
MB_OK | MB_ICONHAND);
return -1;
} // couldn't initialize WINGate
bRegistered = TRUE;
hwndList = CreateWindow("listbox", "",
WS_CHILD | WS_VISIBLE | WS_VSCROLL | LBS_NOTIFY,
0, 0, 0, 0, hwnd, (HMENU) 100, hInst, NULL);
if (!hwndList)
return -1;
for (i = 0; i < arraysize(country); ++i)
ListBox_AddString(hwndList, country[i]);
break;
} // WM_CREATE end
case WM_SIZE:
{ RECT rc; // WM_SIZE
GetClientRect(hwnd, &rc);
if (hwndList)
MoveWindow(hwndList, rc.left, rc.top, rc.right-rc.left,
rc.bottom-rc.top, TRUE);
break;
} // WM_SIZE end
case WM_COMMAND:
switch (LOWORD(wParam)) // select on control id
{ case 100: // the list box

switch (HIWORD(lParam)) // select on notification code
{
case LBN_SELCHANGE: // LBN_SELCHANGE
{ char msgbuf[80]; // message assembly buffer
int i; // selection (country) index
char capital[80]; // response from server
WGTRANS trans; // query transaction
int code; // error code
long tid; // query transaction id
i = ListBox_GetCurSel(hwndList);
trans = WGCreateTrans("client", 80);
WGSetTransString(trans, country[i]);
WGSetTransValue(trans, 1, 1);
tid = WGExecute(trans, "server", 1000,
WG_STAT_WAIT_RESPONSE, &code);
WGGetResponse(trans, tid, WG_STAT_WAIT_RESPONSE);
WGGetTransString(trans, capital, sizeof(capital));
WGDestroyTrans(trans);
wsprintf(msgbuf, "The capital of %s is %s",
(LPSTR) country[i], (LPSTR) capital);
MessageBox(hwnd, msgbuf, "Geographical Information",
MB_OK | MB_ICONINFORMATION);
break;
} // LBN_SELCHANGE end
} // select on notification code end
} // select on control id end
break;
case WM_DESTROY:
if (bRegistered)
{ int code; // close out WINGate connection
WGTRANS trans = WGCreateTrans("client", 0);
WGSetTransValue(trans, 1, 0);
WGExecute(trans, "server", 1000, WG_STAT_NO_RESPONSE, &code);
WGDestroyTrans(trans);
WGUnregisterClient("client");
} // close out WINGate connection end
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
} // process message end
return 0;
} // MainWndProc end



Listing Two

/*********************************************************************/
/* SERVER.C -- DOS-based database server for WINGate demo. */
/* Written by Walter Oney */
/*********************************************************************/

#include
#include
#include

static void error(int code);


#define arraysize(p) (sizeof(p)/sizeof((p)[0]))
/*********************************************************************/
void main() // main
{ short code; // error code
if ((code = WGInit(0, 16384)))
error(code);
if ((code = WGRegisterServer("server", 1024, 0, 0)))
{ // can't register server
WGTerm();
error(code);
}
while (1) // until told to quit
{ WGTRANS trans = WGGetTrans();
if (trans) // process transaction
{ char country[80]; // name of country being queried
int i; // loop index
long tid; // transaction id
WGTRANS response; // response to query
static char *key[] =
{
"Afghanistan", "Algeria", "Angola", "Argentina",
"Australia", "Austria"
};
static char *value[] =
{
"Kabul", "Algiers", "Luanda", "Buenos Aires",
"Canberra", "Vienna"
};
tid = WGGetTransID(trans, &code);
if (WGGetTransValue(trans, 1, &code) == 0)
break; // error or "quit" request
WGGetTransString(trans, country, sizeof(country));
for (i = 0; i < arraysize(country); ++i)
if (strcmp(country, key[i]) == 0)
break; // found it
response = WGCreateTrans("server", strlen(value[i])+1);
WGSetTransString(response, value[i]);
WGPostResponse(response, tid);
WGDestroyTrans(response);
} // process transaction end
_asm // yield time slice
{ mov ax, 1680h
int 2Fh
} // yield time slice end
} // until told to quit
WGUnregisterServer("server");
WGTerm();
} // main end
/*********************************************************************/
static void error(int code)
{ // error
printf("WINGate error %d\n", code);
exit(1);
} // error end



Example 1:

WGTRANS trans = WGCreateTrans("client", 80);
WGSetTransString(trans, country[i]);
WGSetTransValue(trans, 1, 1);
long tid = WGExecute(trans, "server", 1000,
WG_STAT_WAIT_RESPONSE, &code);
WGGetResponse(trans, tid, WG_STAT_WAIT_RESPONSE);
WGGetTransString(trans, capital, sizeof(capital));

WGDestroyTrans(trans);


Example 2:

WGTRANS trans = WGGetTrans();
if (trans)
{ // process transaction
WGGetTransString(trans, country, sizeof(country));
... // [code that looks up capital city name]
WGTRANS response = WGCreateTrans("server",strlen(capital)+1);
WGSetTransString(response, capital);
long tid = WGGetTransID(trans, &code);
WGPostResponse(response, tid);
WGDestroyTrans(response);
}


Example 3:

(a)

C:\WINGATE>winspawn notepad
Execution OK ==> 11591

(b)

C:\WINGATE>winctrl -ms #11591 300 240 300 240
Execution OK ==> 0


(c)

C:\WINGATE>winkill #11591
Execution OK ==> 0



  3 Responses to “Category : Files from Magazines
Archive   : DDJ9403A.ZIP
Filename : DOS2WIN.ASC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/