Subject: Another problem with DLL's
From: [email-masked] (" Ismael Jurado")

19 Mar 1997 13:35:40 -0800
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Content-Type: text/plain
X-Originating-IP: [194.179.125.167]
Original-To: [email-masked]
Original-Sender: [email-masked]

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, 
     [email-masked]

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
"[email-masked]" with one line of text: "help".