Skip to content

Commit e94b273

Browse files
committed
add samples
1 parent bb60751 commit e94b273

25 files changed

+3589
-0
lines changed

samples/all.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
# Little shell script to compile, link, and run all the samples.
3+
# Use dmd2\windows\bin\shell.exe to execute.
4+
5+
DMD=..\..\windows\bin\dmd
6+
DFLAGS=
7+
CLEAN=clean.bat
8+
9+
10+
11+
#~ $(DMD) chello $(DFLAGS) # which compilation flags?
12+
#~ chello
13+
14+
$(DMD) d2html $(DFLAGS)
15+
d2html d2html.d
16+
17+
$(DMD) dhry $(DFLAGS)
18+
dhry
19+
20+
$(DMD) hello $(DFLAGS)
21+
hello
22+
23+
#~ $(DMD) htmlget $(DFLAGS) # broken
24+
25+
#~ $(DMD) listener $(DFLAGS) # broken
26+
27+
28+
$(DMD) pi $(DFLAGS)
29+
pi 1000
30+
31+
$(DMD) sieve $(DFLAGS)
32+
sieve
33+
34+
$(DMD) wc $(DFLAGS)
35+
wc wc.d
36+
37+
$(DMD) wc2 $(DFLAGS)
38+
wc2 wc2.d
39+
40+
$(DMD) winsamp gdi32.lib winsamp.def
41+
winsamp
42+
43+
$(CLEAN)
44+
45+
#~ broken:
46+
# COM client/server example
47+
#~ $(DMD) -c dserver -release $(DFLAGS)
48+
#~ $(DMD) -c chello $(DFLAGS)
49+
#~ $(DMD) dserver.obj chello.obj uuid.lib ole32.lib advapi32.lib kernel32.lib user32.lib dserver.def -L/map
50+
#~ $(DMD) dclient $(DFLAGS) ole32.lib uuid.lib

samples/build.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
..\..\windows\bin\shell all.sh

samples/chello.d

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
2+
/* Server for IHello
3+
* Heavily modified from:
4+
*/
5+
/*
6+
* SELFREG.CPP
7+
* Server Self-Registrtation Utility, Chapter 5
8+
*
9+
* Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
10+
*
11+
* Kraig Brockschmidt, Microsoft
12+
* Internet : [email protected]
13+
* Compuserve: >INTERNET:[email protected]
14+
*/
15+
16+
// From an example from "Inside OLE" Copyright Microsoft
17+
18+
import std.c.stdio;
19+
import std.c.stdlib;
20+
import std.string;
21+
import std.c.windows.windows;
22+
import std.c.windows.com;
23+
24+
GUID CLSID_Hello = { 0x30421140, 0, 0, [0xC0, 0, 0, 0, 0, 0, 0, 0x46] };
25+
GUID IID_IHello = { 0x00421140, 0, 0, [0xC0, 0, 0, 0, 0, 0, 0, 0x46] };
26+
27+
interface IHello : IUnknown
28+
{
29+
extern (Windows) :
30+
int Print();
31+
}
32+
33+
// Type for an object-destroyed callback
34+
alias void (*PFNDESTROYED)();
35+
36+
/*
37+
* The class definition for an object that singly implements
38+
* IHello in D.
39+
*/
40+
class CHello : ComObject, IHello
41+
{
42+
protected:
43+
IUnknown m_pUnkOuter; // Controlling unknown
44+
45+
PFNDESTROYED m_pfnDestroy; // To call on closure
46+
47+
/*
48+
* pUnkOuter LPUNKNOWN of a controlling unknown.
49+
* pfnDestroy PFNDESTROYED to call when an object
50+
* is destroyed.
51+
*/
52+
public this(IUnknown pUnkOuter, PFNDESTROYED pfnDestroy)
53+
{
54+
m_pUnkOuter = pUnkOuter;
55+
m_pfnDestroy = pfnDestroy;
56+
}
57+
58+
~this()
59+
{
60+
MessageBoxA(null, "CHello.~this()", null, MB_OK);
61+
}
62+
63+
extern (Windows) :
64+
/*
65+
* Performs any intialization of a CHello that's prone to failure
66+
* that we also use internally before exposing the object outside.
67+
* Return Value:
68+
* BOOL true if the function is successful,
69+
* false otherwise.
70+
*/
71+
72+
public:
73+
BOOL Init()
74+
{
75+
MessageBoxA(null, "CHello.Init()", null, MB_OK);
76+
return true;
77+
}
78+
79+
public:
80+
HRESULT QueryInterface(const (IID)*riid, LPVOID *ppv)
81+
{
82+
MessageBoxA(null, "CHello.QueryInterface()", null, MB_OK);
83+
84+
if (IID_IUnknown == *riid)
85+
*ppv = cast(void*) cast(IUnknown) this;
86+
else if (IID_IHello == *riid)
87+
*ppv = cast(void*) cast(IHello) this;
88+
else
89+
{
90+
*ppv = null;
91+
return E_NOINTERFACE;
92+
}
93+
94+
AddRef();
95+
return NOERROR;
96+
}
97+
98+
ULONG Release()
99+
{
100+
MessageBoxA(null, "CHello.Release()", null, MB_OK);
101+
102+
if (0 != --count)
103+
return count;
104+
105+
/*
106+
* Tell the housing that an object is going away so it can
107+
* shut down if appropriate.
108+
*/
109+
MessageBoxA(null, "CHello Destroy()", null, MB_OK);
110+
111+
if (m_pfnDestroy)
112+
(*m_pfnDestroy)();
113+
114+
// delete this;
115+
return 0;
116+
}
117+
118+
// IHello members
119+
HRESULT Print()
120+
{
121+
MessageBoxA(null, "CHello.Print()", null, MB_OK);
122+
return NOERROR;
123+
}
124+
}

samples/clean.bat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@echo off
2+
setlocal EnableDelayedExpansion
3+
del *.obj
4+
del *.map
5+
del *.res

0 commit comments

Comments
 (0)