Proc address not found. 
Author Message
 Proc address not found.

Hi all,
I am using dynamically linking DLL to executable.
My problem is that GetProcAddress () returns me NULL.
The code snippet is like this :
typedef int(*LPFNDLLFUNC1)(void);
---
HINSTANCE hDLL;               // Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1;    // Function pointer

 hDLL = LoadLibrary("dllpro"); // Library gets loaded
 if (hDLL != NULL)
 {
    lpfnDllFunc1 = (LPFNDLLFUNC1) GetProcAddress (hDLL, "fnDllpro");
file://Returns NULL
    printf("%d", GetLastError ()); // Prints 127...Proc address not found
    if (!lpfnDllFunc1)
    {
    // handle the error
    FreeLibrary(hDLL);
    return SOME_ERR_CODE;
    }
    else
    {
    // call the function
    file://iRetVal = lpfnDllFunc1();
    }
 }

My dllpro.h looks like this -
#ifdef DLLPRO_EXPORTS
#define DLLPRO_API __declspec(dllexport)
#else
#define DLLPRO_API __declspec(dllimport)
#endif
--
DLLPRO_API int fnDllpro(void);

If I use static linking everything works fine. What am I missing?

Thanks in advance.



Mon, 26 Sep 2005 22:53:00 GMT  
 Proc address not found.

Quote:
> I am using dynamically linking DLL to executable.
> My problem is that GetProcAddress () returns me NULL.
> The code snippet is like this :
> ...
> My dllpro.h looks like this -
> #ifdef DLLPRO_EXPORTS
> #define DLLPRO_API __declspec(dllexport)
> #else
> #define DLLPRO_API __declspec(dllimport)
> #endif
> --
> DLLPRO_API int fnDllpro(void);

> If I use static linking everything works fine. What am I missing?

It may be an issue of "name  mangling". Find the DUMPBIN utility in the
compiler's bin subdirectory and enter this command

    dumpbin /exports YourDLL.dll

What names do you see? Is the one you pass to GetProcAddress() visible in
the output?

Regards,
Will



Mon, 26 Sep 2005 23:02:02 GMT  
 Proc address not found.


Quote:
> Hi all,
> I am using dynamically linking DLL to executable.
> My problem is that GetProcAddress () returns me NULL.
> The code snippet is like this :
> typedef int(*LPFNDLLFUNC1)(void);
> ---
> HINSTANCE hDLL;               // Handle to DLL
> LPFNDLLFUNC1 lpfnDllFunc1;    // Function pointer

>  hDLL = LoadLibrary("dllpro"); // Library gets loaded
>  if (hDLL != NULL)
>  {
>     lpfnDllFunc1 = (LPFNDLLFUNC1) GetProcAddress (hDLL, "fnDllpro");
> file://Returns NULL
>     printf("%d", GetLastError ()); // Prints 127...Proc address not found
>     if (!lpfnDllFunc1)

This is probably not the problem, but you should only check GetLastError
when the function is known to have failed. In other words, in this case, you
should only print out GetLastError if lpfnDllFunc1 is NULL. Otherwise,
GetLastError is undefined.

Quote:
>     {
>     // handle the error
>     FreeLibrary(hDLL);
>     return SOME_ERR_CODE;
>     }
>     else
>     {
>     // call the function
>     file://iRetVal = lpfnDllFunc1();
>     }
>  }

Jay


Mon, 26 Sep 2005 23:49:09 GMT  
 Proc address not found.
Thanks William.
dumpbin utility told me that the name of function had been mangled to

After making this change evrything worked fine.
Do you suggest using ordinals is better than specifying actual function
name?



Quote:


> > I am using dynamically linking DLL to executable.
> > My problem is that GetProcAddress () returns me NULL.
> > The code snippet is like this :
> > ...
> > My dllpro.h looks like this -
> > #ifdef DLLPRO_EXPORTS
> > #define DLLPRO_API __declspec(dllexport)
> > #else
> > #define DLLPRO_API __declspec(dllimport)
> > #endif
> > --
> > DLLPRO_API int fnDllpro(void);

> > If I use static linking everything works fine. What am I missing?

> It may be an issue of "name  mangling". Find the DUMPBIN utility in the
> compiler's bin subdirectory and enter this command

>     dumpbin /exports YourDLL.dll

> What names do you see? Is the one you pass to GetProcAddress() visible in
> the output?

> Regards,
> Will



Tue, 27 Sep 2005 12:01:58 GMT  
 Proc address not found.

Quote:
> Thanks William.

You are welcome.

Quote:
> dumpbin utility told me that the name of function had been mangled to

> After making this change evrything worked fine.

That's good.

Quote:
> Do you suggest using ordinals is better than specifying actual function
> name?

Well, if it works for you, that's fine. Personally I prefer to use module
definition (.def) files. In your case the file would look something like
this

LIBRARY yourDLLBaseNameGoesHere

EXPORTS

        fnDllpro

Regards,
Will



Tue, 27 Sep 2005 13:14:01 GMT  
 Proc address not found.
Thanks again.


Quote:


> > Thanks William.

> You are welcome.

> > dumpbin utility told me that the name of function had been mangled to

> > After making this change evrything worked fine.

> That's good.

> > Do you suggest using ordinals is better than specifying actual function
> > name?

> Well, if it works for you, that's fine. Personally I prefer to use module
> definition (.def) files. In your case the file would look something like
> this

> LIBRARY yourDLLBaseNameGoesHere

> EXPORTS

>         fnDllpro

> Regards,
> Will



Tue, 27 Sep 2005 13:42:46 GMT  
 Proc address not found.


<snip>

Quote:
> > Do you suggest using ordinals is better than specifying actual function
> > name?

> Well, if it works for you, that's fine. Personally I prefer to use module
> definition (.def) files.

SK, also note that unless you are using a DEF file, the
ordinals can change when you recompile the DLL.
This has happened more than once to people using
Windows system DLLs.

In general, linking to ordinal numbers is not a good
idea.



Wed, 28 Sep 2005 00:32:23 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. kind of OT: Where to find proC information?

2. speed of in-proc dll vs out-of-proc dll

3. in-proc, out-proc and ATL EXE project.

4. Find and Replace, Not Find and Overwrite

5. could not execute: path not found(Win32 error 3)

6. LINK : LNK6004: Debug/wconnect.exe not found or not built by the last

7. LINK : LNK6004: Debug/wconnect.exe not found or not built by the last

8. Web Service Not Working -- Namespace not found

9. Finding return address

10. Finding out a host's IP address?

11. Finding IO addresses

12. Finding an IP Address

 

 
Powered by phpBB® Forum Software