DLL导出问题

hamh 2002-09-12 05:56:27
我在Extension DLL中新建了一个对话框资源,然后再对这个对话框新建了一个类CMyDlg。编译出错,找不到IDD_DIALOG1.
MyDlg.cpp
d:\hhh\vcwork\dll\mydlg.h(26) : error C2065: 'IDD_DIALOG1' : undeclared identifier
d:\hhh\vcwork\dll\mydlg.h(26) : error C2057: expected constant expression

请高手指点~不胜感激~!
本人初练DLL,vc的底子可能也不是很好,望对导入和导出都给予详细的说明。谢谢!!
...全文
58 点赞 收藏 10
写回复
10 条回复
hamh 2002年09月16日
经过研究已经成功。
wade_vc(我命由我不由天) 的方法是我绕了一些弯路,屏蔽是肯定错误的。
回复 点赞
CharmDream 2002年09月12日
up
回复 点赞
hamh 2002年09月12日
这个我都有加呀,MainFrm.cpp里有加这一条#include "MyDlg.h"。
而且对于wade_vc(我命由我不由天) 的方法,我想了一下我把enum = { IDD_DLG }注释掉并在构造函数初始列表中直接加上对话框的ID。对于dll变异是通过了,但是对于exe调用时,MyDlg这个类指针怎么定义,而对话框哪个面板的资源呢,又是如何处理的。
我对dll的机制不很了解,在练习时也是参照了一篇文章(http://www.yesky.com/20010427/172392.shtml)做的,而里面也说的不是很明白。
这里也请众高手再指点。谢谢~!
回复 点赞
Hankuu 2002年09月12日
MyDlg未声明,请把
#include "MyDlg.h"
加到你引用MyDlg的cpp的头部
回复 点赞
webber84 2002年09月12日
没有包含头文件。
回复 点赞
hamh 2002年09月12日
我按照 wade_vc(我命由我不由天) 的方法作了编译能通过了,非常感谢。
接下来我在另生成的测试程序中试图用
MyDlg dlg;
dlg.DoModal();
来生成同样的对话框。我生成了一个MyDlg.h,并使其内容与DLL里的MyDlg.h一样。并且做了以下的步骤:
在WorkSpace中的mydlltest files上点击右键,选择Add files to Project ,将dll.dll添加到工程;
拷贝dll.dll 到\mydlltest\debug\下,拷贝dll.lib到\mydlltest\目录下。
编译出错:
MainFrm.cpp
mydlltest\MainFrm.cpp(113) : error C2065: 'MyDlg' : undeclared identifier
mydlltest\MainFrm.cpp(113) : error C2146: syntax error : missing ';' before identifier 'dlg'
mydlltest\MainFrm.cpp(113) : error C2065: 'dlg' : undeclared identifier
mydlltest\MainFrm.cpp(114) : error C2228: left of '.DoModal' must have class/struct/union type

请众高手不吝再次指教。谢谢~!!
回复 点赞
WadeHan 2002年09月12日
这和资源的搜索顺序有关,必须在dll中改变资源搜索顺序,在.h中将enum = { IDD_DLG } 屏蔽掉,然后在.cpp中#include "Resource.h",并且在构造函数初始列表中,加上对话框的ID。其他的看看资料了。
回复 点赞
rivershan 2002年09月12日
How to Create a Modal Dialog from Within a USRDLL
ID: Q121947



--------------------------------------------------------------------------------
The information in this article applies to:

The Microsoft Foundation Classes (MFC), included with:
Microsoft Visual C++ for Windows, 16-bit edition, versions 1.5, 1.51
Microsoft Visual C++, 32-bit Editions, versions 2.0, 4.0

--------------------------------------------------------------------------------


SUMMARY
When creating a modal dialog box from within a USRDLL, or a regular DLL statically linked to the MFC, you need to pass a valid parent window object to the CDialog constructor. You cannot pass the CWnd pointer from an EXE to an USRDLL, so you need to pass the HWND of the parent window.

You can use two methods to construct the CDialog object with the HWND as its parent. You can either construct a CWnd object and use the Attach() function to attach the HWND to it, or you can use CWnd::FromHandle. After that you can use the CWnd object as the parent of the CDialog object.

The DLLTRACE sample program demonstrates the latter method and demonstrates how to delete the temporary objects created by MFC in the OnIdle() handler.

To construct a modal dialog in the USRDLL, export a "C" interface function that takes an HWND as a parameter:




export "C"
{

void FAR PASCAL _export CreateModal(HWND hParent);
}


The implementation of the CreateModal() is below.



MORE INFORMATION
Modal dialog requires a valid parent window to be modal. If the parent window is invalid or NULL, the dialog will not be modal and it will not prevent the user from switching to the other windows of the application.

Sample Code

\* kbon
/* Compile options needed: standard USRDLL options
*/

void FAR PASCAL _export CreateModal(HWND hParent)
{
TRACE("Inside USRDLL\n");

CWnd wndParent;

if (!wndParent.Attach(hParent) )
{
TRACE("Attach Failed\n");
AfxAbort();
}

CMyDialog Dlg(IDD_DIALOG1, &wndParent); // IDD_DIALOG1 is in
// the DLL resource
if ( Dlg.DoModal() == IDOK )
{
// more code
}
else
{
// check for cancel or error
}
wndParent.Detach(hwndParent);
}
\* kboff
Note: In Visual C++ version 4.0, the term "USRDLL" is obsolete. In earlier versions, USRDLL described DLLs that used MFC internally, but typically export functions using the standard "C" interface. In version 4.0, such DLLs are called "Regular DLLs." Regular DLLs, statically linked to MFC have the same characteristics as the former USRDLL.

Additional query words: kbinf modal dialog CDialog DLL USRDLL 1.50 2.00 2.50 2.51 3.00 4.00

Keywords : kbcode
Version : 1.50 1.51 | 2.00 4.00
Platform : NT WINDOWS
Issue type :


Last Reviewed: February 4, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.




--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
回复 点赞
In355Hz 2002年09月12日
#include "resource.h"
回复 点赞
siphonelee 2002年09月12日
The following example copies a dialog box resource from one executable file, Hand.exe, to another, Foot.exe, by following these steps:

Use the LoadLibrary function to load the executable file Hand.exe.
Use the FindResource and LoadResource functions to locate and load the dialog box resource.
Use the LockResource function to retrieve a pointer to the dialog box resource data.
Use the BeginUpdateResource function to open an update handle to Foot.exe.
Use the UpdateResource function to copy the dialog box resource from Hand.exe to Foot.exe.
Use the EndUpdateResource function to complete the update.
The following code implements these steps.

HRSRC hResLoad; // handle to loaded resource
HANDLE hExe; // handle to existing .EXE file
HRSRC hRes; // handle/ptr. to res. info. in hExe
HANDLE hUpdateRes; // update resource handle
char *lpResLock; // pointer to resource data
BOOL result;
// Load the .EXE file that contains the dialog box you want to copy.
hExe = LoadLibrary("hand.exe");
if (hExe == NULL)
{
ErrorHandler("Could not load exe.");
}

// Locate the dialog box resource in the .EXE file.
hRes = FindResource(hExe, "AboutBox", RT_DIALOG);
if (hRes == NULL)
{
ErrorHandler("Could not locate dialog box.");
}

// Load the dialog box into global memory.
hResLoad = LoadResource(hExe, hRes);
if (hResLoad == NULL)
{
ErrorHandler("Could not load dialog box.");
}

// Lock the dialog box into global memory.
lpResLock = LockResource(hResLoad);
if (lpResLock == NULL)
{
ErrorHandler("Could not lock dialog box.");
}

// Open the file to which you want to add the dialog box resource.
hUpdateRes = BeginUpdateResource("foot.exe", FALSE);
if (hUpdateRes == NULL)
{
ErrorHandler("Could not open file for writing.");
}

// Add the dialog box resource to the update list.
result = UpdateResource(hUpdateRes, // update resource handle
RT_DIALOG, // change dialog box resource
"AboutBox", // dialog box name
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), // neutral language
lpResLock, // ptr to resource info
SizeofResource(hExe, hRes)); // size of resource info.
if (result == FALSE)
{
ErrorHandler("Could not add resource.");
}

// Write changes to FOOT.EXE and then close it.
if (!EndUpdateResource(hUpdateRes, FALSE))
{
ErrorHandler("Could not write changes to file.");
}

// Clean up.
if (!FreeLibrary(hExe))
{
ErrorHandler("Could not free executable.");
}
回复 点赞
发动态
发帖子
VC/MFC
创建于2007-09-28

7893

社区成员

42.1w+

社区内容

VC/MFC相关问题讨论
社区公告
暂无公告