几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » ObjectARX(C++)
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-04-16, 10:36 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】objectarx&dummies教程(三a)——minimum application

objectarx&dummies教程(三a)——minimum application
objectarx&dummies教程(三a)——minimum application
class 3a - minimum application
hello,
on this class we will implement the minimum objectarx application without use the arxwizard. to do that we will need to create the visual c++ project from scratch and perform some tuning on project settings.
to begin, open your microsoft visual c++ .net 2. open file menu, then choose new and new project. the following dialog will appear (note that this dialog can change a little bit depending on what add-on your have installed):
on this dialog, choose visual c++ projects tree node and, on the right portion select mfc dll template. after that, specify the name and location you would like to use for this project. click ok to continue.
after click ok the following dialog will be displayed. this dialog has two steps (in this case). the first step, called overview, just confirm what you have entered before.
clicking on the application settings step, the following page will appear inside this dialog:
now we will choose the mfc extension dll that is the most adequate dll type to build objectarx applications. note that the use of mfc is not an obligation. you can build objectarx applications without mfc but i strongly recommend you to always use mfc because if you don't need mfc now you probably will need it in a near future.
i would like to avoid more technical discussions on this subject because this is not our focus on this course. mfc is a huge and rich library that will avoid several lines of code and will make your application safe and easy to manage. click finish to continue.
after clicking finish visual c++ will create the mfc dll project files for you with basic implementation of some features. remember, this is just a minimum application and we will only make a few things to turn it ready to compile, build and load into autocad.
the visual c++ environment is very intuitive and i guess you will not face much trouble to learn how to use it. basically it has a project management area (default placed at left side), an editor area (placed at the right portion) and the command / monitor area which is placed below. the project management area uses a tab dialog bar to provide tools like solution explorer, resource view and class view among many others.
select the solution explorer tab and you will see your project files, organized using a tree. this explorer can handle multiple projects but only one can be the default which has its name in bold font.
now we will need to change some basic settings on our visual studio environment to allow us to compile and link objectarx application. as i said on previous classes, to build the application, which is a dll, we will need to compile using the provided objectarx headers (.h files) and to link with objectarx libraries (.lib files). the easiest way to do this is to change the global options of visual studio. this will affect all projects and you won't need to do this again for new projects.
open the tools menu and select options (the last entry). the following dialog will appear. select projects and then vc++ directories. on the show directories for field, select include files. below will appear a list of the include directories that visual studio already has and we will add our objectarx inc path which contains the desired .h files. click on the folder icon and click on the ellipsis button and search for the inc path (in my case, it is placed at c:\objectarx 4\inc).
don't click ok. now we need to add the library files directory. select library files on the show directories for field. repeat the above procedure to add a path but this time you will add the lib path (in my case, c:\objectarx 4\lib). click ok to finish.
now we need to configure our project. this will require some project settings change and some code typing. first, we will change the project settings. right click the project name inside solution explorer and select properties. the following dialog will appear. select, on the configuration field, all configurations. this will allow us to change both debug* and release* settings at the same time.
on the configuration properties node, select c/c++ and code generation. the right portion of this dialog will display a list with several properties. select the runtime library entry and chance its value to multi-threaded dll. this is a requirement to make our dll compatible with autocad environment.
now, select the linker node and general. on the output file entry change the extension name from dll to arx. note that visual studio use several macros (those names with a $ at beginning) to allow easy and flexible path configuration.
still inside linker node, select input. here we will add those libraries our application will use. this will depend on what features you are using inside your objectarx application. in this case, we will add just the basic two libraries called rxapi.lib and acdb16.lib.
select the additional dependencies entry and click on ellipsis button. type the two previously mentioned files. these libraries are located at lib folder. remember that on previous classes i have talked about the features each library has built in.
click ok to close project properties dialog. now we still need to do some code typing. the first step is to edit the def file which is placed at source files folder of your project at solution explorer. double click the def file and it will appear at the right portion of visual studio window. we will need to add the following lines, under the exports section of this file:
acrxentrypoint private
acrxgetapiversion private
pay attention to the name between quotes in front of library section inside this file. this name must be the same name you have entered on the output file. in other words, if your project generates a abcd.arx file you need to have library "abcd" inside the def file.
the next step is to change our stdafx.h file which is the key compilation file. we will need to inform visual studio to use release version of mfc libraries when our project is being compiled using the debug directive.
to do that, open the stdafx.h file which is located at header files folder inside solution explorer. before the #include line, insert the following code:
#if defined(_debug) && !defined(_fulldebug_)
#define _debug_was_defined
#undef _debug
#pragma
message (" compiling mfc header files in release mode.")
#endif
now, scroll to the end of this file and add the following lines to manage the _debug symbol back and to include basic .h files our application will need:
#ifdef _debug_was_defined
#define _debug
#undef _debug_was_defined
#endif
// objectarx includes
#include "rxregsvc.h"
#include "acutads.h"
the last step is to add our acrxentrypoint method which is our application start point. open the cpp file of your application which has the same name that you have set to your project plus the cpp extension. it is placed inside source files folder. open if and scroll down to the end. add the following lines:
// objectarx entrypoint
extern "c" acrx::appretcode acrxentrypoint(acrx::appmsgcode msg, void* appid){
switch(msg) {
case acrx::kinitappmsg:
acrxunlockapplication(appid);
acrxregisterappmdiaware(appid);
acutprintf("\nminimum objectarx application loaded!");
break;
case acrx::kunloadappmsg:
acutprintf("\nminimum objectarx application
unloaded!");
break;
}
return acrx::kretok;
}
now we are ready to build our application. open build menu and select build solution (or f7 key). visual studio will compile and link and build your project. if you have followed all above steps carefully it will generate the application without any error.
start autocad and run appload command which will show the following dialog. browse to your project and you will find the application inside the debug folder which is the default compilation type. select it and click load button. a message will appear at the bottom of this dialog telling you that your arx was successfully loaded or not!
that's it, your first objectarx application is loaded and is running inside autocad!
next class we will do the same using the arxwizard. stay tuned!
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】draw shaft using visual basic application yang686526 SolidWorks二次开发 0 2009-04-12 06:01 PM
【转帖】dll学习(资料收集) huangyhg vc编程 0 2008-05-17 09:24 PM
how to catch any error happened in SolidWorks application? huangyhg SolidWorks二次开发 1 2007-09-04 12:00 AM


所有的时间均为北京时间。 现在的时间是 05:50 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多