Skip to main content

Create and Use DLL's in D Mars Digital

This is a DLL written in the D Digital Mars language.

Also, there is a main D Digtal Mars class which invokes methods in the DLL, made with the D Digital
Mars language.

The source code to the whole project is included here, including the build file which is a batch file.

The Tango Library is in a serparate directory that the project file folders. A bit of reverse engineering will need to be done from the build.bat file to place all the files in the correct locations :(

The code is also available from http://code.google.com/p/tsglobalvariable/

I've remembered to include the sc.ini file for configuring the DMD and Tango libraries.


module dll.Dll;

import tango.sys.win32.Types;
import tango.io.Stdout;

// The core DLL init code.
extern (C) bool  rt_init( void delegate( Exception ) dg = null );
extern (C) bool  rt_term( void delegate( Exception ) dg = null ); 

HINSTANCE g_hInst;

extern (Windows)
BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved)
{
switch (ulReason)
{
case DLL_PROCESS_ATTACH:
rt_init();
break;

case DLL_PROCESS_DETACH:
rt_term();
break;

case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
// Multiple threads not supported yet
return false;
}
g_hInst=hInstance;
return true;
}



module dll.Exported;

import tango.math.Math;
import tango.io.digest.Crc32;
import tango.stdc.stringz;
import tango.text.convert.Float;
import tango.core.sync.Mutex;

import dll.Interface;

export extern(Windows) void setDouble(char * cWorkspace, double value )
{

char[] workspaceName = fromStringz(cWorkspace);

Invoke.setDouble(workspaceName, value);
}

export extern(Windows) double getDouble(char * cWorkspace )
{
//
// a bad value..to look for from out calling client
//
double value = -999.999;

//
// if date and time equal -1 then use only the index value
// to return back a value
//

char[] workspaceName = fromStringz(cWorkspace);

value = Invoke.getDouble(workspaceName);

return value;
}



LIBRARY simple.dll
DESCRIPTION  'Terry - global variable dll'

EXETYPE NT
SUBSYSTEM WINDOWS
CODE SHARED EXECUTE
DATA WRITE

EXPORTS
getDouble @1
setDouble @2



module dll.Interface;


class Invoke
{    
public static char[] name;
public static double value = 0.0;

public static void setDouble(char [] workspace,  double value)
{
Invoke.name = workspace;
Invoke.value = value;
}

public static double getDouble(char [] workspace)
{  
return Invoke.value;
}   


}




module client.CallDLL;

import tango.io.Stdout;

extern(C)
{
void setDouble(char * workspace,  double value);
double getDouble(char * workspace );
}

void main() 
{    
Stdout("hello world..5").newline;
setDouble("hello", 5);
auto val = getDouble("hello");

Stdout.formatln("hey now..{}", val );


}


rem
rem build.bat
rem description: generates a dll 
rem

set tangoLib= C:\tango\lib\gdi32.lib
set tangoLib= %tangoLib% C:\tango\lib\kernel32.lib
set tangoLib= %tangoLib% C:\tango\lib\libbz2.lib
set tangoLib= %tangoLib% C:\tango\lib\shell32.lib
set tangoLib= %tangoLib% C:\tango\lib\snn.lib
set tangoLib= %tangoLib% C:\tango\lib\tango-base-dmd.lib
set tangoLib= %tangoLib% C:\tango\lib\tango-base-dmd-d.lib
set tangoLib= %tangoLib% C:\tango\lib\tango-user-dmd.lib
set tangoLib= %tangoLib% C:\tango\lib\tango-win32-dmd.lib
set tangoLib= %tangoLib% C:\tango\lib\user32.lib
set tangoLib= %tangoLib% C:\tango\lib\ws2_32.lib
set tangoLib= %tangoLib% C:\tango\lib\zlib.lib


set dllFiles= dll\globalVariable.def 
set dllFiles= %dllFiles% dll\Dll.d
set dllFiles= %dllFiles% dll\Exported.d
set dllFiles= %dllFiles% dll\Interface.d

set clientFiles= client\CallDLL.d 



rem
rem build the dll
rem
C:\tango\bin\dmd.exe -ofsimple.dll %dllFiles% %tangoLib%

rem 
rem create library to import into D code
rem
tools\dm\bin\implib.exe /s simple.lib simple.dll

rem
rem build the dll test client
rem
C:\tango\bin\dmd.exe -ofclient.exe %clientFiles% simple.lib %tangoLib%  




[Version]
version=7.51 Build 020

[Environment]
LIB="C:\tango\lib"
DFLAGS="-IC:\tango\import" -version=Tango -defaultlib=tango-base-dmd.lib -debuglib=tango-base-dmd-d.lib
LINKCMD=C:\tango\bin\link.exe

Comments

Popular posts from this blog

clonezilla - creating a wifi ad-hoc hotspot and running a ssh server

Here are some notes on connecting to a wifi-hotspot from a running clonezilla
live-cd.

[ target machine to save a backup hard-disk clone/image ]
[ target machine is also running a wifi hotspot and an ssh server ]
Ubuntu 11.04 - Natty Narwhal

terry@terry-HP:~$ uname -a
Linux terry-HP 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
terry@terry-HP:~$

[ Creating an 'ad-hoc' wifi spot ]
Click the 'up down arrow' icon ( or what have you )


[ choose menu item to create a wifi ad-hoc hotspot ]

[ create the ad-hoc wifi hotspot ]

[ the eth1 connection is the created ad-hoc network with an essid of 'terry' ]

[ the ad-hoc wifi hotspot is now visible on the 'host' computer and other computer as well now ]

[ enter the following on the machine being cloned with clonezilla
[ at the appropriate place in the clonezilla backup image step ]
terry@terry-HP:~$ ip link set wlan0 down
terry@terry-HP:~$ iwconfig wlan0 mode ad-hoc
terry@…

Translators, maps, conduits, and containers

Interpreters
The Amiga had a hardware emulator which transformed instruction to instruction to a dedicated x86 hardware interpreter in the Amiga could run Microsoft DOS spreadsheet programs in the Amiga OS.

MS-DOS on Amiga via Sidecar or Bridgeboard[edit]
MS-DOS compatibility was a major issue during the early years of the Amiga's lifespan in order to promote the machine as a serious business machine. In order to run the MS-DOS operating system, Commodore released the Sidecar for the Amiga 1000, basically a 8088 board in a closed case that connected to the side of the Amiga. Clever programming (a library named Janus, after the two-faced Roman god of doorways) made it possible to run PC software in an Amiga window without use of emulation. At the introduction of the Sidecar the crowd was stunned to see the MS-DOS version of Microsoft Flight Simulator running at full speed in an Amiga window on the Workbench.

Later the Sidecar was implemented on an expansion card named "Bridgebo…

Use Gwenview to upload images to picasaweb.google.com

Use Gwenview to upload images to https://picasaweb.google.com/

install the following KDE4 plugins:

terry@narwhal:~/download$ sudo apt-get install kipi-plugins
From Linux Clicks...
the Gwenview application...

From Linux Clicks...