0

I'm trying to call the WinAPI function DialogBox(). On the Microsoft website this function is specified to be in the user32.dll. However, when tried to import this function by declaring it as function to import from a dll, the linker told me it isn't there. Then I tried to find the function with the dependency walker in C:\Windows\System32\user32.dll, but the function wasn't there. (I could see all the other fancy function literals there though.) What can be reasons for that and how can I solve the problem?

I'm using the D programming language. The windows module from the standard library does not import the complete set of functions in the WinAPI. Therefore I sometimes have to import stuff by hand.

Ralph Tandetzky
  • 22,780
  • 11
  • 73
  • 120
  • 2
    What language are you using? How to import WinAPI functions depends greatly on that, and you've provided no information. If you tag your question properly, it helps you get answers more quickly. (At least post the code you've tried using to import the function.) – Ken White Aug 09 '12 at 14:32
  • I'm using the D programming language. But the problem is not language specific. I tried to import the symbols using "extern(Windows) INT_PTR DialogBoxA( HINSTANCE hInstance, LPCTSTR lpTemplate, HWND hWndParent, DLGPROC lpDialogFunc );", but the problem is now solved by importing the function DialogBoxParamA() instead and writing a DialogBoxA() wrapper function. – Ralph Tandetzky Aug 09 '12 at 17:05

1 Answers1

5

That's accurate, there is no such function. From the WinUser32.h SDK header file:

#define DialogBoxA(hInstance, lpTemplate, hWndParent, lpDialogFunc) \
DialogBoxParamA(hInstance, lpTemplate, hWndParent, lpDialogFunc, 0L)
#define DialogBoxW(hInstance, lpTemplate, hWndParent, lpDialogFunc) \
DialogBoxParamW(hInstance, lpTemplate, hWndParent, lpDialogFunc, 0L)

In other words, the C preprocesor renames the function to DialogBoxParam. That's the only one you can pinvoke. Just pass a zero like the macro does.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536