在Win32程序中使用main()函数替换WinMain() [英] Replacing WinMain() with main() function in Win32 programs
问题描述
我在StackOverflow和Google上搜索了一些,但是没能得到想法。我想使用此类型的用户编程启动我的应用程序:
int main()
{
窗口应用程序(Test,640,480);
while(App.IsOpen())
{
//做东西
}
}
但这是不可能的,因为我应该将hInstance和hPrevInstance等参数传递给WinMain函数。实际上有一个Window类,我设计它使窗口创建一点点更容易。我在SFML上看到这个实现,但我不知道它是如何实现的。
现在我使用通常的方式:
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR,int)
{
Window App(hInst,hPrevInst,Test ,640,480);
while(App.IsOpen())
{
//做东西
}
}
解决方案您可以使用标准如果将以下内容添加到Microsoft链接器选项中,则即使使用Microsoft工具,也可以在Windows应用程序(即GUI子系统Windows应用程序)中创建
main >
/ subsystem:windows / ENTRY:mainCRTStartup
注意,这不是GNU工具链必需的。
仍然对于Microsoft工具,您可以将其添加到您的主文件: / p>
#ifdef _MSC_VER
#pragma comment(linker,/ subsystem:windows / ENTRY:mainCRTStartup)
#endif
@James McNellis告诉你如何获得hInstance。
I searched a little bit on StackOverflow and Google but couldn't get the idea. I want to start my application with this type of user programming:
int main() { Window App("Test", 640, 480); while(App.IsOpen()) { // Do the stuff } }
But this isn't possible because I should pass the hInstance and hPrevInstance and other parameters to a WinMain function. Actually there is a Window class which I designed it to make the Window creation a little bit easier. I saw this implementation on SFML but I don't know how it did come to this.
Right now I'm using the usual way:
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR, int) { Window App(hInst, hPrevInst, "Test", 640, 480); while(App.IsOpen()) { // Do the stuff } }
Thanks.
解决方案You can use standard
main
in a "windows" app (that is, a GUI subsystem Windows application) even with the Microsoft tools, if you add the following to the Microsoft linker options:/subsystem:windows /ENTRY:mainCRTStartup
Note that this is not necessary for the GNU toolchain.
Still for the Microsoft tools you can alternatively add this to your main file:
#ifdef _MSC_VER # pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup") #endif
@James McNellis tells you how to get the hInstance.
这篇关于在Win32程序中使用main()函数替换WinMain()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!