mengde 发表于 2007-1-17 20:07:00

麻烦看一下一个很简单的objectarx2007开发的代码

<p>现在不知道objectarx2007的程序框架如何。自己照着2000objectarx的书上的例子写了一个,编译连接都通过了,也可以加载,但输入命令总是说找不到相关命令。</p><p>工程名为Arx1。我生成工程之后就改了两个文件,如下,红色的代码是我加入的</p><p>一个是acrxEntryPoint.cpp</p><p>#include "StdAfx.h"<br/>#include "resource.h"</p><p>//-----------------------------------------------------------------------------<br/>#define szRDS _RXST("fff")</p><p>//-----------------------------------------------------------------------------<br/>//----- ObjectARX EntryPoint<br/><font color="#ff0000">void initApp();<br/>void unloadApp();</font></p><p>class CArx1App : public AcRxArxApp {</p><p>public:<br/>&nbsp;CArx1App () : AcRxArxApp () {}</p><p>&nbsp;virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {<br/>&nbsp;&nbsp;// TODO: Load dependencies here</p><p>&nbsp;&nbsp;// You *must* call On_kInitAppMsg here<br/>&nbsp;&nbsp;AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff0000"> acrxDynamicLinker-&gt;unlockApplication(pkt);&nbsp;&nbsp;&nbsp;initApp();<br/></font>&nbsp;&nbsp;<br/>&nbsp;&nbsp;// TODO: Add your initialization code here</p><p>&nbsp;&nbsp;return (retCode) ;<br/>&nbsp;}</p><p>&nbsp;virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {<br/>&nbsp;&nbsp;// TODO: Add your code here<br/>&nbsp;&nbsp; <font color="#ff0000">unloadApp();<br/></font>&nbsp;&nbsp;// You *must* call On_kUnloadAppMsg here<br/>&nbsp;&nbsp;AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;</p><p><br/>&nbsp;&nbsp;// TODO: Unload dependencies here<br/>&nbsp;<br/>&nbsp;&nbsp;return (retCode) ;<br/>&nbsp;}</p><p>&nbsp;virtual void RegisterServerComponents () {<br/>&nbsp;}</p><p>} ;</p><p>//-----------------------------------------------------------------------------<br/>IMPLEMENT_ARX_ENTRYPOINT(CArx1App)<br/></p><p>还有一个是Arx1.cpp</p><p>#include "StdAfx.h"<br/>#include "resource.h"</p><p>//-----------------------------------------------------------------------------<br/>//- DLL Entry Point<br/>extern "C"<br/>BOOL WINAPI DllMain (HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) {<br/>&nbsp;//- Remove this if you use lpReserved<br/>&nbsp;UNREFERENCED_PARAMETER(lpReserved) ;</p><p>&nbsp;if ( dwReason == DLL_PROCESS_ATTACH ) {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _hdllInstance =hInstance ;<br/>&nbsp;} else if ( dwReason == DLL_PROCESS_DETACH ) {<br/>&nbsp;}<br/>&nbsp;return (TRUE) ;<br/>}</p><p><font color="#ff0000">void firstARX();<br/>void initApp()<br/>{<br/>&nbsp;acedRegCmds-&gt;addCommand((const ACHAR*)"ArxProject1_Commands",<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (const ACHAR*)"showname",<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(const ACHAR*)"thefirst",<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ACRX_CMD_TRANSPARENT|ACRX_CMD_USEPICKSET,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;firstARX);//注册命令&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>}</font></p><p><font color="#ff0000">void unloadApp()<br/>{<br/>&nbsp;acedRegCmds-&gt;removeGroup((const ACHAR*)"ArxProject1_Commands"); //卸载命令<br/>}</font></p><p><font color="#ff0000">void firstARX()<br/>{<br/>&nbsp;ads_alert((const ACHAR*)"this is my first .net arx");<br/>}</font></p>

tongtongfan 发表于 2007-1-19 08:38:00

<p>不能<font color="#ff0000">(const ACHAR*)</font><font color="#000000">这么强制转换,转换的结果使你的命令字符出错了,我也遇到类似问题,</font></p><p>用什么函数转换正在查找当中,有哪位大仙知道,不妨出来赐教,再下这厢有礼了!</p>

zhang007 发表于 2007-1-19 10:52:00

<p><a href="http://bbs.mjtd.com/forum.php?mod=viewthread&tid=55055">http://bbs.mjtd.com/forum.php?mod=viewthread&tid=55055</a></p><p>这里面说得很详细</p>

mengde 发表于 2007-1-19 12:00:00

本帖最后由 作者 于 2007-1-19 12:02:52 编辑

http://bbs.mjtd.com/forum.php?mod=viewthread&tid=55055
这里面说得很详细
经过进一步实战验证,虽然按上面步骤能编译过去,但是还是有些问题。
这个问题就是(ACHAR*)的强制转化,直接用强制转化会有bug出现的,大概规律是这样,字符串长度为奇数时ok,如果为偶数,转化后的字符串前面也为正确的字符串,但是后面将带一大堆乱码。原因分析为,就是wchar_t型是占两字节的类型,如果字符串为偶数则字符串结束符将被占用。
修改办法:
1、利用char和wchar_t型的类型转化函数进行转化。
2、手工截断字符串。(没有试过^_^)
我按照他说的做了还是不行啊,你能够说得具体一点吗?我现在还不能够看精华帖子只能看回复,谢谢啊

fpiw 发表于 2007-1-19 13:53:00

<p><font color="#ff0000">void unloadApp()<br/>{<br/>&nbsp;acedRegCmds-&gt;removeGroup(L"ArxProject1_Commands"); //卸载命令<br/>}</font></p><p><font color="#ff0000">或</font></p><p><font color="#ff0000">_T("ArxProject1_Commands") 可同时兼容CAD2002及CAD2007的工程</font></p>
页: [1]
查看完整版本: 麻烦看一下一个很简单的objectarx2007开发的代码