麻烦看一下一个很简单的objectarx2007开发的代码
现在不知道objectarx2007的程序框架如何。自己照着2000objectarx的书上的例子写了一个,编译连接都通过了,也可以加载,但输入命令总是说找不到相关命令。工程名为Arx1。我生成工程之后就改了两个文件,如下,红色的代码是我加入的
一个是acrxEntryPoint.cpp
#include "StdAfx.h"
#include "resource.h"
//-----------------------------------------------------------------------------
#define szRDS _RXST("fff")
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
void initApp();
void unloadApp();
class CArx1App : public AcRxArxApp {
public:
CArx1App () : 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) ;
acrxDynamicLinker->unlockApplication(pkt); initApp();
// TODO: Add your initialization code here
return (retCode) ;
}
virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
// TODO: Add your code here
unloadApp();
// You *must* call On_kUnloadAppMsg here
AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;
// TODO: Unload dependencies here
return (retCode) ;
}
virtual void RegisterServerComponents () {
}
} ;
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CArx1App)
还有一个是Arx1.cpp
#include "StdAfx.h"
#include "resource.h"
//-----------------------------------------------------------------------------
//- DLL Entry Point
extern "C"
BOOL WINAPI DllMain (HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) {
//- Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved) ;
if ( dwReason == DLL_PROCESS_ATTACH ) {
_hdllInstance =hInstance ;
} else if ( dwReason == DLL_PROCESS_DETACH ) {
}
return (TRUE) ;
}
void firstARX();
void initApp()
{
acedRegCmds->addCommand((const ACHAR*)"ArxProject1_Commands",
(const ACHAR*)"showname",
(const ACHAR*)"thefirst",
ACRX_CMD_TRANSPARENT|ACRX_CMD_USEPICKSET,
firstARX);//注册命令
}
void unloadApp()
{
acedRegCmds->removeGroup((const ACHAR*)"ArxProject1_Commands"); //卸载命令
}
void firstARX()
{
ads_alert((const ACHAR*)"this is my first .net arx");
}
不能(const ACHAR*)这么强制转换,转换的结果使你的命令字符出错了,我也遇到类似问题,
用什么函数转换正在查找当中,有哪位大仙知道,不妨出来赐教,再下这厢有礼了!
这里面说得很详细
复制代码经过进一步实战验证,虽然按上面步骤能编译过去,但是还是有些问题。
这个问题就是(ACHAR*)的强制转化,直接用强制转化会有bug出现的,大概规律是这样,字符串长度为奇数时ok,如果为偶数,转化后的字符串前面也为正确的字符串,但是后面将带一大堆乱码。原因分析为,就是wchar_t型是占两字节的类型,如果字符串为偶数则字符串结束符将被占用。
修改办法:
1、利用char和wchar_t型的类型转化函数进行转化。
2、手工截断字符串。(没有试过^_^)
我按照他说的做了还是不行啊,你能够说得具体一点吗?我现在还不能够看精华帖子只能看回复,谢谢啊
void unloadApp()
{
acedRegCmds->removeGroup(L"ArxProject1_Commands"); //卸载命令
}
或
_T("ArxProject1_Commands") 可同时兼容CAD2002及CAD2007的工程
页:
[1]