如何在Visual Studio中正确设置exe的入口点? [英] How do I correctly set the entry point for an exe in Visual Studio?

查看:2527
本文介绍了如何在Visual Studio中正确设置exe的入口点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了进入点WinMain,但是当我运行应用程序,它开始,不显示,然后我必须关闭它与任务管理器。这里是代码到WinMain():

I have set the entry point to WinMain but when I run the app it starts and doesn't display, I then have to shut it with task manager. Here's the code upto WinMain() :

#include <Windows.h>

// forward declarations
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 

// The entry point into a windows program
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int windowStyle )
{
....

我没有C ++的经验,我不知道这是做什么,我的exe更小,这是我想实现。

I'm not experienced in C++, and I don't know what this is doing, except making my exe smaller, which is what I'm trying to achieve.

编辑:我想做的是创建一个非常小的窗口EXE,了解如何演示代码工作。所以我想创建一个小的c ++窗口应用程序提供了一个窗口句柄,我可以附加SlimDX(如果我可以静态链接最终的c ++ dll到一个C#应用程序,但我还没有)我有我的BasicWindow .exe下载到6,656字节。所以我正在尝试任何我可以找到的尺寸到<3k。

edit : What I'm trying to do is create a very small window exe to understand how demo coder's work. So I'm thinking of creating a small c++ window app that provides a window handle to which I can attach SlimDX (if i can statically link the final c++ dll to a C# app, but I'm not there yet) I have my BasicWindow.exe down to 6,656 bytes. So I'm experimenting with anything I can find to get that size down to <3k.

[2012.Jan.10]我已经取得了一些成功重建minicrt(可从 http://www.benshoof.org/blog/small-programs/ )在VS2010下添加它作为附加依赖。我不能忽略所有默认库,建议,但我现在有一个Windows应用程序的exe大小为4,096字节。我会说这是一些重大的成功。我现在在惊人的距离。每一次从这里减少,是更多的空间为SlimDX。我很幸运考虑到我所写的唯一的c ++应用程序是控制台应用程序和一个基本的窗口:)我很幸运我知道!

[2012.Jan.10] Well I've had some success by rebuilding minicrt (available from http://www.benshoof.org/blog/small-programs/) under VS2010 and adding it as an additional dependency. I couldn't Ignore All Default Libraries as suggested, but I now have a Windowed application with an exe size of 4,096 bytes. I'd say that's some significant success. I'm within striking distance now. Every reduction from here on in, is more room for SlimDX. I'm pretty happy considering the only c++ apps I've ever written are console apps and a basic window :) I've been lucky I know !

推荐答案

典型的应用程序不应该搞乱链接器的入口点设置。应该在标准运行时库(对于Windows子系统的unicode应用程序 wWinMainCRTStartup )中包含的函数上设置入口点。这个函数做的东西喜欢CRT的正确初始化和全局对象的创建。通过重新路由入口点到你的 WinMain ,你会得到未定义的行为,除非你知道你正在做什么,并以某种方式实现CRT初始化在你自己的 WinMain 。在我看来,由此导致的规模减少将是可以忽略的,整个事件几乎不值得冒险。

A typical application should not mess up with Entry point setting of linker. Entry point should be set on a function included in the standard runtime library (which is wWinMainCRTStartup for unicode application for windows subsystem). This function does stuff like the proper initialization of CRT and creation of global objects. By rerouting entry point to your WinMain you will get undefined behavior unless you know precisely what you are doing and somehow implementing CRT initialization in your own WinMain. In my opinion the resulting size decrease will be negliable and the whole affair is hardly worth the risk.

这篇关于如何在Visual Studio中正确设置exe的入口点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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