annotate R/scratch/callbacks.R @ 34:2682a627168c

- breaking changes: * restrict 'Z' conversions to immutable types * restrict 'p' to mutable types (and handles)
author Tassilo Philipp
date Sun, 12 Apr 2020 19:37:37 +0200
parents 0cfcc391201f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 dynbind("user32","RegisterClassEx(p)p;")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 C.struct <- function(signature) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 map <- strsplit(signature,'[; \t\n]+')[[1]]
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8 if (map[1] == "")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9 map <- map[-1]
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 n <- length(map)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 types <- map[seq(1,n,by=2)]
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 ids <- map[seq(2,n,by=2)]
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 sizes <- C.sizes[types]
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 offsets <- c(0,cumsum(sizes))
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 ids <- c(ids,".sizeof")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 types <- c(types,"")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 sizes <- c(sizes,"")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 data.frame(
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 id=ids,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 type=types,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 size=sizes,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 offset=offsets,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23 row.names=1
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 WNDCLASSEX <- "
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 UINT cbSize;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 UINT style;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 WNDPROC lpfnWndProc;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 int cbClsExtra;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 int cbWndExtra;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33 HINSTANCE hInstance;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34 HICON hIcon;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35 HCURSOR hCursor;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
36 HBRUSH hbrBackground;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37 LPCTSTR lpszMenuName;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38 LPCTSTR lpszClassName;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39 HICON hIconSm;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40 "
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42 WNDCLASSEX <- C.struct("
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43 UINT cbSize;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44 UINT style;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45 WNDPROC lpfnWndProc;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46 int cbClsExtra;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47 int cbWndExtra;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48 HINSTANCE hInstance;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
49 HICON hIcon;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50 HCURSOR hCursor;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51 HBRUSH hbrBackground;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52 LPCTSTR lpszMenuName;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53 LPCTSTR lpszClassName;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54 HICON hIconSm;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55 ")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
56
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57 library(rdyncall)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59 allocC <- function(info)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 x <- malloc(sizeof(info))
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62 attr(x, "cstruct") <- info
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63 class(x) <- "cstruct"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 return(x)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
65 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
66
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67 packC <- function( address, offset, type, value )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
72
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
73 "$.Cstruct<-" <- function (cstruct, name, value)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
74 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75 info <- attr(x, "cstruct")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76 element <- info[name,]
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
77 packC( cstruct, element$offset, sigchar(element$type), value )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
78 return(value)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
79 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
80
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
81 winclass <- allocC(WNDCLASS)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
82 winclass$cbSize <- sizeofC(WNDCLASS)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
83 RegisterClassEx(winclass)