Trying to get the address of a test method and I'm getting NULL. I have
created a map file and everything looks correct:
<snip>
Exports
ordinal name
1 ?GetNumber@@YAHXZ (int __cdecl GetNumber(void))
</snip>

In the host DLL, I'm importing with this code:
<snip>
typedef int (CALLBACK* LPFNDLLFUNC1)(void);
HINSTANCE hDLL; // Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer

hDLL =
LoadLibrary("Z:\\M3\\Code\\MAX_Plugins\\InFluFluIO\\Debug\\InFluFluIO.dll");
if (hDLL != NULL){
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,
"GetNumber");
if (!lpfnDllFunc1){
// handle the error
::MessageBox(0, "Failed loading InFluFluIO dll", "some tools may not work
correctly", MB_OK|MB_ICONWARNING);

FreeLibrary(hDLL);
return -1;
}
else{
// call the function
result = lpfnDllFunc1();
FreeLibrary(hDLL);
}
}
</snip>

Even though the map file shows me the name, I have tried adding the "_"
before the name. I get NULL everytime. Anyone have any ideas?

Any help appreciated,
Steve Klett

Re: yet another GetProcAddress() problem by Doug

Doug
Tue Jul 26 13:53:58 CDT 2005

On Tue, 26 Jul 2005 11:44:53 -0700, Steve wrote:

> Trying to get the address of a test method and I'm getting NULL. I have
> created a map file and everything looks correct:
> <snip>
> Exports
> ordinal name
> 1 ?GetNumber@@YAHXZ (int __cdecl GetNumber(void))
> </snip>
>
> In the host DLL, I'm importing with this code:
> <snip>
> typedef int (CALLBACK* LPFNDLLFUNC1)(void);
> HINSTANCE hDLL; // Handle to DLL
> LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer
>
> hDLL =
> LoadLibrary("Z:\\M3\\Code\\MAX_Plugins\\InFluFluIO\\Debug\\InFluFluIO.dll");
> if (hDLL != NULL){
> lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,
> "GetNumber");
> if (!lpfnDllFunc1){
> // handle the error
> ::MessageBox(0, "Failed loading InFluFluIO dll", "some tools may not work
> correctly", MB_OK|MB_ICONWARNING);
>
> FreeLibrary(hDLL);
> return -1;
> }
> else{
> // call the function
> result = lpfnDllFunc1();
> FreeLibrary(hDLL);
> }
> }
> </snip>
>
> Even though the map file shows me the name, I have tried adding the "_"
> before the name. I get NULL everytime. Anyone have any ideas?
>
> Any help appreciated,
> Steve Klett

Per your map file, the exported name of the function is
"?GetNumber@@YAHXZ". Try GetProcAddress'ing that.

--
Doug Harrison
Microsoft MVP - Visual C++

Re: yet another GetProcAddress() problem by Eugene

Eugene
Tue Jul 26 13:55:45 CDT 2005

Steve wrote:
> Trying to get the address of a test method and I'm getting NULL. I
> have created a map file and everything looks correct:
> <snip>
> Exports
> ordinal name
> 1 ?GetNumber@@YAHXZ (int __cdecl GetNumber(void))
> </snip>


Note the __cdecl above

>
> In the host DLL, I'm importing with this code:
> <snip>
> typedef int (CALLBACK* LPFNDLLFUNC1)(void);

And note the CALLBACK == __stdcall here. In this case you are lucky because
for functions with no parameters the difference between __cdecl and
__stdcall is insignificant. If you had multiple params your call would
crash.


> HINSTANCE hDLL; // Handle to DLL
> LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer
>
> hDLL =
> LoadLibrary("Z:\\M3\\Code\\MAX_Plugins\\InFluFluIO\\Debug\\InFluFluIO.dll");
> if (hDLL != NULL){
> lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,
> "GetNumber");

This should have been "?GetNumber@@YAH". The name you use in GetProcAddr
must match the one exported from DLL.

> Even though the map file shows me the name, I have tried adding the
> "_" before the name. I get NULL everytime. Anyone have any ideas?

I suggest you find a good book or online tutorial that explains the DLL
loading and read it.


--
Eugene
http://www.gershnik.com




Re: yet another GetProcAddress() problem by Steve

Steve
Tue Jul 26 13:59:47 CDT 2005


"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message
news:w1ar74s4a67r$.1vm3y3m9kke4t.dlg@40tude.net...
> On Tue, 26 Jul 2005 11:44:53 -0700, Steve wrote:
>
> > Trying to get the address of a test method and I'm getting NULL. I have
> > created a map file and everything looks correct:
> > <snip>
> > Exports
> > ordinal name
> > 1 ?GetNumber@@YAHXZ (int __cdecl GetNumber(void))
> > </snip>
> >
> > In the host DLL, I'm importing with this code:
> > <snip>
> > typedef int (CALLBACK* LPFNDLLFUNC1)(void);
> > HINSTANCE hDLL; // Handle to DLL
> > LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer
> >
> > hDLL =
> >
LoadLibrary("Z:\\M3\\Code\\MAX_Plugins\\InFluFluIO\\Debug\\InFluFluIO.dll");
> > if (hDLL != NULL){
> > lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,
> > "GetNumber");
> > if (!lpfnDllFunc1){
> > // handle the error
> > ::MessageBox(0, "Failed loading InFluFluIO dll", "some tools may not
work
> > correctly", MB_OK|MB_ICONWARNING);
> >
> > FreeLibrary(hDLL);
> > return -1;
> > }
> > else{
> > // call the function
> > result = lpfnDllFunc1();
> > FreeLibrary(hDLL);
> > }
> > }
> > </snip>
> >
> > Even though the map file shows me the name, I have tried adding the "_"
> > before the name. I get NULL everytime. Anyone have any ideas?
> >
> > Any help appreciated,
> > Steve Klett
>
> Per your map file, the exported name of the function is
> "?GetNumber@@YAHXZ". Try GetProcAddress'ing that.
>
> --
> Doug Harrison
> Microsoft MVP - Visual C++

wow, I feel dumb. From stuff I had read, I was under the impression that I
should be checking if there is or isn't an underscore in front. Your
suggestion worked fine, thank you. I think I will look into the different
options I have to find out how to export the name a little more clear.
Thank you, Doug!



Re: yet another GetProcAddress() problem by Alex

Alex
Tue Jul 26 15:38:27 CDT 2005

Steve wrote:
> Trying to get the address of a test method and I'm
> getting NULL. I have created a map file and everything
> looks correct: <snip>
> Exports
> ordinal name
> 1 ?GetNumber@@YAHXZ (int __cdecl
> GetNumber(void)) </snip>
>
> [...]
>
> Even though the map file shows me the name, I have tried
> adding the "_" before the name. I get NULL everytime.
> Anyone have any ideas?

Did you specify C linkage? It seems that you export
GetNumber as C++ finction (i.e., with decorated name).
Following articles describe how to avoid that:

"Name Decoration"
http://msdn.microsoft.com/library/en-us/vccore/html/_error_n
ame_decoration.asp

"Exporting C++ Functions for Use in C-Language Executables"
http://msdn.microsoft.com/library/en-us/vccore/html/_core_Ex
port_C.2b2b_.Functions_for_Use_in_C.2d.Language_Executables.
asp