问题
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:
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.
来源:https://stackoverflow.com/questions/11885247/how-do-i-call-the-dialogbox-function-in-the-user32-dll