delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/01/13/17:50:59

From: m DOT pymm AT strath DOT ac DOT uk (Michael Pymm)
Subject: RE: DLL musings
13 Jan 1998 17:50:59 -0800 :
Message-ID: <01BD1FB4.71E2B860.cygnus.gnu-win32@cerebus>
Mime-Version: 1.0
To: "'gnu-win32 AT cygnus DOT com'" <gnu-win32 AT cygnus DOT com>

Further to my last post, I've got a partial solution, although it's a little urgh.
(this is only for the glide2x.dll, a library to use the 3Dfx card - I've got other
3rd party dlls to work using the SOP).

Say there's a function (void)grGlideInit(void) in the DLL. My code looks like

void (*pgrGlideInit)(void);

void LoadFuncs(void) {
	HINSTANCE m;
	FARPROC f;

	m = LoadLibrary(<path to glide2x.dll>);
	f = GetProcAddress(m, "_grGlideInit AT 0"); pgrGlideInit = (void (*)()) f;
	
	return;
}

int main(void) {
	LoadFuncs();

	(*pgrGlideInit)();

	return(0);
}

This works! The function LoadFuncs is quite easy to generate from a .def
file, as long as all the DLL functions return void.

I suppose a c preprocessor could be used to extract function definitions
from the glide.h file and construct the (*p<funcname>) stuff at the top and
do proper casting in the LoadFuncs procedure (any ideas?)

dlltool probably creates a library that provides wrapper functions with the
same name as the DLL functions that simply call what I've called (*p<funcname>).

Obviously, my approach is very unportable but I suppose is slightly faster
as it doesn't use a wrapper function.

The question is that if the above works, why does dlltool and ld produce
an executable that Win95 OSR2 says is in the wrong format?

Michael

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019