How do I call the DialogBox() function in the user

2019-09-15 16:23发布

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.

1条回答
地球回转人心会变
2楼-- · 2019-09-15 16:54

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.

查看更多
登录 后发表回答