This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to make DLLs in cygwin for MSVC and BCB


http://cygwin.com/faq/faq.html#TOC102

Note that this just references loading cygwin1.dll and getting it
initialized.  If you have your own DLL that depends on cygwin1.dll you
will probably first have to load and initialize Cygwin, and then load
your own DLL.

Loading the cygwin1.dll dynamically is certainly an option. I tried it, although I'm not quite sure how to make sure I have "4K of scratch space at the bottom of the stack", like the faq says.


My test program crashes once cygwin_dll_init is called. :-((

#include <windows.h>
#include <stdio.h>

int main(void)
{
	char blah[4096];
	int rc;
	
	HMODULE h = LoadLibrary("cygwin1.dll");
	printf("LoadLibrary: %d\n", (int)h);
	if ((int)h < 32) {
		return 1;
	}
	
	void (*cyginit)() = (void (*)())GetProcAddress(h, "cygwin_dll_init");
	printf("cyginit: %p\n", cyginit);
	if (cyginit) {
		printf("calling...\n");
		cyginit();
		printf("call ok\n");
	}
	
	FreeLibrary(h);
	return 0;
}

This is the program output:

LoadLibrary: 1627389952
cyginit: 61006F00
calling...
6 [main] ? 2820 handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
Exception: STATUS_ACCESS_VIOLATION at eip=610B93F3
eax=0012F084 ebx=003A0043 ecx=003A0043 edx=00130000 esi=000000A8 edi=00000000
ebp=0012EEDC esp=0012EEDC program=, pid 0, thread main
cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023
Stack trace:
Frame Function Args
0012EEDC 610B93F3 (003A0043, 0012EE70, 0012EF0C, 610BB331)
0012EF0C 610B92E0 (61128014, 6110F1B4, 00000000, 00000000)
0012EF4C 61006775 (00000000, FFFFFFFE, 00000504, 6110F1B4)
0012EF7C 61006FBD (0040A0B8, 7FFD8000, 00000001, 00000080)
0012FF8C 004011AE (00000001, 00D621CC, 00D6267C, C10040A1)
0012FFB8 00407CF2 (0040A0B8, 7C816D4F, C10040A1, 13A302E0)
End of stack trace



What is going wrong here?


Thanks,
Patrick.



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]