I have experimented with forwarding a little.
This is my def file:
LIBRARY "mybeep"
EXPORTS
"MyExportFunction"=_SampleFunction@8
"MyBeep"=Kernel32._Beep@8
podump mybeep.dll /EXPORTS
gives me the following result:
ordinal hint address name
1 0 100046FE MyBeep (forwarded to Kernel32._Beep@8)
2 1 10001010 MyExportFunction
which looks good to me!
podump mybeep.lib /EXPORTS
gives me the following result:
mybeep.dll: MyBeep (MyBeep)
mybeep.dll: MyExportFunction (MyExportFunction)
which looks not so good. Nothing to see from forwarding. I further would expect to see the decorated symbols in braces.
The following test program
#include <windows.h>
#include <stdio.h>
//#define INDIRECT
#ifdef INDIRECT
typedef BOOL (CALLBACK* MYBEEP)(DWORD,DWORD);
void printErr(HRESULT hresult)
{
LPTSTR errorText = NULL;
FormatMessage(
// use system message tables to retrieve error text
FORMAT_MESSAGE_FROM_SYSTEM
// allocate buffer on local heap for error text
|FORMAT_MESSAGE_ALLOCATE_BUFFER
// Important! will fail otherwise, since we're not
// (and CANNOT) pass insertion parameters
|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, // unused with FORMAT_MESSAGE_FROM_SYSTEM
hresult,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&errorText, // output
0, // minimum size for output buffer
NULL); // arguments - see note
if (errorText)
{
// ... do something with the string - log it, display it to the user, etc.
printf("Error (%d) : %s\n", hresult, errorText);
// release memory allocated by FormatMessage()
LocalFree(errorText);
errorText = NULL;
}
}
#else
BOOL MyBeep(DWORD, DWORD);
#endif
int main(int argc, char *argv[])
{
#ifdef INDIRECT
HINSTANCE hdll = LoadLibrary("MyBeep.dll");
MYBEEP MyBeep;
if (hdll) {
MyBeep = (MYBEEP)GetProcAddress(hdll, "MyBeep");
if (!MyBeep) {
printErr(GetLastError());
FreeLibrary(hdll);
} else {
MyBeep(1000,1000);
}
}
#else
MyBeep(1000,1000);
#endif
return 0;
}
says
POLINK: error: Unresolved external symbol '_MyBeep'.
see the underscore in front!
If INDIRECT is defined, it says:
Error (127) : Die angegebene Prozedur wurde nicht gefunden.
I do not understand what exactly is the problem!
Here again is the problem with the missing underscore.
If I change my def file to:
LIBRARY "mybeep"
EXPORTS
"_MyExportFunction"=_SampleFunction@8
"_MyBeep"=Kernel32._Beep@8
I get the system message
Der Prozedureinsprungpunkt "Kernel32._Beep@8" wurde in der DLL "mybeep.dll" nicht gefunden
What exactly is the os expecting in the export table of my dll to accept this as a function forwarding?