win32 dll如何使用资源,例如表格,图标等. [英] how win32 dll use the the resouce ,such as form,icon ect.

查看:84
本文介绍了win32 dll如何使用资源,例如表格,图标等.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Win32 DLL中的资源(例如表单),并在DLL导出功能中弹出对话框.这意味着当我调用导出的函数时,会弹出对话框,谢谢!!我该怎么办?


I wanted to use the resource such as the form in the Win32 DLL and pop up the dialog in the DLL exported function. That''s means when I call the exported function, the dialog pops up, thanks!! How can I do this?


#include "resource.h"
#include<windows.h>
HINSTANCE hinst=NULL;     
HWND hwndDLG=NULL;   
BOOL   CALLBACK   DlgProc(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);     

extern "C" __declspec(dllexport) void ShowDlg()      //
{   
    hinst=LoadLibrary("Modal_Dialog.dll");  
 hwndDLG=CreateDialog(hinst,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)DlgProc);         
 ShowWindow(hwndDLG,SW_SHOW);  
 UpdateWindow (hwndDLG) ; 
// hinst=LoadLibrary("Modal_Dialog.dll");      
// DialogBox(hinst,MAKEINTRESOURCE(IDD_DIALOG1),NULL,DlgProc);  // FreeLibrary(hinst);
 
}     
BOOL CALLBACK DlgProc(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)     
{         
 switch(message)       
 {       
 case   WM_INITDIALOG:       
  return   TRUE;       
 case   WM_CLOSE:     
  DestroyWindow(hDlg);       
  hwndDLG   =   NULL;       
  return   TRUE;       
 }     
 return   FALSE;     
}

推荐答案

主要有两种方法可以做到这一点:

1)让对话框离开DLL,并在DLL中实现创建并运行对话框的导出函数.
导出的函数将在DLL本身中,并且在您必须链接到程序的相应导入库"中(与从DLL导出函数没有什么不同).

2)让资源在DLL中定义,从程序中加载库(DLL本身,通过LoadLibrary),然后调用传递库句柄的对话框执行API(例如DialogBox CreateDialog).
There are mainly two ways to do this:

1) Let the dialog to leave into the DLL, and implement in the DLL an exported function that creates and run the dialog.
The exported function will be in the DLL itself and in the corresponding "import library" you have to link to your program (that''s no more different than exporting a function from a DLL)

2) Let the resource to be defined in the DLL, load the library from your program (the DLL itself, via LoadLibrary), Than call a dialog execution API (like DialogBox or CreateDialog) passing the library handle.


谢谢,emilio_grv,《 _超人_》.
关于我的代码呢?谢谢您.请给我一些建议.
Thanks,emilio_grv , «_Superman_».
what about my codes??would you give some advise to my codes ,thanks.


请重新措辞并清楚地解释您的问题.
假设要显示一个对话框,其模板作为资源驻留在另一个DLL中,请按顺序调用以下API.
Please rephrase and explain your question a little more clearly.
Assuming you want to show a dialog whose template resides as a resource in another DLL, calls the following APIs in order.
LoadLibrary
FindResource
LoadResource
LockResource
DialogBoxIndirect


这篇关于win32 dll如何使用资源,例如表格,图标等.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆