How do I interface D to a C library based on a DLL?

Christopher Grantham cgrantham at gmail.com
Wed Jun 13 01:42:44 PDT 2007


Sorry, should have included the 'test.d' file...very n00bish, but its 
the most simple way to know the API library is working:

#!J:/dmd/bin/dmd.exe -run

import std.stdio;
import std.c.windows.windows;

import OrcFxAPI;

int main(char[][] args) {
	writefln("Hello World!");
	foreach(argv, argc; args) {
		writefln("Arg:\t%s",argv);
	}
	
	// if this works, then we are interfacing to the DLL successfully :)
	/*C_GetDLLVersion(TDLLVersion *lpRequiredDLLVersion,
                                                      TDLLVersion 
*lpDLLVersion,
                                                      int* lpOK,
                                                      int* lpStatus);
	*/
	TDLLVersion dll_ver;
	int lpOK, lpStatus;
	
	C_GetDLLVersion(null,&dll_ver,&lpOK,&lpStatus);
	writefln("Orcaflex DLL Version:\t%s",dll_ver);
	
	
	return 0;
}

As you can see, I'm assuming the converted header becomes a D module 
with the filename as the module name (minus the '.d' extension)...
I'm probably going about it all wrong or something, so feel free to 
correct me, I could use the constructive criticism...


More information about the Digitalmars-d-learn mailing list