+
+static
+DH_MODULE DH_LoadLibrary_wrk ( DH_LPCSTR modname )
+{
+ Text t;
+ Module m;
+ t = findText(modname);
+ addActions ( singleton(mkCon(t)) );
+ m = findModule(t);
+ if (isModule(m)) return m; else return 0;
+}
+
+DH_MODULE DH_LoadLibrary ( DH_LPCSTR modname )
+{
+ int xxx;
+ DH_MODULE hdl;
+ diet_hep_initialise ( &xxx );
+ hdl = DH_LoadLibrary_wrk ( modname );
+ printf ( "hdl = %d\n", hdl );
+ return hdl;
+}
+
+
+static
+void* DH_GetProcAddress_wrk ( DH_CALLCONV cconv,
+ DH_MODULE hModule,
+ DH_LPCSTR lpProcName )
+{
+ Name n;
+ Text typedescr;
+ void* adj_thunk;
+ StgStablePtr stableptr;
+
+ if (!isModule(hModule)) return NULL;
+ setCurrModule(hModule);
+ n = findName ( findText(lpProcName) );
+ if (!isName(n)) return NULL;
+ assert(isCPtr(name(n).closure));
+
+ /* n is the function which we want to f-x-d,
+ n :: prim_arg* -> IO prim_result.
+ Assume that name(n).closure is a cptr which points to n's BCO.
+
+ Make ns a stable pointer to n.
+ Manufacture a type descriptor string for n's type.
+ use createAdjThunk to build the adj thunk.
+ */
+ typedescr = makeTypeDescrText ( name(n).type );
+ if (!isText(typedescr)) return NULL;
+ if (cconv != dh_stdcall && cconv != dh_ccall) return NULL;
+
+ stableptr = getStablePtr( cptrOf(name(n).closure) );
+ adj_thunk = createAdjThunk ( stableptr,
+ textToStr(typedescr),
+ cconv==dh_stdcall ? 's' : 'c' );
+ return adj_thunk;
+}
+
+void* DH_GetProcAddress ( DH_CALLCONV cconv,
+ DH_MODULE hModule,
+ DH_LPCSTR lpProcName )
+{
+ int xxx;
+ diet_hep_initialise ( &xxx );
+ return DH_GetProcAddress_wrk ( cconv, hModule, lpProcName );
+}
+
+//---------------------------------
+//--- testing it ...
+int main ( int argc, char** argv )
+{
+ void* proc;
+ DH_MODULE hdl;
+ hdl = DH_LoadLibrary("FooBar");
+ assert(isModule(hdl));
+ proc = DH_GetProcAddress ( dh_ccall, hdl, "wurble" );
+fprintf ( stderr, "just before calling it\n");
+ ((void(*)(int)) proc) (33);
+ ((void(*)(int)) proc) (34);
+ ((void(*)(int)) proc) (35);
+ fprintf ( stderr, "exiting safely\n");
+ return 0;
+}
+
+#else
+
+Main main ( Int, String [] ); /* now every func has a prototype */
+
+Main main(argc,argv)
+int argc;
+char *argv[]; {