#include <windows.h>
#include <stdio.h>
int opt_chan;
char opt_dir[1000];
HWND CreateHideWindow(void);
int main(int argc, char **argv)
{
int i, h, stat;
int evType, evSize, evIntData, evUpdateCountData;
HWND hwnd;
char scriptfile[1000];
unsigned char data[64];
opt_chan = 0;
opt_dir[0] = 0;
for (i=1; i<argc; i++) {
int tmp;
char c;
char tmpS[1000];
if (sscanf(argv[i], "-chan=%d%c", &tmp, &c) == 1) {
opt_chan = tmp;
} else if (sscanf(argv[i], "-scriptdir=%s", tmpS) == 1) {
strcpy(opt_dir, tmpS);
}
}
if (h < 0) {
fprintf(stderr, "canOpenChannel failed, stat=%d\n", h);
exit(1);
}
scriptfile[0] = '\0';
if (strlen(opt_dir) > 0) {
strcpy(scriptfile, opt_dir);
strcat(scriptfile, "\\");
}
strcat(scriptfile, "test1.txe");
if (stat < 0) {
fprintf(stderr, "kvScriptLoadFile(%s) failed, stat=%d\n", scriptfile, stat);
exit(1);
}
if (stat < 0) {
fprintf(stderr, "kvScriptStart failed, stat=%d\n", stat);
exit(1);
}
hwnd = CreateHideWindow();
if (stat < 0) {
fprintf(stderr, "canSetNotify failed, stat=%d\n", stat);
}
if (h_evInt < 0) {
fprintf(stderr, "kvScriptEnvvarOpen(evInt) failed, stat=%lld\n", h_evInt);
exit(1);
}
fprintf(stderr, "Suspect type, assumed int (1) got %d\n", evType);
}
if (evSize != (signed)sizeof(int)) {
fprintf(stderr, "Suspect size, assumed 4 got %d\n", evSize);
}
if (h_evUpdateCount < 0) {
fprintf(stderr, "kvScriptEnvvarOpen(updateCount) failed, stat=%lld\n", h_evUpdateCount);
exit(1);
}
fprintf(stderr, "Suspect type, assumed int (1) got %d\n", evType);
}
if (evSize != (signed)sizeof(int)) {
fprintf(stderr, "Suspect size, assumed 4 got %d\n", evSize);
}
evIntData = 12345;
for (i=0; i<100; i++) {
for (;;) {
MSG hWnd_msg;
if (PeekMessage(&hWnd_msg, hwnd, 0, 0, TRUE) != 0) {
TranslateMessage(&hWnd_msg);
DispatchMessage(&hWnd_msg);
} else
break;
}
if (stat < 0) {
fprintf(stderr, "kvScriptEnvvarSetData failed, stat=%d\n", stat);
exit(1);
}
if (stat < 0) {
fprintf(stderr, "kvScriptEnvvarGetData failed, stat=%d\n", stat);
exit(1);
}
if (stat < 0) {
fprintf(stderr, "kvScriptEnvvarGetData failed (second), stat=%d\n", stat);
exit(1);
}
printf("evIntData=%d\n", evIntData);
printf("evUpdateCountData=%d\n", evUpdateCountData);
}
if (h_evBigOne < 0) {
fprintf(stderr, "kvScriptEnvvarOpen(evBigOne) failed, stat=%lld\n", h_evBigOne);
exit(1);
}
if (h_evChecksum < 0) {
fprintf(stderr, "kvScriptEnvvarOpen(evChecksum) failed, stat=%lld\n", h_evChecksum);
exit(1);
}
for (i=0; i<64; i++) {
data[i] = i;
}
if (stat < 0) {
fprintf(stderr, "kvScriptEnvvarSetData failed, stat=%d\n", stat);
exit(1);
}
evIntData = 0;
if (stat < 0) {
fprintf(stderr, "kvScriptEnvvarGetData failed, stat=%d\n", stat);
exit(1);
}
printf("Checksum=%d (expected %d)\n", evIntData, 63*64/2);
if (stat < 0) {
fprintf(stderr, "kvScriptEnvvarClose(1) failed, stat=%d\n", stat);
exit(1);
}
if (stat < 0) {
fprintf(stderr, "kvScriptEnvvarClose(2) failed, stat=%d\n", stat);
exit(1);
}
if (stat < 0) {
fprintf(stderr, "kvScriptEnvvarClose(3) failed, stat=%d\n", stat);
exit(1);
}
if (stat < 0) {
fprintf(stderr, "kvScriptEnvvarClose(4) failed, stat=%d\n", stat);
exit(1);
}
if (stat < 0) {
fprintf(stderr, "kvScriptStop failed, stat=%d\n", stat);
exit(1);
}
if (stat < 0) {
fprintf(stderr, "kvScriptUnload failed, stat=%d\n", stat);
exit(1);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
WORD canEVENT = LOWORD(lParam);
printf("Tallyho!\n");
switch (canEVENT)
{
printf("CAN message sent\n");
break;
printf("CAN message received\n");
break;
printf("CAN message received\n");
break;
printf("CAN message received\n");
break;
printf("Envvar updated\n");
break;
default:
printf("Unknown event %d\n", canEVENT);
break;
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
HWND CreateHideWindow(void)
{
WNDCLASS window;
HWND windowHandle;
memset(&window, 0, sizeof(WNDCLASS));
window.lpszClassName = "Accept Window";
window.lpfnWndProc = (WNDPROC) WindowProc;
if (!RegisterClass(&window)) {
fprintf(stderr, "Registerclass failed, stat=%d\n", GetLastError());
return NULL;
}
windowHandle = CreateWindow(window.lpszClassName,
window.lpszClassName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
(HWND) NULL,
(HMENU) NULL,
(HINSTANCE) NULL,
(LPVOID) NULL);
if (windowHandle == NULL) {
fprintf(stderr, "CreateWindow failed, stat=%d\n", GetLastError());
return NULL;
}
return windowHandle;
}