Subject: Re: DLL's and Objective C
From: [email-masked] (Mikey)

12 Apr 1998 06:09:25 -0700
Message-ID: <[email-masked]>
References: <[email-masked]>
Reply-To: [email-masked]
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
To: [email-masked], [email-masked]

sorry about that ;^) I forgot the @12's

Objective c dll's should certainly be possible,
If you are using B19 this should be all you need

if you are using B18 search for 
Initialising gnuwin DLLs
in the Mailing list

>
>> if linking against the original B18 cygwin.dll/libcygwin.a you MUST
>> give a --image-base other than 0x10000000 even to relocatable
>> dll's, B18's cygwin.dll won't get relocated under win95 NO MATTER WHAT.
>> 

First you need to read up on building dll's in general.

The most important thing is that dll's have an entry point
that is called by the OS, and that must return 1 , like
this

#define APIENTRY __stdcall

/*  PURPOSE:  DllMain is called by Windows when
             the DLL is initialized, Thread Attached, and other times.
             Refer to SDK documentation, as to the different ways this
             may be called.
             
             The DllMain function should perform additional initialization
             tasks required by the DLL.  In this example, no initialization
             tasks are required.  DllMain should return a value of 1 if
             the initialization is successful.

*******************************************************************************/
BOOL APIENTRY DllMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved)
{
    return 1;
        UNREFERENCED_PARAMETER(hInst);
        UNREFERENCED_PARAMETER(ul_reason_being_called);
        UNREFERENCED_PARAMETER(lpReserved);
}

Now for the runtime initialization of the cygwin32 layer you must
include 2 extra object files, produced from the following c files

cut here -------------------------------------------------

/* _DllMainCRTStartup.c initialize the c runtime
layer setting the stdio pointers to the correct values
and returning to the OS, compile with
gcc -c _DllMainCRTStartup.c
include in the dll with 
_DllMainCRTStartup.o -e __DllMainCRTStartup@12	on the link line. */

#include <stdio.h>
extern struct _reent *_imp__reent_data;

__attribute__((__stdcall__))
int DllMain(int, int, void *);

__attribute__((stdcall))
int _DllMainCRTStartup(int handle, int reason, void *ptr)
{ _impure_ptr=_imp__reent_data; return DllMain(handle, reason, ptr); }

cut here -----------------------------------------------
/* dll_reent.c a fake _impure_ptr to avoid
linking in the real one in libccrt0.cc which dosen't work
for dll's. Compile with 
gcc -c dll_reent.c
include in the dll explicitly on the link command line
gcc  -o my.dll dll_reent.o _DllMainCRTStartup.o *.o -mwindows -Wl,--dll,-e,__DllMainCRTStartup@12
or
ld -o my.dll dll_reent.o _DllMainCRTStartup.o *.o --subsystem windows   -lcygwin32 -lkernel32 --dll -e __DllMainCRTStartup@12
*/
#ifdef __CYGWIN32__
void *_impure_ptr;
#endif
cut here --------------------------------------

to call functions in a dll you can just declare them as usual

to reference data in a dll you must call through the pointer
to the data, NOT the function thunk, like this

char **argc;

in an executable linking to a lib becomes

char **_imp__argc
#define __argc (*_imp__argc)

when linking to a dll

How all of this would translate to objective c, I don't know
but these are the points that most people have problems
with when creating their own new cygwin32 dll's.

On Tue, 7 Apr 1998 11:00:11 +0200 (MET DST), you wrote:

>Hi,
>
>I have been trying to build dll's in the cygwin32 environment. In
>itself this works OK! (Great work). I have, however, one question. I
>have build my own version of the compiler (gcc 2.8.1), which has an
>option to build the objective-c runtime as a dll. Should this still
>work? I cannot get it to build.
>Furthermore, I am trying to build a dll with objective-c objects. Does
>anybody have any exprerience with that? I cannot get it to build
>one. Is there any work in that area, or am I trying something
>impossible?
>
>Any help/comments/info is appreciated.
>
>    Ronald Pijnacker.
>    [email-masked]
>-
>For help on using this list (especially unsubscribing), send a message to
>"[email-masked]" with one line of text: "help".

=====================================================
Linux a platform built by, and for users, standing on
the firm legs of reliability, and speed.

Microsoft Windows, a platform without a leg to stand on.

([email-masked])
delete REMOVETHIS from the above to reply
         Mikey
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".