This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Another problem with DLL's


I've got a problem with DLL's...

Folowing the instruccions of the home page of Cygnus, everything works
OK when I link the DLL with my executable but... if you try to load the
library indirectly via LoadLibrary(), it returns an HRESULT of 0

Someone knows how to solve this or is just a bug?

Thanks, 
     ismaelj@hotmail.com


code folows:
----------------------------------------------------------------------
mydll.h
----------------------------------------------------------------------
#include <windows.h>

typedef void (*foop)();
void foof();

----------------------------------------------------------------------
mydll.c
----------------------------------------------------------------------
#include "dll.h"

int WINAPI DllMain(HINSTANCE H, DWORD d, PVOID p) {
  return TRUE;
}

void WINAPI foof() {
  MessageBox(NULL, "Hello from the DLL", "DLL", MB_OK);
}
asm (".section .idata$3\n" ".long 0,0,0,0,0,0,0,0");

----------------------------------------------------------------------
mydll.def
----------------------------------------------------------------------
EXPORTS
foof
----------------------------------------------------------------------
main.c
----------------------------------------------------------------------
#include <stdio.h>
#include "dll.h"

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR
szCmdLine, int iCmdShow) {
  HANDLE dllh;
  foop foo;
  char buf[126];
  dllh=LoadLibrary("mydll.dll");
  if ((UINT)dllh <= HINSTANCE_ERROR){
    sprintf(buf,"Error loading DLL: %d", dllh);
    MessageBox(NULL, buf, "APP", MB_OK);
  }
  else {
   foo=(foop)GetProcAddress(dllh, "foof");
  if (foo==NULL)
      MessageBox(NULL, "foo== null", "APP", MB_OK);
    else
      foo();
  }
  if ((UINT)dllh > HINSTANCE_ERROR)
    FreeLibrary(dllh);
  return 0;
}
----------------------------------------------------------------------
Dll link process:
----------------------------------------------------------------------
gcc -c mydll.c
ld --dll --subsystem windows -e _DllMain@12 -o jnk \
   --base-file dll.base mydll.o -L%LIBRARY_PATH% -luser32
dlltool --dllname mydll.dll --base-file dll.base \
    --def mydll.def --output-lib mydll.a --output-exp mydll.exp
ld --dll --subsystem windows -e _DllMain@12 -o mydll.dll \
   mydll.exp mydll.o -L%LIBRARY_PATH% -luser32
rm jnk dll.base

---------------------------------------------------------
Get Your *Web-Based* Free Email at http://www.hotmail.com
---------------------------------------------------------
-
For help on using this list, send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]