Subject: Does any of you build successfully a DLL with B18?
From: [email-masked]

14 May 1997 14:31:54 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN
Original-To: [email-masked]
Original-Sender: [email-masked]

     Hi folks,

     I've some problems with DLL creation since I've downloaded B18. I want 
     to be sure that I've not missed somethng in the installation process.
     
     So in case that some of you have success with B18 and DLL creation, 
     could you please send me, a little sample script?

     Thanks al lot
     
     pascal

     
     here my files:
     
     ------------------------------------------------
     fixup.s
     ------------------------------------------------
     .section .idata$3
     .long 0,0,0,0, 0,0,0,0
     
     ------------------------------------------------
     init.c
     ------------------------------------------------
     #include <windows.h>
     
     extern int WINAPI dll_entry (HANDLE h, DWORD reason, void *ptr);
     
     int WINAPI dll_entry (HANDLE h,
        DWORD reason,
        void *ptr)
     {
        switch (reason)
        {
        case DLL_PROCESS_ATTACH:
                break;
        case DLL_PROCESS_DETACH:
                break;
        case DLL_THREAD_ATTACH:
                break;
        case DLL_THREAD_DETACH:
                break;
        }
        return 1;
     }
     
     ------------------------------------------------
     main.c
     ------------------------------------------------
     /*
     Main file to try linking with a DLL under gnuwin32
     */
     
     int main()
     {
        printf("doit(5) returns %d\n", doit(5)); 
        return(0);
     }
     
     ------------------------------------------------
     foo.c
     ------------------------------------------------
     /*
      Test file to check out building DLLs with gnuwin32 
      This uses printf from the std lib
     */
     
     #include <stdio.h>

     int doit (i)
     int i;
     {
        printf("from foo.c\n");
        return( i+10 );
     }
     
     ------------------------------------------------
     loadDll.c
     ------------------------------------------------
     #include <windows.h>
     #include <stdio.h>
     
     typedef int (*fooFunc)(int i);

     int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR 
     szCmdLine, int iCmdShow) 
     {
     HANDLE dllh;
     fooFunc doit;
     char buf[126];
     dllh=LoadLibrary("foo.dll");
     if ((UINT)dllh <= HINSTANCE_ERROR){
        sprintf(buf,"Error loading dll: %d", dllh); 
        MessageBox(NULL, buf, "loadDll", MB_OK);
        return(1);
     }
     else {
        doit=(fooFunc)GetProcAddress(dllh, "doit");
        if (doit==NULL)
                MessageBox(NULL, "doit == null", "loadDll", MB_OK);
        else
                printf("doit(10) returns: %d\n",doit(10));
     }
     if ((UINT)dllh > HINSTANCE_ERROR)
        FreeLibrary(dllh);
     return(0);
     }
     
     ------------------------------------------------
     Makefile
     ------------------------------------------------
     OBJS=init.o foo.o fixup.o
     CYGLIB=-lcygwin
     LIBS=$(CYGLIB)
     ENTRY=_dll_entry@12
     
     RELOCATABLE=yes
     
     DLL=foo
     
     LD_OPT=-o $(DLL).dll $(OBJS) $(LIBS) -e $(ENTRY)
     
     .PHONY : all test clean
     
     all: $(DLL).dll $(DLL).a main.exe test
     
     test: $(DLL).dll test4.exe loadDll.exe
        echo "test4: validate functions call"
        ./test4.exe
        echo "loadDll: try to load dll"
        ./loadDll.exe
     
     clean:
        rm -f *.exp* *.def *.o *.base *.a
     
     %.def: %.o
        echo EXPORTS > $@
        nm $^ | egrep "^........ [T] _" | sed "s/[^_]*_//" >> $@
     
     $(DLL).dll: $(OBJS) $(DLL).def
     ifdef RELOCATABLE
        ld --dll --base-file $(DLL).base $(LD_OPT)
        dlltool --as=as --dllname $(DLL).dll --def $(DLL).def --base-file\  
      $(DLL).base --output-exp $(DLL).exp
        ld --dll --base-file $(DLL).base $(DLL).exp $(LD_OPT)
        dlltool --as=as --dllname $(DLL).dll --def $(DLL).def --base-file\  
      $(DLL).base --output-exp $(DLL).exp
        ld $(DLL).exp --dll $(LD_OPT)
     else
        ld --dll --base-file $(DLL).base $(LD_OPT)
        dlltool --as=as --dllname $(DLL).dll --def $(DLL).def --base-file\  
      $(DLL).base --output-exp $(DLL).exp
        ld --dll $(DLL).exp $(LD_OPT)
     endif
     
     $(DLL).a: $(DLL).def $(DLL).dll
        dlltool --as=as --dllname $(DLL).dll --def $< --output-lib $@
     
     main.exe: main.c $(DLL).a
        gcc $^ -o $@
     
     test4.exe: main.c foo.o
        gcc $^ -o $@
     
     loadDll.exe: loadDll.c
        gcc $^ -o $@ -lcygwin -luser32 -lkernel32
____________________________________________________________________
"This email and any files transmitted with it are confidential and 
intended solely for the use of the individual or entity to whom they 
are addressed. This communication may contain material protected by 
attorney-client privilege. If you are not the intended recipient or 
the person responsible for delivering the email to the intended 
recipient, be advised that you have received this email in error and 
that any use, dissemination, forwarding, printing, or copying of this 
email is strictly prohibited. If you have received this email in error 
please notify the IT manager by telephone on 44 (0) 118 9306060."

[email-masked]
http://www.integralis.com

          Innovation, Integration, Integralis
_____________________________________________________________________
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".