#include "StdAfx.h"
#include "resource.h"
#define szRDS _RXST("")
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CArxProject2App : public AcRxArxApp {
public:
CArxProject2App () : AcRxArxApp () {}
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
// TODO: Load dependencies here
// You *must* call On_kInitAppMsg here
AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
// TODO: Add your initialization code here
return (retCode) ;
}
virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
// TODO: Add your code here
// You *must* call On_kUnloadAppMsg here
AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;
// TODO: Unload dependencies here
return (retCode) ;
}
virtual void RegisterServerComponents () {
}
// Modal Command with localized name
// ACED_ARXCOMMAND_ENTRY_AUTO(CArxProject2App, MyGroup, MyCommand, MyCommandLocal, ACRX_CMD_MODAL)
static void MyGroupMyCommand () {
// Put your command code here
}
// Modal Command with pickfirst selection
// ACED_ARXCOMMAND_ENTRY_AUTO(CArxProject2App, MyGroup, MyPickFirst, MyPickFirstLocal, ACRX_CMD_MODAL | ACRX_CMD_USEPICKSET)
static void MyGroupMyPickFirst () {
ads_name result ;
int iRet =acedSSGet (ACRX_T("_I"), NULL, NULL, NULL, result) ;
if ( iRet == RTNORM )
{
// There are selected entities
// Put your command using pickfirst set code here
}
else
{
// There are no selected entities
// Put your command code here
}
}
// Application Session Command with localized name
// ACED_ARXCOMMAND_ENTRY_AUTO(CArxProject2App, MyGroup, MySessionCmd, MySessionCmdLocal, ACRX_CMD_MODAL | ACRX_CMD_SESSION)
static void MyGroupMySessionCmd () {
// Put your command code here
}
static int ads_MyLispFunction () {
return (RTNORM) ;
}
} ;
IMPLEMENT_ARX_ENTRYPOINT(CArxProject2App)
ACED_ARXCOMMAND_ENTRY_AUTO(CArxProject2App, MyGroup, MyCommand, MyCommandLocal, ACRX_CMD_MODAL, NULL)
ACED_ARXCOMMAND_ENTRY_AUTO(CArxProject2App, MyGroup, MyPickFirst, MyPickFirstLocal, ACRX_CMD_MODAL | ACRX_CMD_USEPICKSET, NULL)
ACED_ARXCOMMAND_ENTRY_AUTO(CArxProject2App, MyGroup, MySessionCmd, MySessionCmdLocal, ACRX_CMD_MODAL | ACRX_CMD_SESSION, NULL)
ACED_ADSSYMBOL_ENTRY_AUTO(CArxProject2App, MyLispFunction, false)
定义理解
1. __declspec(selectany)
__declspec是一个Microsoft Visual C++特定的编译器属性开关。括号中指明的是哪一个属性生效。关于__declspec的其他属性可以百度“__declspec msdn”查看微软的官方帮助。也可以参看博客中转载的文章。
c++ 中__declspec 的用法详解-面圈网 (mianshigee.com)
言归正传。__declspec(selectany)在MSDN中的说明是这样的:
Tells the compiler that the declared global data item (variable or object) is a pick-any
COMDAT (a packaged function). At link time, if multiple a definitions of COMDAT are
seen, the linker picks one and discards the rest. Selectany can be used in initializing
global data defined by headers,when the same header appears in more than one
source file.
简单翻译一下:告诉编译器定义的全局数据项(变量或对象)这是一套能被任意挑选的COMDAT(一套函数)。在链接时,如果多个COMDAT的定义被找到,链接器将挑选一个并剔除其他的多余的。Selectany可以被用于当定义有初始化全局变量数据的头文件被应用于多于一个的源文件时。
直白了说:当在头文件定义全局变量,并且这个头文件被include多次时可以用这个开关剔除由于多次include而产生的重定义。
_declspec(selectany)可以让我们在.h文件中初始化一个全局变量而不是只能放在.cpp中。比如有一个类,其中有一个静态变量,那 么我们可以在.h中通过类似" __declspec(selectany) type class::variable = value; "这样的代码来初始化这个全局变量。既是该.h被多次include,链接器也会为我们剔除多重定义的错误。这个有什么好处呢,我觉得对于 teamplate的编程会有很多便利。
(16条消息) 浅谈__declspec(selectany)该何时用_几罗星人的博客-CSDN博客
2. pragma comment
C语言Pragma 指令的作用是设定编译器的状态或者是指示编译器完成一些特定的动作。
C语言之pragma用法详解 (douban.com)
pragma comment将一个注释记录放入一个对象文件或可执行文件中
比如我们连接的时候用到了WSock32.lib,你当然可以不辞辛苦地把它加入到你的工程中。但是我觉得更方便的方法是使用#pragma指示符,指定要连接的库: #pragma comment(lib, "WSock32.lib")
linker:将一个链接选项放入目标文件中,你可以使用这个指令来代替由命令行传入的或者在开发环境中设置的链接选项,你可以指定/include选项来强制包含某个对象,例如: #pragma comment(linker, "/include:__mySymbol")文章来源:https://www.toymoban.com/news/detail-438206.html
3. extern "C" 是用来告诉编译器使用C的命名方式
4. __declspec(allocate("segname"))
_declspec(allocate("segname")) 声明一个已经分配了数据段的一个数据项。它和#pragma 的code_seg, const_seg, data_seg,section,init_seg配合使用,segname必须有这些东东声明。文章来源地址https://www.toymoban.com/news/detail-438206.html
#define __declspec(method) __declspec_##method
#define ARXCOMMAND_FIRST_ENTRYNAME "ARXCOMMAND$__m"
#define ACED_ARXCOMMAND_ENTRY_PRAGMA(group,globCmd) __pragma(comment(linker, "/include:__pArxCmdMap_" #group #globCmd)) ;
#define ACED_ARXCOMMAND_ENTRY_AUTO(classname, group, globCmd, locCmd, cmdFlags, UIContext) \
__declspec(selectany) _ARXCOMMAND_ENTRY __ArxCmdMap_##group##globCmd = { _RXST(#group), _RXST(#globCmd), _RXST(#locCmd), cmdFlags, classname::group ##globCmd, UIContext, 0 } ; \
extern "C" __declspec(allocate("ARXCOMMAND$__m")) __declspec(selectany) _ARXCOMMAND_ENTRY* __pArxCmdMap_##group##globCmd = &__ArxCmdMap_##group##globCmd ; \
ACED_ARXCOMMAND_ENTRY_PRAGMA(group, globCmd)
__declspec(selectany) _ARXCOMMAND_ENTRY __ArxCmdMap_##group##globCmd = { _\
RXST(#group), _RXST(#globCmd), _RXST(#locCmd), cmdFlags, classname::group ##globCmd, UIContext, 0 };\
extern "C" __declspec(allocate(ARXCOMMAND_FIRST_ENTRYNAME))\
__declspec(selectany) _ARXCOMMAND_ENTRY* __pArxCmdMap_##group##globCmd = &__ArxCmdMap_##group##globCmd;\
__pragma(comment(linker, "/include:__pArxCmdMap_" #group #globCmd));
ACED_ARXCOMMAND_ENTRY_AUTO(CArxProject1App, MyGroup, MyCommand, helloline, ACRX_CMD_MODAL, NULL)
{
// 初始化全局变量 __ArxCmdMap_MyGroupMyCommand
__declspec(selectany) _ARXCOMMAND_ENTRY __ArxCmdMap_MyGroupMyCommand = { _RXST(#group), _RXST(#globCmd), _RXST(#locCmd), cmdFlags, classname::group ##globCmd, UIContext, 0 };
// 指定C编译器 声明"ARXCOMMAND$__m"数据段
extern "C" __declspec(allocate("ARXCOMMAND$__m"))
// 初始化全局变量指针 __pArxCmdMap_MyGroupMyCommand
__declspec(selectany) _ARXCOMMAND_ENTRY* __pArxCmdMap_MyGroupMyCommand = &__ArxCmdMap_MyGroupMyCommand;
// 指示编译器完成将一个链接选项放入目标文件,include选项来强制包含某个对象
__pragma(comment(linker, "/include:__pArxCmdMap_" MyGroup MyCommand));
}
到了这里,关于objectARX ACED_ARXCOMMAND_ENTRY_AUTO的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!