Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
End Users
Pocket PCActiveSyncMultimediaEBooksWirelessSmartPhones
Developers
Windows MobileSmartPhonesWinCE ProgrammingVB for WinCEVC++ for WinCEPlatform BuilderTest Tools
PocketPC DirectoryFree SoftwareWeb Resources
Related Topics
PalmMobile PhonesMore Topics ...

Pocket PC Forum / Developers / Windows Mobile / August 2003

Tip: Looking for answers? Try searching our database.

GetProcAddress() fails?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lisa Pearlson - 15 Aug 2003 03:19 GMT
Hi, I have a DLL "my.dll" that exports the function:

__declspec(dllexport) BOOL Enable(BOOL bEnable);

Question 1:
But in my code below, the GetProcAddress(hDLL, _T("Enable")) fails.
However, when use the ordinal in GetProcAddress(hDLL,
(LPCWSTR)MAKEWORD(1,0))
Then it works. How come?

Question 2:
Also, how can I find out the function NAME from its ORDINAL?
I'd like to find all exported functions in a DLL. And I figure I could do
that by scanning all ordinals.
If there's another or better way, I'd like to know.

Lisa

#define IROBEXDLL _T("my.dll")

HINSTANCE hDLL;
hDLL = LoadLibrary(IROBEXDLL);
if (NULL == hDLL)
{
 MessageBox(NULL, _T("Loading ") IROBEXDLL _T(" library failed"),
_T("OBEX"), MB_OK);
 return FALSE;
}

FARPROC pProc = GetProcAddress(hDLL,  _T("Enable"));
if( !pProc )
{
 MessageBox(NULL, _T("No Enable() found in ") IROBEXDLL _T(" library"),
_T("OBEX"), MB_OK);
 FreeLibrary(hDLL);
 return FALSE;
}

typedef BOOL Enable(BOOL bEnable);
Enable* fnEnable = (Enable*) pProc;

BOOL bSuccess = fnEnable(bEnable);

FreeLibrary(hDLL);

return bSuccess;
Yaroslav Goncharov - 15 Aug 2003 08:02 GMT
Hi

use depends.exe to diagnose the problem and see all exported symbols. On my
computer it is located in
"C:\Program Files\Microsoft eMbedded Tools\Common\Tools\"

Signature

Yaroslav Goncharov
Microsoft MVP - Mobile Devices
Smartphone Developer Network
www.smartphonedn.com

> Hi, I have a DLL "my.dll" that exports the function:
>
[quoted text clipped - 42 lines]
>
>  return bSuccess;
D Devlin - 15 Aug 2003 14:05 GMT
You need to specify extern "C" or EXTERN_C macro
for those functions that you want to have an external
linkage that use C syntax.  Otherwise, in CPP projects,
you will get name manging.

You can use "dumbin.exe /exports [dllname]" to verify the
exported function names for any dll.

Darron

> Hi, I have a DLL "my.dll" that exports the function:
>
[quoted text clipped - 42 lines]
>
>  return bSuccess;
r_z_aret@pen_fact.com - 16 Aug 2003 18:36 GMT
>You need to specify extern "C" or EXTERN_C macro
>for those functions that you want to have an external
>linkage that use C syntax.  Otherwise, in CPP projects,
>you will get name manging.

I know one developer who insists on allowing name mangling and then
using fully mangled names in GetProcAddress. This effectively enforces
typematching. I think he is right, but confess to using the lazy
method (taking extra effort to add extern "C" so I can avoid all the
extra care needed to get mangled names right).

clip

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret
PenFact, Inc.
500 Harrison Ave., Suite 3R
Boston, MA 02118
www.penfact.com
Lisa Pearlson - 18 Aug 2003 17:18 GMT
Ok, I'm dumb.. what are mangled names? the W and A at the end for ascii or
unicode?

Lisa

> You need to specify extern "C" or EXTERN_C macro
> for those functions that you want to have an external
[quoted text clipped - 52 lines]
> >
> >  return bSuccess;
Chris Tacke, eMVP - 18 Aug 2003 17:56 GMT
C++ was originally implemented as a pre-processor to a standard C compiler.
The pre-processor parsed the C++ source code and generated C source. A C
compiler then compiled the generated source code. There was, however, a
problem generating the C source. C++ supports polymorphism (having two or
more functions with the same name) but C does not allow two functions to
have the same name. They solved this by invoking a pre-processor. It
generated a C function name by combining the specified C++ function name and
the return and argument types of the function. This solution was called
"name mangling." Although modern C++ compilers do not use the pre-processor
to generate C source anymore, they still mangle function names.

Use dumnpbin.exe to see a function's actual exported name.  See
http://smartdevices.microsoftdev.com/Learn/Articles/514.aspx

Signature

Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net

> Ok, I'm dumb.. what are mangled names? the W and A at the end for ascii or
> unicode?
[quoted text clipped - 58 lines]
> > >
> > >  return bSuccess;
Lisa Pearlson - 20 Aug 2003 14:11 GMT
Thank you for this little but very interesting and helpful piece of info.
When I compile and linking fails, I get those weird function names like
"@Enable@@" or such characters.. still don't know how to read them, but now
I know why it's there.

Lisa

> C++ was originally implemented as a pre-processor to a standard C compiler.
> The pre-processor parsed the C++ source code and generated C source. A C
[quoted text clipped - 73 lines]
> > > >
> > > >  return bSuccess;
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.