简体   繁体   English

如何在Visual Studio 2010 Express的Win32应用程序中使用Win32类库?

[英]How do I use a Win32 Class Library in a Win32 Application in Visual Studio 2010 Express?

As stated, I'm trying to use the class library in the application. 如上所述,我正在尝试在应用程序中使用类库。

Specifically, I've got a (very small) test Console class with one Write(std::string) function. 具体来说,我有一个(非常小的)测试Console类,有一个Write(std :: string)函数。 I want to access the class library, access the Console class and successfully send a std::string to the Write function. 我想访问类库,访问Console类并成功将std :: string发送到Write函数。

I don't, specifically, need to know how to use a class or a function (I'm a C++ newbie only, not a coding newbie), just get my library working with my application in VSE. 具体而言,我不需要知道如何使用类或函数(我只是一个C ++新手,而不是编码新手),只是让我的库在VSE中使用我的应用程序。

Not sure what else to add, but I'm not that good at figuring out what to add and, in this case, I'm not even sure what questions to ask. 不知道还有什么要补充,但我不太擅长弄清楚要添加什么,在这种情况下,我甚至不确定要问什么问题。

Thanks. 谢谢。

First of all you need to decide how you wish to link your 'library' code. 首先,您需要确定如何链接“库”代码。 Do you want it to be static or dynamic? 你想要它是静态的还是动态的? Static linking means the library you wrote gets 'merged' with your exe. 静态链接意味着您编写的库与exe“合并”。 So your exe file will be: 所以你的exe文件将是:

size-of-exe-code + size-of-lib (roughly, just remember that the exe size increases with the lib) size-of-exe-code + lib-size(粗略地,只记得exe大小随lib增加)

With the dynamic link approach (DLL), you have a DLL version of your console library (console.dll) and a lib file (console.lib). 使用动态链接方法(DLL),您有控制台库的DLL版本(console.dll)和lib文件(console.lib)。 I'm not going to explain how to code a DLL because there is a bit of reading to do . 我不打算解释如何编写DLL,因为有一些阅读要做 (Also google to find out more). (还谷歌了解更多)。 With the DLL version your exe size wouldn't increase size with your library because the DLL contains that part of the code and gets linked dynamically at runtime, while with static linking, it's done when linking the exe and creating it (more or less). 使用DLL版本,你的exe大小不会增加你的库的大小,因为DLL包含代码的那部分并在运行时动态链接,而使用静态链接,它是在链接exe和创建它时(或多或少)完成的。

The simplest is to statically link your console library. 最简单的方法是静态链接您的控制台库。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM