- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
WTL 应用程序已经非常小了。但是,对于 Win32 配置,使用 VS 2005 和 WTL 9.10 的静态链接应用程序的重量为 136 kB(139,264 字节)。
查看可执行文件时,我注意到 oleaut32.dll
的静态导入。使用 dumpbin
粗略地看一下,显示了一个通过 ordinal 的导入。
OLEAUT32.dll
4181C0 Import Address Table
41C9B8 Import Name Table
0 time date stamp
0 Index of first forwarder reference
Ordinal 277
检查 oleaut32.dll
发现导出名为 VarUI4FromStr
。
深入研究 IDA,我发现 VarUI4FromStr
被 ATL::CRegParser::AddValue
使用。从那里跟随家属,在 ATL::CRegParser::RegisterSubkeys
中显示了两个调用。
将我的 Visual Studio 安装的 ATL 代码与调查结果进行交叉引用,我发现罪魁祸首是 ATL::CAtlComModule
。它做了很多我的用例不需要的 TypeLib 注册工作。
但是,链接器似乎将所有这些都留在了里面,因为它无法合理地决定将其丢弃。
我怎样才能摆脱这个看似多余的导入?
最佳答案
唉,因为WTL::CAppModule
直接来自 ATL::CComModule
,包括 atlbase.h
header 同时具有 _ATL_NO_COMMODULE
定义导致错误:
Error 1 fatal error C1189: #error : WTL requires that _ATL_NO_COMMODULE is not defined $(ProjectDir)\wtl\Include\atlapp.h 33
最终拉入 ATL::CComModule
的真正罪魁祸首然而,是 ATL::CAtlComModule
.所以我们的目标是摆脱它们。
我们会尝试欺骗 atlbase.h
通过定义 _ATL_NO_COMMODULE
排除所有 TypeLib 注册码无论如何,但是在我们完成包含它之后立即取消定义它。这条路atlapp.h
和其他 WTL header 不会“注意到”。
#define _ATL_NO_COMMODULE
#include <atlbase.h>
#undef _ATL_NO_COMMODULE
#include <atlapp.h>
显然这给我们带来了一些麻烦:
1>atlapp.h(1515) : error C2039: 'CComModule' : is not a member of 'ATL'
1>atlapp.h(1515) : error C2504: 'CComModule' : base class undefined
1>atlapp.h(1524) : error C2653: 'CComModule' : is not a class or namespace name
1>atlapp.h(1543) : error C2653: 'CComModule' : is not a class or namespace name
1>atlapp.h(1625) : error C3861: 'GetModuleInstance': identifier not found
1>atlapp.h(1784) : error C2653: 'CComModule' : is not a class or namespace name
1>atlapp.h(1806) : error C2065: 'm_nLockCnt' : undeclared identifier
但是,看起来我们应该能够快速修复这一小部分错误。
首先让我们检查一下ATL::CComModule
在哪里来自:它在 atlbase.h
中声明和 .我们当然可以声明我们自己的类并将其挤在中间 #include <atlbase.h>
和 #include <atlapp.h>
(见上文)。
让我们从基础开始,基于可以在 atlbase.h
中找到的内容:
namespace ATL
{
class CComModule : public CAtlModuleT<CComModule>
{
public:
CComModule() {}
};
};
现在我们得到一组不同的错误:
1>atlapp.h(1524) : error C2039: 'Init' : is not a member of 'ATL::CComModule'
1> stdafx.h(31) : see declaration of 'ATL::CComModule'
1>atlapp.h(1625) : error C3861: 'GetModuleInstance': identifier not found
非常好,所以我们实际上只缺少两个类函数:GetModuleInstance
和 Init
.让我们把它们也拉进来。为了更好地衡量,我们还将添加 GetResourceInstance
:
namespace ATL
{
class CComModule : public CAtlModuleT<CComModule>
{
public:
CComModule() {}
HINSTANCE GetModuleInstance() throw() { return _AtlBaseModule.m_hInst; }
HINSTANCE GetResourceInstance() throw() { return _AtlBaseModule.m_hInstResource; }
HRESULT Init(_ATL_OBJMAP_ENTRY*, HINSTANCE, const GUID*) throw() { return S_OK; }
};
};
一个简短的测试证明这工作正常。和 oleaut32.dll
import 与来自 ole32.dll
的另外三个进口一起消失了.大获成功!
因此,我们节省了 12 kB 的可执行文件大小。
你知道其他缩小 WTL 应用程序大小的绝妙技巧吗?
请注意,取决于 ATL::CComModule
的特征您的代码使用的是什么,您可能必须回退到使用原始文件。唯一的另一种选择是扩展上述 ATL::CComModule
的模拟版本。修复您可能遇到的任何编译错误。
我还没有对此进行广泛的测试,如果遇到任何问题,我会报告(通过编辑此答案)。然而,从我更改之前的 ATL 和 WTL 代码以及 IDA 数据库中查看它,我认为这是一个安全的更改。
您还可以使用 6001.18002 独立 WDK(适用于 Vista SP1),它支持面向 Windows 2000 (SP4) 和更新版本。它包含 ATL 7.0,因此适合构建 ATL+WTL 应用程序。
为此,您只需将以下两行添加到您的 sources
文件:
USE_STATIC_ATL=1
ATL_VER=70
Thanks to the WDK, which uses msvcrt.dll
, a system DLL, as its default (multithreaded dynamically linked) C runtime ,然后您可以通过动态 链接到 C 运行时来进一步缩小可执行文件的大小。在这种情况下,由于特定的 C 运行时是一个系统 DLL(从 Windows 2000 开始),您可以放心它会工作。
考虑到所有这些,您可以构建非常小的标准 Windows 应用程序(GUI 或控制台)和 DLL。
这是一个例子 sources
您可以用作模板的文件:
# Name of the program
TARGETNAME=progname
# Prefix used for the intermediate/output paths (e.g. objfre_w2k_x86)
TARGETPATH=obj
# A program, not a driver or DLL or static lib
TARGETTYPE=PROGRAM
# windows == GUI, console == Console, native == no subsystem ...
UMTYPE=windows
# Use Unicode ("wide char") instead of ANSI
UNICODE=1
# By default the WDK build treats warnings as errors - this turns it off
BUILD_ALLOW_ALL_WARNINGS=1
# Link dynamically to msvcrt.dll
USE_MSVCRT=1
# Don't link against any of the ATL DLLs
USE_STATIC_ATL=1
# In the 7600.16385.1 WDK you can use 70 as well, which translates to 71
ATL_VER=70
USE_NATIVE_EH=1
# RTTI is required for some ATL/WTL features
USE_RTTI=1
# GUI programs require these entry points
!IF defined(UNICODE) && $(UNICODE)
UMENTRY=wwinmain
C_DEFINES=$(C_DEFINES) /DUNICODE /D_UNICODE
!ELSE
UMENTRY=winmain
C_DEFINES=$(C_DEFINES) /DMBCS /D_MBCS
!ENDIF
# Include folders
INCLUDES=$(DDK_INC_PATH);$(CRT_INC_PATH);$(SDK_INC_PATH);wtl\Include
# Libraries to link to, not just import libraries
TARGETLIBS=\
$(SDK_LIB_PATH)\kernel32.lib \
$(SDK_LIB_PATH)\user32.lib \
$(SDK_LIB_PATH)\Comctl32.lib \
# Give source files (also resources and .mc) in the current or parent directory
SOURCES=...
7600.16385.1 独立 WDK 也适用于此。从 Windows 8 WDK 开始的 WDK 现在需要可以将它们集成到其中的 Visual C++。这也导致二进制文件需要相应的 C 运行时版本而不是 msvcrt.dll
来自以前的 WDK 版本。
关于c++ - 如何缩小 WTL 应用程序的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36161640/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!