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: Callbacks from shared libraries compiled with cygwin


Michael Spicar wrote:

> So I have two questions:
> 1) Is it possible at all to have callbacks like this?
> 2) If yes, must I have the import/export-lists?

Yes, it's possible, but it's not considered great design.  You have to
use __declspec(export) on the symbols in the main .exe, and then produce
and import library for that .exe, and then link against that import
library when you link the shared library.  But this will hard-code a
dependence on the .exe name into the .dll, which means the .exe can
never be renamed, and the dll cannot be used with any other .exe.

A better alternative is to factor out the variables/functions that you
want to access from both the main .exe and the .dll into another common
.dll that is imported by both.

Or change your API so that when main calls the function in the shared
library it passes a function pointer as argument to the routine in main.

Brian

--
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]