Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move dmd samples here #58

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ Some individual functions have been moved here rather than full Phobos modules.

* undead.doformat: Contains the `doFormat` function from std.format
* undead.string: Contains regex style pattern matching functions from std.string

The dmdsamples folder contains a list of code samples which used to be located
in the dmd installation directory, but which have not been kept up to date, so
they are now located here as well.

15 changes: 15 additions & 0 deletions dmdsamples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.d.htm
*.exe
chello
dclient
dserver
d2html
dhry
hello
htmlget
listener
pi
sieve
wc
wc2
winsamp
49 changes: 49 additions & 0 deletions dmdsamples/all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

# Little shell script to compile, link, and run all the samples.
# Use dmd\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

# COM client/server example
$(DMD) dserver.d chello.d dserver.def advapi32.lib ole32.lib user32.lib
# dclient will fail unless run with administrator rights
$(DMD) dclient $(DFLAGS) ole32.lib uuid.lib
dclient

$(CLEAN)
1 change: 1 addition & 0 deletions dmdsamples/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
..\..\windows\bin\shell all.sh
124 changes: 124 additions & 0 deletions dmdsamples/chello.d
Original file line number Diff line number Diff line change
@@ -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 : [email protected]
* Compuserve: >INTERNET:[email protected]
*/

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

import core.stdc.stdio;
import core.stdc.stdlib;
import std.string;
import core.sys.windows.com;
import core.sys.windows.windef;

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 function() 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()
{
printf("CHello.~this()\n");
}

extern (Windows) :
/*
* Performs any initialization 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()
{
printf("CHello.Init()\n");
return true;
}

public:
override HRESULT QueryInterface(const (IID)*riid, LPVOID *ppv)
{
printf("CHello.QueryInterface()\n");

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;
}

override ULONG Release()
{
printf("CHello.Release()\n");

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

/*
* Tell the housing that an object is going away so it can
* shut down if appropriate.
*/
printf("CHello Destroy()\n");

if (m_pfnDestroy)
(*m_pfnDestroy)();

// delete this;
return 0;
}

// IHello members
override HRESULT Print()
{
printf("CHello.Print()\n");
return NOERROR;
}
}
4 changes: 4 additions & 0 deletions dmdsamples/clean.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off
setlocal EnableDelayedExpansion
del *.obj
del *.res
Loading
Loading