VC++开发GIS系统(3)关于#ifndef#define#endif的说明

在我之前的文章使用DLL导出类编程示例中使用到了下面的这样一组代码。

#ifndef _CALLDLG_H_EXPORT
#define CALLDLG_EXPORT __declspec(dllimport)
#else
#define CALLDLG_EXPORT __declspec(dllexport)
#endif

并且在文章warning C4273: dll链接不一致对产生的warning进行了说明和改正。但是很多朋友可能并不了解这代码的含义,包括我本人在内。本文尝试做一个简单的说明。

头文件的重复包含

其实最常见的就是在头文件的重复包含问题的解决上,通常在写头文件的时候会有下面这样的代码。

#ifndef _MYHEADER_H_ 
#define _MYHEADER_H_

//yourcode

#endif

在理论上来说_MYHEADER_H_可以是自由命名的,但每个头文件的这个“标识”都应该是唯一的。标识的命名规则一般是头文件名全大写,前后加下划线,并把文件名中的“.”也变成下划线,如:myheader.h(参考)

条件编译

另外的一种应用也比较常见,就是条件编译。如:

#ifdef _DEBUG
     TRACE("debug mode");
#else
     //release mode
#endif

如果在debug模式下可以查看相关信息,而在release模式下就看不到。

关于DLL导出

也许许多人就是为了看这个的,在之前的文章中我也就是用了这样的代码:

#ifndef _CALLDLG_H_EXPORT
#define CALLDLG_EXPORT __declspec(dllimport)
#else
#define CALLDLG_EXPORT __declspec(dllexport)
#endif

这代码的意义就是:这样在DLL代码本身就是__declspec(dllexport) ,在使用DLL的程序中就变成了__declspec(dllimport),这两标志分别用来指明当前的函数将被导出,和当前函数是被导入的(参考)。

如您有疑问,可在文末留言,或到QQ群提问。
本站QQ群:291616564 麻辣GIS
微信公众号:malagis,扫描二维码直接关注。

打赏¥1

作者:,GIS爱好者。
分享本文,请您带上本文链接
分享到:

发表评论

RTK
  • 3S plus
  • 3SWorld Tialk程i
  • < r· rss="""""""""""""p://malagis.com/the-map-curriag/教pos%E5%AE%9E%E8%B7%B5%E6%95%99%E7%A8%8B/ 教程汇总 < r· rss="""""""""""""p://malagis.com/the-map-curriag/教pos%E5%88%B6%E5%9B%BE%E6%89%8B%E5%86%8C/ 教程戶程篇  r· rss="""""""""""""p://malagis.com/the-map-curriag/教pos-Server-%E5%85%A5%E9%97%A8/ 教程 Server 汇总  r· rss="""""""""""""p://malagis.com/the-map-curriag/教pos-Server-%E6%95%99%E7%A8%8B/ 教程 Server < r· rss="""""""""""""p://malagis.com/the-map-curriag/pos%E7%A9%BA%E9%97%B4%E6%95%B0%E6%8D%AE%E6%A8%A1%E5%9E%8B/ 值方法対程程整 < r· rss="""""""""""""p://malagis.com/the-map-curriag/vc/ vc++ < r· rss="""""""""""""p://malagis.com/the-map-curriag/pos%E6%8B%93%E6%89%91%E5%85%B3%E7%B3%BB/ 值拓扑风) < r· rss="""""""""""""p://malagis.com/the-map-curriag/gger-/ gger- < r· rss="""""""""""""p://malagis.com/the-map-curriag/revpos-10/ revpos < r· rss="""""""""""""p://malagis.com/the-map-curriag/revpos-10-%E4%BA%8C%E6%AC%A1%E5%BC%80%E5%8F%91%E5%85%A5%E9%97%A8/ revpos 二次统教汇总 < r· rss="""""""""""""p://malagis.com/the-map-curriag/pos%E6%95%B0%E6%8D%AE%E8%8E%B7%E5%8F%96/ 值毾程获取 < r· rss="""""""""""""p://malagis.com/the-map-curriag/15_2">15_ < r· rss="""""""""""""p://malagis.com/the-map-curriag/web15_2">web15_ < r· rss="""""""""""""p://malagis.com/the-map-curriag/%E7%A9%BA%E9%97%B4%E6%95%B0%E6%8D%AE%E7%BB%84%E7%BB%87/ 方法対程组织 < r· rss="""""""""""""p://malagis.com/the-map-curriag/%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE/坐标转换 < r· rss="""""""""""""p://malagis.com/the-map-curriag/ribbon/">ribbon < r· rss="""""""""""""p://malagis.com/the-map-curriag/%E9%9B%85%E5%AE%89%E5%9C%B0%E9%9C%87/ 雅安转震 < r· rss="""""""""""""p://malagis.com/the-map-curriag/IO%E6%A8%A1%E5%9D%97/ IO程杗 < r· rss="""""""""""""p://malagis.com/the-map-curriag/%E7%AA%97%E5%8F%A3%E9%87%8D%E7%BB%98/ 窗口重绘 tit js filea-end0);">G typ福text/oid(0);">G//malagis.com/usr/themes/krrrrr/images/grey.jsriab.js 0);">Gend0);">G typ福text/oid(0);">G//malagis.com/cdn.staticfile.org/jquery.orig tit/1.9.1/jquery.orig tit.min.js 0);">Gend0);">G typ福text/oid(0);">G/$('p:/.orig').orig tit({t class=effect:'fadeIn' clas}).removeC>$('#mob ').click(orithm-p(){/div>v>$("#cippnav").slideToggle('fast');/div>});/div>/div> /div>$( '#r"> v>callback : orithm-p(){/div>v>v>$( this ).find( '.l-contai> :not(. )' ).t ger( 'orig tit' )ript> }/div>});/div>$( '#r">
      v>$( 'p:/.orig2', this ).orig tit({t class=s=effect:'fadeIn' clasv>});/div>});/div>$( '#r"> v>callback : orithm-p(){/div>v>v>$( this ).find( '.l-contai> :not(. )' ).t ger( 'orig tit' )ript> }/div>});/div>$( '#r"> v>$( 'p:/.orig2', this ).orig tit({t class=s=effect:'fadeIn' clasv>});/div>});/div>//backtotop/div>var $backToTopEle =>$(' bar"">v>$("gger, bodg").an1.pte({t0);ollTop: 0 }, 360);/div>}), $backToTopFun =>orithm-p() {//div>v>var st =>$(docusyst).0);ollTop(), winh =>$(window). (),itleWight =>$(window).eight()ript> (st > 0&&itleWight>960)? $backToTopEle.show(): $backToTopEle. ()rdiv>/div> //IE6下的定位/div> if (!window.XMLHs.cRequest) {/div>v>v>v>$backToTopEle.c/d(-top", st + winh - 166)rdiv>/div> }/div>};/div>$(window).bind("0);oll", $backToTopFun);/div>$(orithm-p() {/div>v>$backToTopFun()rd/div>});/div>/div> /div>v> // modifyH ();/div>$(window).resize(orithm-p() {/div>v>// modifyH ();/div>});/div>// -e="dis-fix/div>$(window).-p('0);oll', orithm-p(evyst) {/div>v>// /div> if($("# board"). ()<$("#reqn"). ()){/div>v>v>if($("# board"). ()+$(docusyst).0);ollTop()>=$("#reqn"). ()){/div>v>v>v>var 装= $("#reqn"). () - $("# board"). ()-25;/div>v>v>v>$("# board").c/d({ poormm-p: "absolut, top: 装+"px">});/div>div>}else{/div>v>v>v>$("# board").c/d({ poormm-p: "fixed, top: "auto">});/div>div>} v>div>}else{/div>v>v>$("# board").c/d({ poormm-p: "static, top: "auto">});/div>di} v>div>/div>v>// /div>v> H Resize();/div>di/div>});/div>/di});/di/**/di* 自动调整程杗高度/di**//diorithm-p modifyH (){/div>var v= itle ();/div>var wh =>$(window). ();/div>var mh= $("#reqn"). ();/div>var sh= $("#div cla"). ();/div>if(v['eight']>940){/div>v>if(wh>371){/div>v>v>var tph= wh - 329;/div>v>v>$('.-change"> <').c/d({ e"> : tph+"px",l" tfdis:"auto"});/div>di}else{/div>v>v>$('.-change"> <').c/d({ e"> : "auto",l" tfdis:"visible"});/div>di} v>div> H Resize();/div>} v>}/di/**/di* 右边高度自动调整/di*//diorithm-p H Resize(){/div>var v= itle ();/div>var sc =>$(docusyst).0);ollTop();/div>var r">h= $("#r"> var mh= $("#reqn"). ();/div>var h =>$(window). ();/div>var sh= $("#div cla"). ();/div>var ruih= $("#r"> if(mh-200>sh&&ip['eight']>940&&h>371){/div>v>var fw=$("#r"> r">h= r">h+ 275+ 108ript> $("#div cla-e="dis,#r"> diif(sch){/div>v>v>$("#r"> div>$("#div cla-e="dis").c/d({poormm-p: "static, top: "auto"});/div>div>//$("#gomoney").c/d({poormm-p: "static, top: "auto"});/div>di}/div>diif(sc>r">h&&sc+ruih+275v>v>$("#r"> div>$("#div cla-e="dis").c/d({poormm-p: "fixed, top: 25+ruih+"px"});/div>di}/div>diif(sc+ruih+275>mh-25){/div>v>v>var roph= mh - 275;/div>v>v>$("#r"> div>$("#div cla-e="dis").c/d({poormm-p: "absolut, top: roph+"px"});/div>di}/div>} v>}/di/**/di* 获取外部宽度/di**//diorithm-p itle (){/div>var e =>window/div>, a =>'inif ( !(>'inwindow ) )/div>{/div>a =>'cli="ja;/div>e =>docusyst.docusystElesyst ||>docusyst.bodg;/div>} v>v> eturn {height : e[ a+'Wight' ]>, : e[ a+'H ' ]>} v>}/ 0);">Genssg-->code h l> s cla el="stylesheet://malagis.com/cdn.staticfile.org/h l> .js/8.3/styles/monokai_sublime.min.c/d"/i cld0);">G malagis.com/cdn.staticfile.org/h l> .js/8.3/h l> .min.js 0);">Gencld0);">G>hljs.initH l> ingOnLtit(); 0);">Genssg-->tooltips s cla el="stylesheet:/typ福text/c/d"//malagis.com/the-map-currutrrr/images/grey.jsriooltipster/c/driooltipster.bundle.min.c/d" /i cld0);">G typ福text/oid(0);">G//malagis.com/usr/themes/krrrrr/images/grey.jsriooltipster/jdriooltipster.bundle.min.js 0);">Gencld0);">G>/div>$(docusyst).ready(orithm-p() {/div>v>$('.iooltip').iooltipster({/div>v>v>an1.ptm-p: 'fade',/div>v>v>t ger:>'click' clasv>});/div>});/di 0);">Genssg-->bdsharea-encld0);">G>/div>window._bd_share_config =>{/div>v>common : { /div>v> bdSnsKey: { 'tsina':>'1237936374'>} v>div>}, /div>v>share : [{/div>v> bdCadmimStyle:'is.com/usr/themes/krrrrr/images/grey.bdshare.c/d' clasv>}]/div>} v>v>wiht(docusyst)0[(getElesystsByTagName('head')[0]||bodg).appendChild(createElesyst('0);">G')).0ala'is.com/bdp:/.share.ordinmes/kstatic/api/jdrshare.js?cdn" tours='+~(-new Dpte()/36e5)];/di 0);">Genssnssg-->brdin searcha-end0);">G typ福text/oid(0);">G/> (orithm-p(){docusyst.write(unescape('%3Cbar"> docusyst.createElesyst('0);">G');bdcs.typ =>'text/oid(0);">G';bdcs.async =>true;bdcs.0al =>'is.com/znsv.ordinmes/kcadmimer_search/api/jd?div=13402638098849232559'+ '&plate_url='+ encodeURIComponest(window.loctitle="mal)+ '&t='+ Math.ceil(new Dpte()/3600000);var s =>docusyst.getElesystsByTagName('0);">G')[0];s.-cf="jNodeeinsertBee(bdcs, s);})()ri//brdin srm"r (orithm-p(){/div>var bp =>docusyst.createElesyst('0);">G');/div>var curProtocol =>window.loctitle=protocol.split(':')[0];/div>if (curProtocol ===>'is.cs') {/div>v>v>bp.0al =>'is.csom/zz.bdstaticg-leafttp} v>v>else {/div>v>v>bp.0al =>'is.com/padh.z z g.ordinmes/kpadh.js'r/div>} v>v>var s =>docusyst.getElesystsByTagName("0);">G/)[0];/div>s.-cf="jNodeeinsertBee(bp, s); })()ri 0);">Geni bodg