今天使用win32封装了一个DLL,DLL中有很多对话框资源,然后应用程序加载这个DLL后创建对话框时找不到对话框资源,我程序中使用的是CreateDialog,第一个参数是Hinstance类型,之前使用的是如下代码:
//获取应用程序实例句柄:
HInstance hInstance = (HINSTANCE ) GetWindowLong( NULL, GWL_HINSTANCE );
//创建对话框:
HWND hWnd = CreateDilg( hInstance,MAKEINTRESOURCE(IDD_DLGNAME),m_hWndParent,DLGPROC);
然后在google中输入了 “win32 dialog in dll"然后在
stackoverflow发现了一段文字,如下:
You are passing NULL in the hInstance argument to CreateDialogParam(). That means the dialog resource wil be looked up in the executable that has loaded your DLL, not in the DLL itself. You should pass the HINSTANCE associated with your DLL instead.
看完上面的解释恍然大悟,

在win32 DLL开发中遇到对话框资源无法被应用程序识别的问题,原因是使用CreateDialog时,传递的HINSTANCE参数错误。应当传递DLL自身的HINSTANCE,而非应用程序的。通过在DLL入口保存HINSTANCE全局变量,可以正确创建DLL内的对话框资源。
最低0.47元/天 解锁文章
964

被折叠的 条评论
为什么被折叠?



