0

Unfortunately, for some reason I cannot fathom, I haven't been able to get windbg to recognise my extension.

#ifndef EXPT_API
#define EXPT_API __declspec(dllexport)
#endif

extern "C" EXPT_API HRESULT CALLBACK help(PDEBUG_CLIENT Client, PCSTR args)
{
    IDebugControl* Control;
    IDebugSymbols* Symbols;

    DebugCreate(__uuidof(IDebugClient),(void **)&Client);
    Client->QueryInterface(__uuidof(IDebugControl), (void **)&Control);
    Client->QueryInterface(__uuidof(IDebugSymbols), (void **)&Symbols);

    // TODO: Extension code goes here:

    Control->Output(DEBUG_OUTPUT_NORMAL, "A sample help message.");

    return S_OK;
}

It all compiles fine, however, whenever I attempt to load the extension from windbg, I get this:

!Extension.help
No export help found

I load up my .dll into IDA Pro Free, and look at the exports, and there it is: "help". I have been trying to figure this out for hours. Any help you could offer would be very greatly appreciated. Thanks a lot.

niemiro
  • 1,778
  • 1
  • 20
  • 37
  • 1
    Have you looked at the dll in depends? Some calling conventions mangle the name slightly even with extern "C". – Benj Jan 22 '12 at 12:33
  • THANK YOU SO MUCH! You are amazing! It converted my "help" into "_help@8". Do you have any idea how to fix this? Would a .def file do the trick!? Thank you so, so much! EDIT: If you convert this into an answer, I will accept and upvote it :p – niemiro Jan 22 '12 at 14:07
  • 1
    Yes, a .def file is usually the answer. – Benj Jan 22 '12 at 14:20

1 Answers1

1

The chances are you're using the stdcall calling convention which results in name mangling even with extern "C". If you were using the cdecl this would not be the case. It's possible that you require stdcall if you're following the standard method of writing a WinDBG extension so the best way to work around the name mangling is to use a .def file which will allow you to call the exports exactly what you want.

See this previous question for a good rundown on the subtleties:

__cdecl or __stdcall on Windows?

Community
  • 1
  • 1
Benj
  • 31,668
  • 17
  • 78
  • 127
  • Thank you so much for all your help. A .def file has competely solved the problem. Also, thanks for your link. Although it still appears that a __cdecl decorates the function name with an underscore, I learned much. Thanks again! – niemiro Jan 22 '12 at 15:14