delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/02/07/12:45:26

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-Id: <4.3.1.2.20020207094648.0210abf0@pop.ma.ultranet.com>
X-Sender: lhall AT pop DOT ma DOT ultranet DOT com
X-Mailer: QUALCOMM Windows Eudora Version 4.3.1
Date: Thu, 07 Feb 2002 12:41:13 -0500
To: Kent Watsen <kent AT watsen DOT net>, cygwin AT cygwin DOT com
From: "Larry Hall (RFK Partners, Inc)" <lhall AT rfk DOT com>
Subject: Re: dlopen(0, RTLD_LAZY) doesn't work?
In-Reply-To: <3C61ED02.3060204@watsen.net>
References: <3C61E3C1 DOT 9010200 AT watsen DOT net>
Mime-Version: 1.0

I've never seen this attempted to access a function not in a DLL, though
in theory (at least), what you're doing should work.  

Check the symbols in the resulting object file.  Make sure that the call
type is the same as you're referencing the function by.  In other words,
make sure that you call the function by the name as the object file has
it (probably stdcall) rather than the name as you write it (cdecl).  
Change your definition call type or the calling name itself so that the 
call type matches.  This might help.

Larry Hall                              lhall AT rfk DOT com
RFK Partners, Inc.                      http://www.rfk.com
838 Washington Street                   (508) 893-9779 - RFK Office
Holliston, MA 01746                     (508) 893-9889 - FAX



At 09:57 PM 2/6/2002, Kent Watsen wrote:

>OK, so I've written the windows equivalent of my original program
>and still get the same error - is there some linking option I'm missine?
>
>Here is the new code, again just compile (gcc foo.c) and run (foo.exe):
>
>#include <stdio.h>
>#include <windows.h>
>
>extern __declspec(dllexport) void foo(void)
>{
>    printf("hello\n");
>}
>
>int main(int argc, char *argv[])
>{
>    void* dl   = NULL;
>    void* func = NULL;
>
>    dl = (void *) GetModuleHandle (NULL);
>    if (dl == NULL) {
>        printf("GetModuleHandle() failed\n");
>        exit(0);
>    }
>
>    func = (void*)GetProcAddress((HMODULE)dl, "foo");
>    if (func == NULL) {
>        printf("GetProcAddress() failed (code %u)\n", GetLastError());
>        exit(0);
>    }
>
>    printf("do something meaningful\n");
>
>    return 0;
>}
>
>
>
>
>
>
>
>
>
>Kent Watsen wrote:
>
>>
>>Hi,
>>
>>I've read the mailing list archives and searched google trying
>>to figure out how to get the following program to work.  All
>>you have to do is save it to a file (foo.c), compile (gcc foo.c),
>>and run - I always get "dlsym() failed."
>>
>>Note, I have tried many variations of extern and _declspec
>>as well as looking for "_foo" in addition to "foo" ("nm a.exe |
>>grep foo" returned "0040104c T _foo"...
>>
>>Here is the code - help would be greatly appreciated - thanks!
>>
>>#include <stdio.h>
>>#include <dlfcn.h>
>>#include <windows.h>
>>
>>extern __declspec(dllexport) void foo(void)
>>{
>>    printf("hello\n");
>>}
>>
>>int main(int argc, char *argv[])
>>{
>>    void* dl    = NULL;
>>    void* func = NULL;
>>
>>    dl = dlopen(0 , RTLD_LAZY);
>>    if (dl == NULL) {
>>        printf("dlopen() failed\n");
>>        exit(0);
>>    }
>>
>>    func = dlsym(dl, "foo");
>>    if (func == NULL) {
>>        printf("dlsym() failed\n");
>>        exit(0);
>>    }
>>
>>    printf("do something meaningful\n");
>>
>>    dlclose(dl);
>>    return 0;
>>}
>>
>>
>>
>>
>>-- 
>>Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>>Bug reporting:         http://cygwin.com/bugs.html
>>Documentation:         http://cygwin.com/docs.html
>>FAQ:                   http://cygwin.com/faq/
>
>
>
>--
>Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>Bug reporting:         http://cygwin.com/bugs.html
>Documentation:         http://cygwin.com/docs.html
>FAQ:                   http://cygwin.com/faq/


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019