如何将DLL包含到EXE. [英] How to include a DLL to a EXE.

查看:165
本文介绍了如何将DLL包含到EXE.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的问题很简单.我创建了2个项目:

1)MyApp-MyApp.exe
2)Mydll-Mydll.dll

Mydll.h

Hi guys,

My question is very simple. I have created 2 projects:

1) MyApp - MyApp.exe
2) Mydll - Mydll.dll

Mydll.h

// Mydll.h : main header file for the Mydll DLL
//

#pragma once

#ifndef __AFXWIN_H__
	#error "include ''stdafx.h'' before including this file for PCH"
#endif

#include "resource.h"		// main symbols


// MydllApp
// See Mydll.cpp for the implementation of this class
//

class MydllApp : public CWinApp
{
public:
	MydllApp();

// Overrides
public:
	virtual BOOL InitInstance();

	DECLARE_MESSAGE_MAP()
};




MydllDlg.h




MydllDlg.h

#pragma once
// MydllDlg dialog
class MydllDlg : public CDialog
{
    DECLARE_DYNAMIC(MydllDlg)
public:
    MydllDlg(CWnd* pParent = NULL);   // standard constructor
    virtual ~MydllDlg();
// Dialog Data
    enum { IDD = IDD_DIALOG_CRINV };
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    DECLARE_MESSAGE_MAP()
};



我已经分别创建了这些项目.

现在,我希望io将此dll包含到应用程序中,以便可以实例化obj并从应用程序中调用dll的方法.

为了成功实现此目标,我需要采取哪些正确的步骤.
(请在详细信息中说明我是软件开发新手的步骤)

如果对此已经存在威胁或解释,请将链接发送给我.

我进行了一些搜索,但是它没有帮助我,因为在那些论坛中,答案是提供给在MVS IDE中熟悉的ppl. (例如,将您的dll引用到项目中并将dll导入到项目中")...我认真地告诉您,我不知道该怎么做!

对不起,如果我太苛刻:)

精瘦的人,
skunkhead:)



I have created these projects separately.

Now, I want io include this dll to the app so that I can instantiate obj and call methods of the dll from the app.

What are the correct steps I need to do in order to success this.
(Kindly explain in DETAIL the steps as i''m NEW to software development)

If there were already some threats or explaination on this done kindly send me the link.

I have do some searching but, it does NOT HELP me because in those forums the answers were given to ppl who are knowlegeable in MVS IDE. (e.g "reference your dll to the project and import the dll in the project")...seriously I tell you, I don''t know how to do that!

Sorry if I''m too harsh :)

Leaner,
skunkhead :)

推荐答案

您不包含" DLL.它们的另一个名称是共享库".它们在运行时链接或加载.它们是共享的,因为其他MZ文件(便携式可执行文件)也可以从同一文件链接或加载DLL.

在这里,您可以找到有关如何引用它们的说明:
http://stackoverflow.com/questions/414761/how-do-i-reference-a-dll-in-a-vc-project [ http://stackoverflow.com/questions/809948/dll-references-in-visual-c [ ^ ]

对于动态加载DLL,您确实需要知道两个Windows API:LoadLibrary( http://msdn.microsoft.com/en-us/library/ms683212(v = vs.85).aspx [ ^ ]).第一个函数返回用作另一个函数的输入.

—SA
You do not "include" DLLs. Another name for them is "Shared Libraries". They are linked to or loaded during run-time. They are shared because other MZ file (Portable Executable) can also link or load the DLL from the same file.

Here you can find instruction of how to reference them:
http://stackoverflow.com/questions/414761/how-do-i-reference-a-dll-in-a-vc-project[^]
http://stackoverflow.com/questions/809948/dll-references-in-visual-c[^]

As to the loading DLLs dynamically, you really need to know two Windows APIs: LoadLibrary (http://msdn.microsoft.com/en-us/library/ms684175(v=vs.85).aspx[^]) and GetProcAddress (http://msdn.microsoft.com/en-us/library/ms683212(v=vs.85).aspx[^]). First function return is used as input for another one.

—SA


看一下本教程: http://www.hdsoft.org/howtolinktodll.html [ ^ ]
Take a look at this tutorial: http://www.hdsoft.org/howtolinktodll.html[^]


我最喜欢的解决方案是使用:
My favourite solution is to use:
#ifndef BUILDING_MYDLL
 #pragma comment( lib, "mydll" )
#endif


它记录在这里:
http://msdn.microsoft.com/en-us/library/7f0aews7 (v = vs.80).aspx [


It''s documented here:
http://msdn.microsoft.com/en-us/library/7f0aews7(v=vs.80).aspx[^]

I usually embed the #pragma in the header file, so all that''s required is to #include the right header, and the linker has all the information it needs - nice and simple :)

Regards
Espen Harlinn


这篇关于如何将DLL包含到EXE.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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