File: interruptpoly.c

package info (click to toggle)
polyml 5.2.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 19,692 kB
  • ctags: 17,567
  • sloc: cpp: 37,221; sh: 9,591; asm: 4,120; ansic: 428; makefile: 203; ml: 191; awk: 91; sed: 10
file content (93 lines) | stat: -rw-r--r-- 2,770 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
    Title:      Windows application to send an interrupt to Poly
    Copyright (c) 2003
        David C.J. Matthews

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.
    
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.
    
    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/

/*
   This program generates an interrupt Windows Poly/ML program in a similar
   way to sending a SIGINT (Control-C) interrupt in Unix. 
*/

#include <windows.h>
#include <ddeml.h>

// DDE Commands.
#define INTERRUPT_POLY  "[Interrupt]"
#define TERMINATE_POLY  "[Terminate]"

// Default DDE service name.
#define POLYMLSERVICE   "PolyML"


DWORD dwDDEInstance;


// DDE Callback function.
HDDEDATA CALLBACK DdeCallBack(UINT uType, UINT uFmt, HCONV hconv,
                              HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
                              DWORD dwData1, DWORD dwData2)
{
    return (HDDEDATA) NULL; 
}

void SendDDEMessage(LPCTSTR lpszMessage)
{
    HCONV hcDDEConv;
    HDDEDATA res;
    // Send a DDE message to the process.
    DWORD dwInst = dwDDEInstance;
    HSZ hszServiceName =
        DdeCreateStringHandle(dwInst, POLYMLSERVICE, CP_WINANSI);

    hcDDEConv =
        DdeConnect(dwInst, hszServiceName, hszServiceName, NULL); 
    DdeFreeStringHandle(dwInst, hszServiceName);
    res =
        DdeClientTransaction((LPBYTE)lpszMessage, sizeof(INTERRUPT_POLY),
            hcDDEConv, 0L, 0, XTYP_EXECUTE, TIMEOUT_ASYNC, NULL);
    if (res) DdeFreeDataHandle(res);
}

// Interrupt the ML process as though control-C had been pressed.
void RunInterrupt() 
{
    SendDDEMessage(INTERRUPT_POLY);
}


int WINAPI WinMain(
  HINSTANCE hInstance,  // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,      // pointer to command line
  int nCmdShow          // show state of window
)
{
    // Initialise DDE.  We only want to be a client.
    DdeInitialize(&dwDDEInstance, DdeCallBack,
        APPCMD_CLIENTONLY | CBF_SKIP_CONNECT_CONFIRMS | CBF_SKIP_DISCONNECTS, 0);

    RunInterrupt();

    DdeNameService(dwDDEInstance, 0L, 0L, DNS_UNREGISTER);

    // Unitialise DDE.
    DdeUninitialize(dwDDEInstance);

    return 0;
}