This is the mail archive of the
cygwin
mailing list for the Cygwin project.
How to create a .dll which contains a function defined in another program?
- From: "Yu-Cheng Chou" <cycchou at ucdavis dot edu>
- To: cygwin at cygwin dot com
- Date: Wed, 13 Jul 2005 08:35:52 -0700 (PDT)
- Subject: How to create a .dll which contains a function defined in another program?
Hi,
bar() is in the main.c which is compiled using VC++.
bar() is called inside module.c which is compiled as module.dll using
cygwin's gcc.
module.dll is loaded by LoadLibrary() in main.exe.
/* main.c */
#include <stdio.h>
#include <windows.h>
extern "C" int mainCRTStartup();
extern "C" int __stdcall
cygloadCRTStartup() {
char padding[4096];
return mainCRTStartup();
}
__declspec(dllexport)
int bar() {
printf("bar() is called\n");
return 0;
}
int main() {
char *modname = "module.dll";
HMODULE h;
HMODULE handle;
void (*init)();
int (*fp)(int);
int ret;
h = LoadLibrary("cygwin1.dll");
init = (void (*)())GetProcAddress(h, "cygwin_dll_init");
init();
handle = LoadLibrary(modname);
fp = (int (*)(int))GetProcAddress(handle, "foo");
ret = fp(125);
printf("ret = %d\n", ret);
return 0;
}
/* module.c */
#include <stdio.h>
extern __declspec(dllimport)
int bar();
__declspec(dllexport)
int foo(int arg){
printf("foo() is called in main.exe\n");
printf("arg * 2 = %d\n", arg * 2);
printf("\n");
bar();
return arg * 2;
}
Thanks
--
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/