Delphi problem with DLL

Steve Biskis mlx@san.rr.com
Sat May 2 06:28:00 GMT 1998


Yep,  but only finally with beta # 19,  it just plain dun't werk with
anythang earlier.

Its a clever hack I adapted from Ton Van Overbeek
<tvoverbe@wk.estec.esa.nl> :
Just make this your entry module & you can even make calls from as
brain-dead
an .exe as Excel spreadsheets !!!

My version (BTW: I do lots of ObjC & NO C++, not ever) 

BEGIN
----------

#include <stdio.h>
#include <windows.h>
#include <objc/runtime.h>

extern void __main( void );
extern struct _reent *__imp_reent_data;
extern void cygwin_crt0( void *mainFunc );

static struct Globals
{
  HANDLE cygwinDLLEvent;
  HANDLE cygwinDLLThread;
} G;

static int MLXCygwinDLLCallback( int argc, char **argv )
{
  //MessageBox(0,"Entered ...","CygwinDLL",MB_OK);
  __main();   // Initialize ObjC & C++ runtime ...
  G.cygwinDLLEvent=CreateEvent(NULL,FALSE,FALSE,NULL);
  WaitForSingleObject(G.cygwinDLLEvent,INFINITE);
  //MessageBox(0,"Exits ...","CygwinDLL",MB_OK);
  return 0;
}

static DWORD WINAPI initCygwinDLL( void *dummy )
{
  //MessageBox(0,"Pre: Cygwin init.","initCygwinDLL()",MB_OK);
  cygwin_crt0(MLXCygwinDLLCallback);
  //MessageBox(0,"Post: Cygwin init.","initCygwinDLL()",MB_OK);
  return 0;
}

BOOL WINAPI DLLMain( HANDLE h, DWORD reason, void *ptr )
{
  DWORD threadId;
  _impure_ptr=__imp_reent_data;
  switch ( reason )
  {
    case DLL_PROCESS_ATTACH:
      //MessageBox(0,"Entered ...","DLLMain(PROC_ATTACH)",MB_OK);
      G.cygwinDLLThread =
      CreateThread(NULL,0,initCygwinDLL,(void *)NULL,0,&threadId);
      SetThreadPriority(G.cygwinDLLThread,THREAD_PRIORITY_HIGHEST);
      //MessageBox(0,"EXITS","DLLMain(PROC_ATTACH)",MB_OK); 
    break;
    case DLL_PROCESS_DETACH:
      //MessageBox(0,"Entered ...","DLLMain(PROC_DETACH)",MB_OK);
      PulseEvent(G.cygwinDLLEvent);
      //WaitForSingleObject(G.cygwinDLLThread,INFINITE);
      //MessageBox(0,"EXITS","DLLMain(PROC_DETACH)",MB_OK);
    break;
    case DLL_THREAD_ATTACH:
    break;
    case DLL_THREAD_DETACH:
    break;
  }
  return 1;
}

asm(".section .idata$3\n" ".long 0,0,0,0, 0,0,0,0");

------------------
END

Just uncomment the test code & you'll get the flow ...

If/when you improve upon it, let me know !


Your welcome in arrears,

da bisk.


----------
> From: Laurent Merckx <Laurent.merckx@eurodb.be>
> To: mlx@san.rr.com
> Subject: Delphi problem with DLL
> Date: Thursday, April 30, 1998 6:12 AM
> 
> > Hi,
> >
> > I've been quietly following this list for some time, haven't really had
any
> > problems that I couldn't eventually overcome (w/list's help) till now.
> >
> > Here's my problem:
> >
> > Trying to initialize the cygwin32 runtime via a call from my own dll.
> > I've got a cygwin generated dll of my own home-brew that works fine in
> > delphi executables until I try to call malloc & the like.  So I've >
turned
> > to trying to init cygwin.dll from my dll.
> 
> Hello,
> I have the same problem but when I search the archive mail-list of
> Cygnus, I didn't find any answer of your question.
> Have you solved your problem ? If yes, can you tell me how you did ?
> 
> Thank you in advance
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".



More information about the Cygwin mailing list