NO

Author Topic: w2k with xp-kernel functions  (Read 18500 times)

czerny

  • Guest
Re: w2k with xp-kernel functions
« Reply #15 on: October 15, 2014, 07:01:11 PM »
I have experimented with forwarding a little.

This is my def file:
Code: [Select]
LIBRARY "mybeep"

EXPORTS
"MyExportFunction"=_SampleFunction@8
"MyBeep"=Kernel32._Beep@8

podump mybeep.dll /EXPORTS
gives me the following result:
Code: [Select]
        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:
Code: [Select]
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
Code: [Select]
#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

Code: [Select]
POLINK: error: Unresolved external symbol '_MyBeep'.
see the underscore in front!

If INDIRECT is defined, it says:
Code: [Select]
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:
Code: [Select]
LIBRARY "mybeep"

EXPORTS
"_MyExportFunction"=_SampleFunction@8
"_MyBeep"=Kernel32._Beep@8
I get the system message
Code: [Select]
Der Prozedureinsprungpunkt "Kernel32._Beep@8" wurde in der DLL "mybeep.dll" nicht gefundenWhat exactly is the os expecting in the export table of my dll to accept this as a function forwarding?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2151
Re: w2k with xp-kernel functions
« Reply #16 on: October 15, 2014, 08:52:52 PM »
At this moment polink can't help you.
You need MicroSoft's link.exe for forwaring dll.
May the source be with you

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2114
Re: w2k with xp-kernel functions
« Reply #17 on: October 18, 2014, 06:27:09 PM »
Maybe you want try this tool?
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

czerny

  • Guest
Re: w2k with xp-kernel functions
« Reply #18 on: October 18, 2014, 10:48:12 PM »
Maybe you want try this tool?
Oh, yes! This helps a lot.

czerny

  • Guest
Re: w2k with xp-kernel functions
« Reply #19 on: October 23, 2014, 03:01:35 PM »
I am fighting with Visual C++ 2010 Express:

Code: [Select]
typedef BOOL (CALLBACK *MYBEEP)(DWORD,DWORD);error C2143: Syntaxfehler: Es fehlt ')' vor '*'
error C2143: Syntaxfehler: Es fehlt '{' vor '*'
error C2059: Syntaxfehler: ')'

I have renamed my files to *.c extension and I have set the /TC option.

Who knows the switch necessary to let this compile?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2151
Re: w2k with xp-kernel functions
« Reply #20 on: October 23, 2014, 10:18:42 PM »
Is windows.h included ?
Or
Code: [Select]
typedef int BOOL;
typedef unsigned long DWORD;
#define CALLBACK __stdcall
May the source be with you