delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/07/28/15:20:42

From: ron AT websci DOT com (Ron Kulper)
Subject: export data from a b18 DLL? (stdout bug?)
28 Jul 1997 15:20:42 -0700 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <Pine.SOL.3.91.970728164421.7112A-100000.cygnus.gnu-win32@supersun>
Mime-Version: 1.0
>Received: by supersun.websci.com (SMI-8.6/SMI-SVR4)
id RAA14192; Mon, 28 Jul 1997 17: 44:02 -0400
X-Sender: ron AT supersun
Original-To: gnu-win32 AT cygnus DOT com
Original-Sender: owner-gnu-win32 AT cygnus DOT com

Is it possible to export data (as opposed to a function) from a dll? 
For instance, can I access a malloc'ed structure located in one dll
from a different dll by exporting a structure pointer to the allocated 
space? I know this can be done in MSVC++, but when I try it using
cygwin32, I receive a SIGSEGV when attempting to reference the pointer.
Does this issue have anything to do with the bug described below?

I recieve a SIGSEGV when attempting to set a FILE * = stdout within a dll.
Platform is NT4.0SP3 on a pentium with cygwin32 beta 18.

The problem can be recreated with the 5 small files below.
"dbpcc8.sh stdout" will create stdout.dll
gcc -g main2.c creates a.exe which tries to load C:\tmp\stdout.dll and 
 call stdout_dll().
init.cc and fixup.c are the standard files included for completeness.
The SIGSEGV occurs at line 7 of stdout.c "fp=stdout".

Any help resolving this problem is appreciated.

Thanks,
Ron Kulper
ron AT dbpower DOT com

stdout.c
--------------------------------------------------------------------------------
#include <stdio.h>

void
stdout_dll()
{
	FILE *fp;
	fp=stdout;
	fprintf(fp,"hello\n");
}
main()
{
	stdout_dll();
}
--------------------------------------------------------------------------------


main2.c
--------------------------------------------------------------------------------
#include <stdio.h>
#include "windows.h"

typedef void (*vfp)();


main()
{
	vfp dbp_init_func;
	HINSTANCE lib_handle = LoadLibrary("c:\\tmp\\stdout.dll");
	if(lib_handle == NULL)
	{
		perror("Error loading DLL");
		exit(0);
	}

	dbp_init_func = (vfp) GetProcAddress(lib_handle, "stdout_dll");
	if(dbp_init_func == NULL)
	{
		perror("Error loading func dbp_init_report");
		exit(0);
	}

	dbp_init_func();

	FreeLibrary(lib_handle);
}
--------------------------------------------------------------------------------



dbpcc8.sh
--------------------------------------------------------------------------------
export LIBPATH="C:/gnuwin32/b18/H-i386-cygwin32/i386-cygwin32/lib"
echo EXPORTS > $1.def
gcc -DCYGWIN32 -g -c  $1.c
nm $1.o | grep '^........ [T] _'|sed 's/[^_]*_//' >> $1.def
ld --base-file $1.base --dll -o $1.dll $1.o  init.o fixup.o $LIBPATH/libcygwin.a $LIBPATH/libkernel32.a -e _dll_entry AT 12
dlltool --as=as --dllname $1.dll --def $1.def --base-file $1.base --output-exp $1.exp
ld --base-file $1.base $1.exp --dll -o $1.dll $1.o  init.o fixup.o $LIBPATH/libcygwin.a $LIBPATH/libkernel32.a -e _dll_entry AT 12
dlltool --as=as --dllname $1.dll --def $1.def --base-file $1.base --output-exp $1.exp
ld $1.exp --dll -o $1.dll $1.o  init.o fixup.o $LIBPATH/libcygwin.a $LIBPATH/libkernel32.a -e _dll_entry AT 12
dlltool --as=as --dllname $1.dll --def $1.def --output-lib $1.a
--------------------------------------------------------------------------------


init.cc
--------------------------------------------------------------------------------
/* #include GNU version 2 copyright */
#include <windows.h>
extern "C"
{
	int WINAPI dll_entry (HANDLE h, DWORD reason, void *ptr);
};

int WINAPI dll_entry (HANDLE, DWORD reason, void *)
{
	switch(reason)
	{
		case DLL_PROCESS_ATTACH:
			break;
		case DLL_PROCESS_DETACH:
			break;
		case DLL_THREAD_ATTACH:
			break;
		case DLL_THREAD_DETACH:
			break;
	}
	return 1;
}
--------------------------------------------------------------------------------


fixup.c
--------------------------------------------------------------------------------
asm(".section .idata$3\n" ".long 0,0,0,0, 0,0,0,0");
--------------------------------------------------------------------------------

-
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