1. RE: help! (DLLs)

i tried that, and no change. btw, i pedump'ed it and apparently it 
doesn't add underscores, but all compilers prepend underscores to 
function names

stabmaster_ at HOTMAIL.COM wrote:
> Hmm.. does your C file have the following function in it?
> 
> BOOL WINAPI __declspec(dllexport) LibMain(HINSTANCE hDLLInst, DWORD 
> fdwReason, LPVOID lpvReserved)
> {
> switch (fdwReason)
> {
>   case DLL_PROCESS_ATTACH:
>    return TRUE;
>    break;
>   case DLL_PROCESS_DETACH:
>    break;
>   case DLL_THREAD_ATTACH:
>    break;
>   case DLL_THREAD_DETACH:
>    break;
> }
> return TRUE;
> }
> 
> 
> Every dll must have a LibMain(). Oh, and now that I think about it; I 
> recall 
> lcc adding underscores to all function-names. So you prolly should try 
> define_c_proc("test_").
> 
> 
>

new topic     » topic index » view message » categorize

2. RE: help! (DLLs)

>i tried that, and no change. btw, i pedump'ed it and apparently it
>doesn't add underscores, but all compilers prepend underscores to
>function names
>

Yeah, most of them do. But only lcc keeps the underscores in the exported 
names (that I know of).

I was unable to get your example with puts("Hello World") to work. The 
function would be defined properly, but it wouldn't output anything. 
However, I do have a working example for you:


<SIMPLE.C>

  #include <windows.h>

  BOOL WINAPI __declspec(dllexport) LibMain(HINSTANCE hDLLInst, DWORD   
fdwReason, LPVOID lpvReserved)
  {
    switch (fdwReason)
    {
       case DLL_PROCESS_ATTACH:
         return TRUE;
         break;
       case DLL_PROCESS_DETACH:
         break;
       case DLL_THREAD_ATTACH:
         break;
       case DLL_THREAD_DETACH:
         break;
    }
    return TRUE;
  }


  int extern_add(int a, int b)
  {
    return a+b;
  }

</SIMPLE.C>


<SIMPLE.DEF>

  LIBRARY simple
  EXPORTS extern_add

</SIMPLE.DEF>


<SIMPLE.EXW>

  include dll.e

  atom lib,func

  lib = open_dll("simple.dll")
  func = define_c_func(lib, "_extern_add", {C_INT,C_INT}, C_INT)

  printf(1, "%d + %d = %d", {5,8,c_func(func, {5,8})})

  -- Prevent the console from being closed immediately.
  if getc(0) then end if

</SIMPLE.EXW>


I compiled the dll with:
  lcc simple.c
  lcclnk -dll -s simple.obj simple.def

(-s strips debugging stuff, or something..)

new topic     » goto parent     » topic index » view message » categorize

3. RE: help! (DLLs)

> -----Original Message-----
> From: sephiroth _ [mailto:euman2376 at yahoo.com]

> i tried that, and no change. btw, i pedump'ed it and apparently it
> doesn't add underscores, but all compilers prepend underscores to
> function names

I just made a little dll (dll.dll) with lcc by translating and running
emake.  No def file or anything, and it returned the name of the function
with an underscore and @4 appended (1 arg):

-- begin dll.ew
global function huh( atom x )
	return rand(5)
end function
-- end dll.ew

Eu  function:  huh( atom x )
C   function:  _0huh( int x )
DLL function:  __0huh@4

Now, I tried a DEF file (dll.def):

EXPORTS
huh = _0huh

and rebuilt the dll.  LCC still exported __0huh@4, but also exported huh.
Removing the __declspec(dllexport) from the function definition (in dll.c)
and the prototype in main_.h, and the only thing exported was huh.  The same
thing worked with Borland (I don't have Watcom).  LCC seems to need to have
the .def file included in the call to the linker, while Borland finds the
.def file on its own.

Rob, I think it would be better to not declare anything
_declspec(dllexport), but to create a def file with the original Eu routine
names in an export file.  It would make things much cleaner, and shouldn't
be too difficult.  It would also make it easy to include/exclude routines
from being exported (for instance, if win32lib is included in the source for
the dll, it's probably not necessary to export all the routines in
win32lib).

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

4. RE: help! (DLLs)


new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu