Re: Where is my DLL?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Robert Craig wrote:
> 
> Matt Lewis wrote:
> > 
> > Juergen Luethje wrote:
> > > 
> > > Sorry, I don't want to bother anyone.
> > 
> > It's no bother.  If we didn't want to be bothered, we wouldn't read this
> > list. :)
> > 
> > > 
> > > Now I tested the following, which *seems* to work. I use this include
> > > file in my Eu program:
> > > 
> > > --------------------------[ dll_instance.e ]--------------------------
> > > }}}
<eucode>
> > > integer DLL_Instance_Hi, DLL_Instance_Lo
> > > -- DLL_Instance_Hi = 0           -- Initialize the variables only when
> > > -- DLL_Instance_Lo = 0           -- testing the program with the
> > >                                  -- interpreter, *not* when compiling
> > >                                  -- to a DLL!
> > > global function dll_instance()
> > >    return DLL_Instance_Hi*#10000 + DLL_Instance_Lo
> > > end function
> > > </eucode>
{{{

> > > ----------------------------------------------------------------------
> > > 
> > > 
> > > After translating the program for Borland, in "main_.c" I added two
> > > lines to DllMain(), so that it looks like this:
> > > 
> > > int __declspec (dllexport) __stdcall DllMain(int hDLL, int Reason, void
> > > *Reserved)
> > > {
> > >     _9DLL_Instance_Hi = (hDLL >> 16) & 0xFFFF;    // line added manually
> > >     _9DLL_Instance_Lo = hDLL & 0xFFFF;            // line added manually
> > >     if (Reason == 1)
> > >         EuInit();
> > >     return 1;
> > > }
> > > 
> > > Could one of our experts please tell me whether this can be considered
> > > safe?
> 
> Juergen, your multiplication code looks correct.
> 
> > That should work, since you're guaranteed to have a valid 31-bit integer.
> > You could alternatively do this (which is what make_atom does):
> > 
> > if( (unsigned)hDLL > (unsigned)0x7fffffff)
> >   {  _9DLL_Instance = NewDouble( (double)(unsigned long) hDLL ); Ref(hDLL);}
> 
> Matt, the Ref(hDLL) should be deleted. 
> Ref should not be applied to a general 32-bit integer,
> just to a 32-bit Euphoria object (a 31-bit integer, or a pointer), 
> and it isn't needed anyway because NewDouble will set 
> the ref-count to 1, which should be fine.
> (Ref will be a no-op on a 31-bit Euphoria integer, so it won't do
> any damage in that very common case.)
> 
> Also, you should change 0x7fffffff to 0x3fffffff, though 
> your way will work by luck in many cases.
> 
> Maybe you should check make_atom as well.
> (This bit fiddling stuff is very tricky. I hope I'm right here!)
> 
> For those who like bit fiddling, here is a 
> chart of Euphoria internal 32-bit codes taken
> from execute.h in the source:
> 
>   unused  : 011xxxxx xxxxxxxx xxxxxxxx xxxxxxxx
>   unused  : 010xxxxx xxxxxxxx xxxxxxxx xxxxxxxx
> 
>   TOO_BIG:  01000000 00000000 00000000 00000000   (just too big for INT)
> 
>  +ATOM-INT: 001vvvvv vvvvvvvv vvvvvvvv vvvvvvvv   (31-bit integer value)
>  +ATOM-INT: 000vvvvv vvvvvvvv vvvvvvvv vvvvvvvv   (31-bit integer value)
>  -ATOM-INT: 111vvvvv vvvvvvvv vvvvvvvv vvvvvvvv   (31-bit integer value)
>  -ATOM-INT: 110vvvvv vvvvvvvv vvvvvvvv vvvvvvvv   (31-bit integer value)
> 
>   NO VALUE: 10111111 11111111 11111111 11111111   (undefined object)
> 
>   ATOM-DBL: 101ppppp pppppppp pppppppp pppppppp   (29-bit pointer)
> 
>   SEQUENCE: 100ppppp pppppppp pppppppp pppppppp   (29-bit pointer)
> 
> 8-byte alignment is always ensured when allocating 
> sequence and double blocks, so the lower 3 bits of the address
> are redundant, i.e only 29 bits are stored.
> 
> Regards,
>    Rob Craig
>    Rapid Deployment Software
>    <a href="http://www.RapidEuphoria.com">http://www.RapidEuphoria.com</a>
> 

So Rob when you implement dll_instance() in the next release, will it just be a
Windows only routine like instance()?, or would it work for Linux/FreeBSD shared
objects too?


Regards,
Vincent

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu