Skip to content

Commit

Permalink
add samples
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jun 15, 2011
1 parent bb60751 commit e94b273
Show file tree
Hide file tree
Showing 25 changed files with 3,589 additions and 0 deletions.
50 changes: 50 additions & 0 deletions samples/all.sh
@@ -0,0 +1,50 @@

# Little shell script to compile, link, and run all the samples.
# Use dmd2\windows\bin\shell.exe to execute.

DMD=..\..\windows\bin\dmd
DFLAGS=
CLEAN=clean.bat



#~ $(DMD) chello $(DFLAGS) # which compilation flags?
#~ chello

$(DMD) d2html $(DFLAGS)
d2html d2html.d

$(DMD) dhry $(DFLAGS)
dhry

$(DMD) hello $(DFLAGS)
hello

#~ $(DMD) htmlget $(DFLAGS) # broken

#~ $(DMD) listener $(DFLAGS) # broken


$(DMD) pi $(DFLAGS)
pi 1000

$(DMD) sieve $(DFLAGS)
sieve

$(DMD) wc $(DFLAGS)
wc wc.d

$(DMD) wc2 $(DFLAGS)
wc2 wc2.d

$(DMD) winsamp gdi32.lib winsamp.def
winsamp

$(CLEAN)

#~ broken:
# COM client/server example
#~ $(DMD) -c dserver -release $(DFLAGS)
#~ $(DMD) -c chello $(DFLAGS)
#~ $(DMD) dserver.obj chello.obj uuid.lib ole32.lib advapi32.lib kernel32.lib user32.lib dserver.def -L/map
#~ $(DMD) dclient $(DFLAGS) ole32.lib uuid.lib
1 change: 1 addition & 0 deletions samples/build.bat
@@ -0,0 +1 @@
..\..\windows\bin\shell all.sh
124 changes: 124 additions & 0 deletions samples/chello.d
@@ -0,0 +1,124 @@

/* Server for IHello
* Heavily modified from:
*/
/*
* SELFREG.CPP
* Server Self-Registrtation Utility, Chapter 5
*
* Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Microsoft
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/

// From an example from "Inside OLE" Copyright Microsoft

import std.c.stdio;
import std.c.stdlib;
import std.string;
import std.c.windows.windows;
import std.c.windows.com;

GUID CLSID_Hello = { 0x30421140, 0, 0, [0xC0, 0, 0, 0, 0, 0, 0, 0x46] };
GUID IID_IHello = { 0x00421140, 0, 0, [0xC0, 0, 0, 0, 0, 0, 0, 0x46] };

interface IHello : IUnknown
{
extern (Windows) :
int Print();
}

// Type for an object-destroyed callback
alias void (*PFNDESTROYED)();

/*
* The class definition for an object that singly implements
* IHello in D.
*/
class CHello : ComObject, IHello
{
protected:
IUnknown m_pUnkOuter; // Controlling unknown

PFNDESTROYED m_pfnDestroy; // To call on closure

/*
* pUnkOuter LPUNKNOWN of a controlling unknown.
* pfnDestroy PFNDESTROYED to call when an object
* is destroyed.
*/
public this(IUnknown pUnkOuter, PFNDESTROYED pfnDestroy)
{
m_pUnkOuter = pUnkOuter;
m_pfnDestroy = pfnDestroy;
}

~this()
{
MessageBoxA(null, "CHello.~this()", null, MB_OK);
}

extern (Windows) :
/*
* Performs any intialization of a CHello that's prone to failure
* that we also use internally before exposing the object outside.
* Return Value:
* BOOL true if the function is successful,
* false otherwise.
*/

public:
BOOL Init()
{
MessageBoxA(null, "CHello.Init()", null, MB_OK);
return true;
}

public:
HRESULT QueryInterface(const (IID)*riid, LPVOID *ppv)
{
MessageBoxA(null, "CHello.QueryInterface()", null, MB_OK);

if (IID_IUnknown == *riid)
*ppv = cast(void*) cast(IUnknown) this;
else if (IID_IHello == *riid)
*ppv = cast(void*) cast(IHello) this;
else
{
*ppv = null;
return E_NOINTERFACE;
}

AddRef();
return NOERROR;
}

ULONG Release()
{
MessageBoxA(null, "CHello.Release()", null, MB_OK);

if (0 != --count)
return count;

/*
* Tell the housing that an object is going away so it can
* shut down if appropriate.
*/
MessageBoxA(null, "CHello Destroy()", null, MB_OK);

if (m_pfnDestroy)
(*m_pfnDestroy)();

// delete this;
return 0;
}

// IHello members
HRESULT Print()
{
MessageBoxA(null, "CHello.Print()", null, MB_OK);
return NOERROR;
}
}
5 changes: 5 additions & 0 deletions samples/clean.bat
@@ -0,0 +1,5 @@
@echo off
setlocal EnableDelayedExpansion
del *.obj
del *.map
del *.res

0 comments on commit e94b273

Please sign in to comment.