APPENDIX B
Common PEN*KEY 6000 Series Information
B-6 PEN*KEY
R
6200/6300 Hand-Held Computer Programmer’s Reference Guide
Sample Programs
Charge Detection Demonstration Program
TESTCHRG is a C++ Windows program that demonstrates a method for accessĆ
ing NORAPM.DLL to get the existing charge status (tells you whether it is in
the dock or not). The program needs to include NORAPM.H. The sample proĆ
gram TESTCHRG.CPP is presented in the following pages.
// TESTCHRG.CPP: NorAPM charge detection test fixture v1.01.
// (C) Copyright 1994 by Norand Corporation
// **************************************************************
/* TESTCHRG.DEF
NAME TESTCHRG
DESCRIPTION ‘Tests NorAPM Charge Detection’
EXETYPE WINDOWS
STUB ‘WINSTUB.EXE’
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
HEAPSIZE 1024
STACKSIZE 8200
*/
#include <windows.h>
#include “norapm.h”
char szTitle[] = “TESTCHRG.EXE — 94.07.07.01”;
HINSTANCE hinstNorAPM;
// For storing NorAPM library instance.
tagPOWER_STATUS PwrStat;
// Holds current power status.
WORD Error;
// Holds error codes.
char MsgBuf[100];
// Message buffer
#pragma argsused
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow) {
// Turn off the “File not found” error box.
SetErrorMode(SEM_NOOPENFILEERRORBOX);
// Get handle to NORAPM.DLL driver
hinstNorAPM = LoadLibrary(”NORAPM.DLL”);
// Did we find the library?
if (hinstNorAPM > HINSTANCE_ERROR) {
// Get Entry point for GetPowerStatus()
fpGetPowerStatus lpfnGetPowerStatus = (fpGetPowerStatus)
GetProcAddress(hinstNorAPM, ”GetPowerStatus”);
if (lpfnGetPowerStatus) {
// Get and display charge state
do {
Error = lpfnGetPowerStatus(&PwrStat);
if (Error != PWR_OK) {
wsprintf(MsgBuf,
“GetPowerStatus() call failed with result of %d”, Error);
Error = MessageBox(NULL, MsgBuf, szTitle,
MB_RETRY MB_ICONEXCLAMATION);
} // then
else {
// Display battery status
wsprintf(MsgBuf, “A/C is %s line.\nBattery is %scharging\n”,
(char far *)
(PwrStat.LineStatus == 1 ? “on” : “off”),
(char far *)
(PwrStat.BatteryFlags & 8 ? “” : “NOT ”));
Error = MessageBox(NULL, MsgBuf, szTitle,
B. Common PEN*KEY
6000 Series Info.