Modules on Windows: help with dlltool
Jerry James <[email protected]>
| Newsgroups | gmane.emacs.xemacs.windows,gmane.emacs.xemacs.beta |
|---|---|
| Message-ID | <[email protected]> |
I've decided to have a go at fixing module support on Windows platforms. I've reluctanly set up my home machine to dual-boot Windows and Linux, and have installed cygwin on the Windows side. I came up with a test to see if I correctly understand the linking problems involved. It didn't work out quite as I expected, though, and I wonder if anybody can give me a boost in the right direction. The test.c file is supposed to be an analog of XEmacs: it is self-contained, has a function that can be used by modules, and opens and attempts to use some user-specified DLL. On the other hand, dll.c is the source for a simple dll.c that provides a function needed by test.c, and uses a support function provided by test.c. The Makefile attempts to compile these to an executable, test.exe, and a DLL, my.dll. With the Makefile as given, the result is: $ ./test.exe my.dll "This is a test" Unable to open library my.dll If the use of dlltool is removed in favor of the two commented lines below it, namely: gcc -o junk -shared -Wl,--out-implib -Wl,libtest.a test.o rm junk.exe then the result is: $ ./test my.dll "This is a test" The string is This is a test Its reverse is tset a si sihT Also, I note that when gcc is used to create junk.exe as above, it says "Creating library file: libtest.a", but dlltool does not. When the "-shared" is omitted from the gcc line above, to create the actual test.exe executable, then libtest.a is NOT created. And finally, the junk.exe created above really is junk: it is actually a DLL, not an executable. I'd rather not create a junk XEmacs DLL just to get the import library. Can anybody show me how to use dlltool appropriately to make this work? -- Jerry James http://www.ittc.ku.edu/~james/
Makefile
(application/octet-stream, 354 B) - not displayed
test.c
(application/octet-stream, 1.1 KB)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#define DllExport __declspec(dllexport)
#define DllImport __declspec(dllimport)
typedef void (CALLBACK* dllfunc)(char *);
int
main (int argc, char *argv[])
{
HINSTANCE h;
dllfunc func; // Function pointer
if (argc < 3)
{
fprintf (stderr, "Usage: %s library string\n", argv[0]);
return EXIT_FAILURE;
}
/* Open the library */
h = LoadLibrary (argv[1]);
if (h == NULL)
{
fprintf (stderr, "Unable to open library %s\n", argv[1]);
return EXIT_FAILURE;
}
/* Find the library function */
func = (dllfunc) GetProcAddress(h, "dllfunc");
if (func == NULL)
{
fprintf (stderr, "Unable to find function dllfunc in library %s\n",
argv[1]);
FreeLibrary (h);
}
/* Call the library function */
func (argv[2]);
/* Close the library */
FreeLibrary (h);
return EXIT_SUCCESS;
}
DllExport void
reverse_string (char *s)
{
register int i, length = strlen (s);
for (i = 0; i < length - i - 1; i++)
{
char temp = s[i];
s[i] = s[length - i - 1];
s[length - i - 1] = temp;
}
}
dll.c
(application/octet-stream, 281 B)
#include <stdio.h>
#define DllExport __declspec(dllexport)
#define DllImport __declspec(dllimport)
DllImport extern void reverse_string (char *);
DllExport void
dllfunc (char *s)
{
printf ("The string is %s\n", s);
reverse_string (s);
printf ("Its reverse is %s\n", s);
}