Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <4328198B.2070007@carmen.se> Date: Wed, 14 Sep 2005 14:37:31 +0200 From: Michael Spicar User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20050719 Red Hat/1.7.10-1.1.3.1 MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: Callbacks from shared libraries compiled with cygwin References: <431FFEDC DOT 9030908 AT carmen DOT se> <43204E9E DOT B5C05D69 AT dessent DOT net> In-Reply-To: <43204E9E.B5C05D69@dessent.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Brian Dessent wrote: > 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 Thanks for your answers. And now it works. Initially I will choose the ugly solution and export all symbols. It doesn't matter right now, and the shared libraries I produce are anyway tight coupled to the application. But I will use your advice to improve the solution later. Michael -- 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/