Mail Archives: cygwin/2005/07/12/14:02:40
> As has been already pointed out, you have to load cygwin1.dll first,
> initialize it, and then load your DLL. The whole cygload thing is for
> cygwin1.dll only, it will not work for anything else. After the Cygwin
> DLL has been loaded and initialized you should be able to load your DLL
> that depends on the Cygwin DLL normally, without any special procedure.
> If you try to load your DLL directly Cygwin will not be initialized
> properly, and if you try to locate the Cygwin initialization routine in
> your DLL it will fail (because it exists only in the Cygwin DLL.)
My program works in this way. However, after the cygwin1.dll was
initialized, the I/O seemed to be redirected. How can I get my I/O back?
I listed my codes below for reference.
/* main.c */
#include <stdio.h>
#include <windows.h>
extern "C" int mainCRTStartup();
extern "C" int __stdcall
cygloadCRTStartup() {
char padding[4096];
return mainCRTStartup();
}
int main() {
char *modname = "module.dll";
HMODULE h;
HMODULE handle;
void (*init)();
int (*fp)(int);
int ret;
printf("1\n");
h = LoadLibrary("cygwin1.dll");
printf("h = %p\n", h);
init = (void (*)())GetProcAddress(h, "cygwin_dll_init");
printf("init = %p\n", init);
init(); // after this, I/O will be redirected
printf("2\n");
handle = LoadLibrary(modname);
if(handle == NULL) {
fprintf(stderr, "Can't load %s in LoadLibrary()\n", modname);
exit(1);
}
printf("handle = %p\n", handle);
fp = (int (*)(int))GetProcAddress(handle, "foo");
if(fp== NULL) {
fprintf(stderr, "ERROR: GetProcAddress()\n");
exit(1);
}
printf("fp = %p\n", fp);
ret = fp(100);
printf("ret = %d\n", ret);
return 0;
}
/* module.c */
#include <stdio.h>
int foo(int arg){
printf("foo() is called in main.exe\n");
printf("arg * 2 = %d\n", arg * 2);
return arg * 2;
}
Here is the output from MS command prompt
C:\users\ycchou\VC1>main.exe
1
h = 61000000
init = 61005790
foo() is called in main.exe
arg * 2 = 200
Thanks for anyone's help
--
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/
- Raw text -