从User32.dll中导出MessageBoxW
代码:
#include <Windows.h> #include <iostream> #include <functional> typedef int(__stdcall *MsgBOX) ( HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType ); int main(int argc, char* argv[]) { HINSTANCE handle_user32_dll = LoadLibrary(TEXT("User32.dll")); std::function<int(HWND, LPCWSTR, LPCWSTR, UINT)> MsgBoxInstance; if (!handle_user32_dll) { std::cout << "Dll isn't loaded successfuly." << std::endl; } else { MsgBoxInstance = reinterpret_cast<MsgBOX>(GetProcAddress(handle_user32_dll, "MessageBoxW")); if (!MsgBoxInstance) { std::cout << "Function didn't resolved."; } else { MsgBoxInstance(NULL, TEXT("Resource not available Do you want to try again?"), TEXT("Account Details"), MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2); } } FreeLibrary(handle_user32_dll); return 0; }