- 积分
- 12459
- 明经币
- 个
- 注册时间
- 2003-5-28
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2005-3-15 23:44:00
|
显示全部楼层
reply
acrxEntryPoint这个入口函数定义了没有,参见arx帮助:
#include "stdafx.h" #include <aced.h> #include <rxregsvc.h> |
Next, we declare two functions:
- initApp() - which will be called by AutoCAD when our application is loaded and
- unloadApp() - which is called when our application is unloaded.
Please refer to the acrxEntryPoint() function below to see how these functions are being called by AutoCAD. Add the lines:
void initApp(); void unloadApp(); |
Next, we declare our own function to print "Hello world!" on the AutoCAD command line. Add:
Now we will define the initApp() function. This function registers a new command with the AutoCAD command mechanism. This new command will become an additional entry point into our application:
void initApp() {
// register a command with the AutoCAD command mechanism acedRegCmds->addCommand("HELLOWORLD_COMMANDS", "Hello", "Bonjour", ACRX_CMD_TRANSPARENT, helloWorld);
}
|
For details regarding the acedRegCmds macro and the addCommand() method (of AcEdCommandStack class), please refer to the ObjectARX online help file. The first argument of addCommand() is the command group name (it includes only one command in our case). The second argument is the global/un-translated command name. The third argument is the local/translated name for the same command. The fourth argument is the command flag (note that here we define a transparent command, which means that the command can be invoked while another command is active). Finally, the last argument is the pointer to the function being called by our command. In C++ this is the function name itself.
Next we define the unloadApp() function. This function will remove our command group, which will also remove our command. Since commands registered with AutoCAD become additional entry points into our application, it is absolutely necessary to remove them when the application is unloaded. Add:
void unloadApp() {
acedRegCmds->removeGroup("HELLOWORLD_COMMANDS");
}
|
Next we define our helloWorld() function; acutPrintf() is the equivalent of the C printf function redirected to the AutoCAD command line. Add:
void helloWorld() {
acutPrintf("\nHello World!");
}
|
Pretty basic indeed!
Now we need to define the most important function for ObjectARX applications. All ObjectARX applications have one main entry point that is used for messaging: the acrxEntryPoint() function. Remember that an ObjectARX application is a DLL and thus does not have a main() entry point. AutoCAD calls the ObjectARX module acrxEntryPoint() function to pass messages to the application.
The first parameter of acrxEntryPoint() is a data member of the AcRx class called msg which represents the message sent from the ObjectARX kernel to the application. Refer to the online help for details about the different messages an ObjectARX application can receive from AutoCAD.
In our very simple example, we need to be notified when the application is loaded and unloaded in order to register and un-register our "hello" command. In the first case we will call our initApp() function; in the second case we will call our unloadApp() function.
The second parameter of acrxEntryPoint() is an opaque handle to data passed to different functions, such as the lock and unlock functions (this data changes depending on the message passed by AutoCAD).
By default applications are locked, which means that once loaded they cannot be unloaded. Since our application is very simple (it does not define objects that AutoCAD and other applications refer to, except our command), we can safely unlock our application to make it unloadable, provided that we remove our command first, which is achieved in our unloadApp() function.
Also by default, ObjectARX applications are not MDI aware (again, please refer to the online help for detailed information on the MDI issues). Applications need to register themselves explicitly as being MDI aware using the acrxRegisterAppMDIAware() global function.
NOTE: Registering an application as being MDI aware is not in itself enough for the application to be effectively MDI aware. The criteria that need to be met are described in details in the ObjectARX online documentation.
Since our application is very simple (it does not use the concept of Document and does not interact with the AutoCAD drawing database), we can safely register it as being MDI aware using the acrxRegisterAppMDIAware() global function. Add: acrxEntryPoint入口函数:
extern "C" AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt) {
switch (msg) {
case AcRx::kInitAppMsg: acrxDynamicLinker->unlockApplication(pkt); acrxRegisterAppMDIAware(pkt); initApp(); break; case AcRx::kUnloadAppMsg: unloadApp(); break; default: break;
}
return AcRx::kRetOK;
}
|
DEF定义:
- acrxEntryPoint
- acrxGetApiVersion.
LIBRARY Step01 EXPORTS acrxEntryPoint PRIVATE acrxGetApiVersion PRIVATE |
|
|