首页 > REDM基础教程 > REDM基础教程14-单EXE方式
2016十一月28

REDM基础教程14-单EXE方式

  MyRes+Test下载–>

Test.zip

MyRes.zip

    

    单独的exe工程下载–>

MyTest.zip (MyRes.zip不需要放在exe同目录下,已内嵌)

zlib.zip (放在exe同目录下)

   


    

有时我们只想发一个单独的EXE出去,不想带上DMMain.dll,也不想带上MyRes资源包,这里做下简单的介绍:

   

1.使用DMMain的lib库方式链接, 编译CMake时,把USE_DMDLL_勾选去掉:

 1.png

编译后,我们应该变成了一个Test.exe+MyRes资源包这样的方式运行了

  

2.默认内置的资源包就是一个文件夹,但DM库在插件Plugin_Expand还支持zip打包资源包, 对应的文件是

PlugIns\Plugin_Expand\inc\Res\DMResZipImpl.h
PlugIns\Plugin_Expand\src\Res\DMResZipImpl.cpp

以及它们的辅助文件类:
PlugIns\Plugin_Expand\inc\Res\DMZipHelper.h
PlugIns\Plugin_Expand\src\Res\DMZipHelper.cpp
PlugIns\Plugin_Expand\inc\Res\DMResZipParam.h
PlugIns\Plugin_Expand\inc\Res\DMResZipHelper.h
PlugIns\Plugin_Expand\src\Res\DMResZipHelper.cpp

zip文件头:
3rdParty\zlib\zconf.h
3rdParty\zlib\zlib.h

下面简单介绍下怎么在exe中使用它们,其实就是把插件的代码移到我们的exe工程中,改下预编译头,再Register下   

      

3.我们把它们拷贝出来,分别把.h文件全部放在Test的inc文件夹下,.cpp文件全部放在Test的src文件夹下,然后点击cmake的Generate按扭自动添加到vs工程中

编译:

>DMZipHelper.cpp
1>..\..\Test\src\DMZipHelper.cpp(1) : warning C4627: '#include "Plugin_ExpandAfx.h"': skipped when looking for precompiled header use
1>        Add directive to 'StdAfx.h' or rebuild precompiled header
1>..\..\Test\src\DMZipHelper.cpp(2) : warning C4627: '#include "DMZipHelper.h"': skipped when looking for precompiled header use
1>        Add directive to 'StdAfx.h' or rebuild precompiled header
1>..\..\Test\src\DMZipHelper.cpp(3) : warning C4627: '#include <zconf.h>': skipped when looking for precompiled header use
1>        Add directive to 'StdAfx.h' or rebuild precompiled header
1>..\..\Test\src\DMZipHelper.cpp(4) : warning C4627: '#include <zlib.h>': skipped when looking for precompiled header use
1>        Add directive to 'StdAfx.h' or rebuild precompiled header
1>..\..\Test\src\DMZipHelper.cpp(842) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
1>DMResZipImpl.cpp
1>..\..\Test\src\DMResZipImpl.cpp(1) : warning C4627: '#include "Plugin_ExpandAfx.h"': skipped when looking for precompiled header use
1>        Add directive to 'StdAfx.h' or rebuild precompiled header
1>..\..\Test\src\DMResZipImpl.cpp(2) : warning C4627: '#include "DMResZipImpl.h"': skipped when looking for precompiled header use
1>        Add directive to 'StdAfx.h' or rebuild precompiled header
1>..\..\Test\src\DMResZipImpl.cpp(3) : warning C4627: '#include "DMResZipParam.h"': skipped when looking for precompiled header use
1>        Add directive to 'StdAfx.h' or rebuild precompiled header
1>..\..\Test\src\DMResZipImpl.cpp(551) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
1>DMResZipHelper.cpp
1>..\..\Test\src\DMResZipHelper.cpp(1) : warning C4627: '#include "Plugin_ExpandAfx.h"': skipped when looking for precompiled header use
1>        Add directive to 'StdAfx.h' or rebuild precompiled header
1>..\..\Test\src\DMResZipHelper.cpp(2) : warning C4627: '#include "DMResZipHelper.h"': skipped when looking for precompiled header use
1>        Add directive to 'StdAfx.h' or rebuild precompiled header
1>..\..\Test\src\DMResZipHelper.cpp(53) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
1>Generating Code...

 

  

这种错误,和之前的类似,把Plugin_ExpandAfx.h全部替换成StdAfx.h(预编译头改变了),还有一个错误,未找到zlib.lib

3>LINK : I:\MyTest\Build2008\bin\Debug\Test.exe not found or not built by the last incremental link; performing full link
3>LINK : fatal error LNK1104: cannot open file 'zlib_d.lib'

这个错误,我们打开DM库,编译3rdParty下的zlib,生成zlib_d.lib即可:

2.png

生成的lib位于DM库自身的bin目录下,把生成的zlib_d.lib拷贝到MyTest的bin目录下(如:MyTest\Build2008\bin\Debug\zlib_d.lib),OK,这样就编译成功了

      

4.外置zip加载

在Test.cpp中加入注册并加载zip打包资源的代码,类似于DM库的PlugIns\Plugin_Expand\src\Plugin_Expand.cpp中的注册:

g_pDMApp->Register(DMRegHelperT<DMResZipImpl>(),true);
g_pDMApp->SetDefRegObj(DMResZipImpl::GetClassName(),DMResZipImpl::GetClassType());// 把zip打包设置为默认
DMResZipParam zipres(L"MyRes.zip");
theApp.LoadResPack((WPARAM)(&zipres),NULL,NULL);

或者

g_pDMApp->Register(DMRegHelperT<DMResZipImpl>(),true);
DMResZipParam zipres(L"MyRes.zip");
theApp.LoadResPack((WPARAM)(&zipres),NULL,L"DMResZipImpl");// 未设置默认,就在这里强制传入DMResZipImpl字符串

    

5.把MyRes的内容打包成zip,注意,zip包不要带上MyRes这个文件夹,放在bin目录下,运行:

1.gif

     

6.内置zip加载

把我们生成的MyRes.zip放在Test\inc\目录下,新建一个ZIP类型的资源包,资源名就叫IDR_ZIP1

18.gif

   

这时我们注意到,生成的resource.hTest.rc是位于bin目录的,我们把它们移到Test\inc目录下,并修改MyTest\Test\CMakeLists.txt(让它自动加入.rc文件)

# CMAKE_CURRENT_SOURCE_DIR宏指当前CMakeLists.txt所在的目录,即Test文件夹目录
FILE(GLOB ROOT_HEADER 		${CMAKE_CURRENT_SOURCE_DIR}/inc/*.h;${CMAKE_CURRENT_SOURCE_DIR}/inc/*.rc)# 把Test\inc\*.h 设置为ROOT_HEADER标识宏

在Test.cpp中加入注册并加载zip打包资源的代码

g_pDMApp->Register(DMRegHelperT<DMResZipImpl>(),true);					// 注册zip打包Res
	g_pDMApp->SetDefRegObj(DMResZipImpl::GetClassName(),DMResZipImpl::GetClassType());// 把zip打包设置为默认
	//DMResZipParam zipres(L"MyRes.zip");
	DMResZipParam zipres(hInstance,MAKEINTRESOURCE(IDR_ZIP1),L"ZIP");
	theApp.LoadResPack((WPARAM)(&zipres),NULL,NULL);
	//theApp.LoadResPack((WPARAM)(L"MyRes"),NULL,NULL);						// 路径总是相对于生成目录

特别注意,第二个参数要使用MAKEINTRESOURCE这个宏

      

这时,内置zip资源包的单独exe生成了

19.gif

当然,如果你更小心点的话,可以把Test.rc以文本方式打开,把其中的MyRes.zip路径改成相对路径:

IDR_ZIP1                ZIP                     ".\\inc\\MyRes.zip"

      

    下一节教程:REDM基础教程15-增加托盘功能


    

      





文章作者:hgy413
本文地址:http://hgy413.com/3830.html
版权所有 © 转载时必须以链接形式注明作者和原始出处!

17 Responses to “REDM基础教程14-单EXE方式”

  1. #1 minecraft 回复 | 引用 Post:2019-04-04 14:12

    Its like you learn my thoughts! You appear
    to understand so much approximately this, such as
    you wrote the e-book in it or something. I feel that you just can do with
    some % to pressure the message house a bit, but instead of that, that is fantastic blog.
    An excellent read. I will certainly be back.

  2. #2 minecraft 回复 | 引用 Post:2019-04-05 16:23

    I visited many web sites however the audio feature for audio songs present
    at this site is truly fabulous.

  3. If you would like to grow your experience only keep visiting this web site
    and be updated with the hottest news posted
    here.

  4. Howdy just wanted to give you a quick heads up. The text in your post seem to be running off the screen in Ie.
    I’m not sure if this is a format issue or something to do with internet browser compatibility
    but I thought I’d post to let you know. The design look great though!
    Hope you get the problem resolved soon. Cheers

  5. #5 download minecraft pc 回复 | 引用 Post:2019-05-10 04:15

    Undeniably consider that that you said. Your favorite reason appeared to be on the net the simplest thing to keep in mind of.
    I say to you, I definitely get irked at the same time as other folks
    consider issues that they just don’t realize about. You controlled to hit the nail
    upon the top as well as defined out the whole thing without having side-effects ,
    other folks could take a signal. Will probably be again to get more.
    Thanks

  6. #6 minecraft free 回复 | 引用 Post:2019-05-14 17:31

    My relatives always say that I am killing my time here at web, however I know I
    am getting experience every day by reading thes good articles or reviews.

  7. I blog frequently and I really thank you for your
    content. The article has truly peaked my interest.
    I will bookmark your blog and keep checking for new details
    about once a week. I opted in for your RSS feed as well.

  8. #8 free minecraft download 回复 | 引用 Post:2019-05-17 02:32

    hey there and thank you for your information – I have definitely picked up anything new from right here.

    I did however expertise some technical issues using this website, as I experienced to reload
    the web site many times previous to I could get it
    to load correctly. I had been wondering if your web host is OK?
    Not that I’m complaining, but slow loading instances times will sometimes
    affect your placement in google and can damage your high quality
    score if advertising and marketing with Adwords. Well I am adding this RSS to my
    email and could look out for much more of your respective exciting content.
    Ensure that you update this again soon.

  9. Hey there! I know this is kinda off topic but I was wondering if you knew where I could find a captcha plugin for my comment form?

    I’m using the same blog platform as yours and I’m having problems
    finding one? Thanks a lot!

  10. #10 gamefly free trial 回复 | 引用 Post:2019-06-03 21:54

    Hello There. I discovered your weblog using msn.
    This is a very smartly written article. I will make sure to bookmark
    it and come back to learn extra of your helpful info.
    Thanks for the post. I’ll certainly comeback.

  11. #11 gamefly free trial 回复 | 引用 Post:2019-06-06 11:06

    Does your site have a contact page? I’m having problems locating
    it but, I’d like to send you an email. I’ve got some ideas for
    your blog you might be interested in hearing.
    Either way, great blog and I look forward to seeing it develop over time.

  12. #12 new playstation 4 games 回复 | 引用 Post:2019-06-08 00:20

    I am curious to find out what blog platform you’re
    using? I’m having some minor security issues with my latest website and I’d like to find something more safe.
    Do you have any recommendations?

  13. Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something.
    I think that you could do with a few pics to drive the message home
    a bit, but instead of that, this is magnificent blog. A great read.
    I will certainly be back.

  14. #14 quest bars cheap 回复 | 引用 Post:2019-06-14 06:04

    Thanks for finally talking about >blog topic <Loved it!

  15. #15 quest bars cheap 回复 | 引用 Post:2019-06-14 08:00

    Hi there, just became alert to your blog through Google, and found that
    it is truly informative. I’m gonna watch out for brussels.
    I will appreciate if you continue this in future.

    Many people will be benefited from your writing.

    Cheers!

  16. #16 quest bars cheap 回复 | 引用 Post:2019-06-14 20:05

    Hello are using WordPress for your site platform? I’m new to the blog world but
    I’m trying to get started and set up my own. Do you need any
    html coding knowledge to make your own blog? Any help would
    be really appreciated!

  17. #17 http://tinyurl.com 回复 | 引用 Post:2019-06-17 04:47

    I do agree with all of the ideas you have introduced for your post.

    They are very convincing and can definitely work.
    Still, the posts are very brief for novices. May you please prolong them a
    bit from subsequent time? Thank you for the post.

发表评论