CAD/CAM discussion forum > CAD Tutorial & Tips > Use your AutoCAD ARX application in ZWCAD+, convert ARX to ZRX

Use your AutoCAD ARX application in ZWCAD+, convert ARX to ZRX

Rank: 8Rank: 8

Jenny

Super Moderator

posts: 502

Registered: 2013-5-6

Message 1 of 1

 Use your AutoCAD ARX application in ZWCAD+, convert ARX to ZRX
24-07-2013 12:14 . pm | View his/her posts only
ZWCAD+ has an API just like AutoCAD ARX call ZRX. This tutorial show you how to migrate AutoCAD ARX application to ZRX, how to convert ARX to ZRX.
It only take 7 steps to migrate AutoCAD ARX application to ZWCAD+, pretty simple and easy. The APIs is improved a lot in ZWCAD+. ZRX is much stronger and it is easier to migrate ARX to ZRX.

If you are a developer and want to convert your ARX application to ZRX, you need the ZRX SDK package, pls contact ZDN@zwcad.com to apply the SDK package and a developer license.

Here is a video to show how to migrate ARX to ZRX in 7 steps:




-----------------------ZRX Migration Manual--------------------------
This document will guide you to migrate an ARX application to ZRX of ZWCAD+. If you have any problems can’t be solved in this document, please feel free to contact us for help by email to zdn@zwcad.com.

 System Requirement
1. Developing environment: Visual Studio 2010
2. ZWCAD Version: ZWCAD+
3. SDK: ZRXSDK
4. ARX objects Based on ObjectARX2006 or ObjectARX2008 are recommended

NOTE: ZRX is compatible with ObjectARX2008, so some features, like constraint, provided in higher versions of ObjectARX would not be supported in current ZRX. Meanwhile, the current ZRX doesn’t Unicode. For migration, we recommend to use ARX objects for ObjectARX 2006 or ObjectARX 2008, and if you want to use projects for ObjectARX 2010, please make sure that your ARX2010 object can be compatible with ObjectARX 2008, otherwise, maybe some unknown problems will happen.


 Migration steps
Step 1: Update your ARX projects to VS2010 (Visual Studio 2010)
Open you ARX Projects in VS2010 and VS2010 will wizard you to update them to VS2010.

Step 2: Change the header files and library paths to ZRX
a) Change header files path to ZRX. In project property dialog: [C/C++ -> General -> Additional Include Directories], remove the path refer to ObjectARX and add the path of ZRXSDK\arxport. For example, the path is "D:\ZRXSDK\ arxport". It is shown as the figure below.
AutoCAD_ARX_to_ZWCAD_ZRX_01.jpg
2013-7-24 12:02

b) Change the library path to ZRX. In project property dialog: [Linker -> General -> Additional Library Directories], Remove old paths refer to ObjectARX and add the path of ZRXSDK\lib, for example, “D: \ZRXSDK\lib”. It is shown as the figure below

AutoCAD_ARX_to_ZWCAD_ZRX_02.jpg
2013-7-24 12:02


c) Modify the file extension of output file from .arx to .zrx in [Linker -> General -> Output File] as below:

AutoCAD_ARX_to_ZWCAD_ZRX_03.jpg
2013-7-24 12:02


d) [Linker -> Input -> Additional Dependencies]: Remove old files from ARXSDK and add follow dependency libraries: ZwRx.lib; ZwDatabase.lib; ZwGeometry.lib; ZWCAD.lib; ZdUI.lib; ZwUI.lib;
AutoCAD_ARX_to_ZWCAD_ZRX_04.jpg
2013-7-24 12:02


Step 3: Change other settings
a) Character setting: If you use Unicode in your project, please change to “Multi-Byte Character Set” as below [General -> Character Set]:
AutoCAD_ARX_to_ZWCAD_ZRX_05.jpg
2013-7-24 12:03


b) Language Setting: Change [C/C++ -> Language -> Treat wchart_t as Built-in Type] to “No (/Zc:wchar_t-)” and change [C/C++ -> Language -> Force Conformance in For Loop Scope] to “No (/Zc:wchar_t-)” as below:

AutoCAD_ARX_to_ZWCAD_ZRX_06.jpg
2013-7-24 12:03


Step 4: Modify the .def file
Open the .def file included in you project (if there is not this file in your project, this step can be skipped, but please make sure that acrxEntryPoint was exported and you needed to change it to zcrxEntryPoint) and modify its content as below:

a) Add .zrx extension after the name of your LIBRARY file Note: If your DEF just contains EXPORTS, you can skip this step and continue to step b.b) Change “acrxEntryPoint” and “acrxGetApiVersion” to “zcrxEntryPoint” and “zcrxGetApiVersion”

For example:
If your DEF is like this:
LIBRARY "hwWHKC"
EXPORTS

acrxEntryPoint
PRIVATE


acrxGetApiVersion
PRIVATE

Please modify it as:
LIBRARY "hwWHKC.zrx"
EXPORTS

zcrxEntryPoint
PRIVATE


zcrxGetApiVersion
PRIVATE

If your DEF is like this:
EXPORTS

acrxEntryPoint
PRIVATE


acrxGetApiVersion
PRIVATE

Please modify it as:
EXPORTS

zcrxEntryPoint
PRIVATE


z
crxGetApiVersion
PRIVATE


Step 5: Modify acrxEntryPoint to zcrxEntryPoint in your .CPP file.
Note: Please Make sure that your zcrxEntryPoint is declared as Extern “C” type, for example: extern "C" AcRx::AppRetCode zcrxEntryPoint(AcRx::AppMsgCode msg, void* pkt).


Meanwhile, you can’t declare your zcrxEntryPoint as static type.
Otherwise, you ZRX commands will not be recognized.

Step 6: About COM interface.
If you need to use COM interface, please refer to following steps:

a) Added your ZWCAD+ installation path, for example, to [C/C++ -> General -> Additional Include Directories].

b) Use #import “ZwAuto.dll” in your code.

Step 7: Modify support file name.
If there are some customized support files in your application, you should change their name accordingly. For example:
ACAD.MNU -> ZWCAD.MNU
ACAD.DLL -> ZWCAD.DLL
ACAD.lin -> ZWCAD.lin
ACAD.PGP -> ZWCAD.PGP

Note: Currently ZWCAD+ doesn’t support CUI/CUIX files.


Trouble shooting
 Updating from VS2003(VC7) to VS2010(VC10)
a) In VC10, variables defined inside “for” expression would exist in the same expression.
Vc7: for(int i<0;i<100;++i){…}; j = i; (ok)
Vc10: for(int i<0;i<100;++i){…}; j = i; (illegal)
int i; for(i<0;i<100;++i){…}; j = i; (ok)

b) error C4430: missing type specifier
Take the following codes for example
ArxDbgLongTransactionReactor(const& ArxDbgLongTransactionReactor);
ArxDbgLongTransactionReactor& operator=(const& ArxDbgLongTransactionReactor);


It’s ok in VC7, but in VC10 there will be an error: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
You should modify these codes to
ArxDbgLongTransactionReactor(const ArxDbgLongTransactionReactor &other);
ArxDbgLongTransactionReactor& operator=(const ArxDbgLongTransactionReactor & other);


c) Find following codes in StdAfx.h:
#ifndef _WIN32_WINNT //----- Allow use of features specific to Windows NT 4 or later.
#define _WIN32_WINNT 0x0400 //----- Change this to the appropriate value to target Windows 2000 or later.
#endif

Modify the value of _WIN32_WINNT from 0x0400 to 0x0600
#ifndef _WIN32_WINNT //----- Allow use of features specific to Windows NT 4 or later.
#define _WIN32_WINNT 0x0600 //----- Change this to the appropriate value to target Windows 2000 or later.
#endif


d) Find following codes in StdAfx.h:
#ifndef WINVER //----- Allow use of features specific to Windows 95 and Windows NT 4 or later.
#define WINVER 0x0400 //----- Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
#ifndef _WIN32_IE //----- Allow use of features specific to IE 4.0 or later.
#define _WIN32_IE 0x0400 //----- Change this to the appropriate value to target IE 5.0 or later.

#endif
Modify the value of WINVER and _WIN32_IE from 0x0400 to 0x0600
#ifndef WINVER //----- Allow use of features specific to Windows 95 and Windows NT 4 or later.
#define WINVER
0x0600 //----- Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
#ifndef _WIN32_IE //----- Allow use of features specific to IE 4.0 or later.
#define _WIN32_IE
0x0600 //----- Change this to the appropriate value to target IE 5.0 or later.
#endif


e) error C2440: 'static_cast'
The reason is declarations of some MFC functions are modified in VC10. Please modify your code accordingly. For example,

afx_msg UINT OnNcHitTest(CPoint point);
UINT CMyDlg::OnNcHitTest(CPoint point)
{

UINT nh=CDialog::OnNcHitTest(point);

return ((nh==HTCLIENT)?HTCAPTION:nh);
}
Should be modified to
#if _MSC_VER >= 1400
afx_msg
LRESULT OnNcHitTest(CPoint point);
#else
afx_msg UINT OnNcHitTest(CPoint point);
#endif

#if _MSC_VER >= 1400
LRESULT CMyDlg::OnNcHitTest(CPoint point)
{

LRESULT nh=CDialog::OnNcHitTest(point);

return ((nh==HTCLIENT)?HTCAPTION:nh);
}
#else
UINT CMyDlg::OnNcHitTest(CPoint point)
{

UINT nh=CDialog::OnNcHitTest(point);

return ((nh==HTCLIENT)?HTCAPTION:nh);
}
#endif



f) Using CString improperly may lead to a crash.
For example:
char* strPromt[2] = {strSel.GetBuffer(-1), strRemove.GetBuffer(-1)};
should be modified to:
char* strPromt[2] = {strSel.GetBuffer(strSel.GetLength()+1),
strRemove.GetBuffer(strRemove.GetLength()+1)};


g) In order to use RichEdit control, you need to call AfxInitRichEdit();. Please refer to MSDN for more information.

h) If there is a #include inside your code, you will have this error:
error LNK2001: unresolved external symbol “__declspec(dllexport) public:__thiscall std::basic_string, calss std::allocator >……
The solution is to add “msvcprt.lib” to your project setting [Linker -> Input -> Additional Dependencies].

i) Ostrstream cannot be compiled in DEBUG version. You could make it compatible by doing this:
#ifdef DEBUG
#undef DEBUG
{
ostrstream msg;



}
#endif


j) If following compile error occurs:

Please add #include “comdef.h” to file stdafx.h.

k) If error LNK 2038 occurs:

AutoCAD_ARX_to_ZWCAD_ZRX_07.jpg
2013-7-24 12:03


Change [C/C++ -> Code Generation -> Runtime Library] to /MD.

AutoCAD_ARX_to_ZWCAD_ZRX_08.jpg
2013-7-24 12:03


l) If warning LNK 4098 occurs:

AutoCAD_ARX_to_ZWCAD_ZRX_09.jpg
2013-7-24 12:03


It means you are linking to the debug version of MFC. You can remove the “_DEBUG” symbol or change it to “NDEBUG” in [C/C++ -> Preprocessor -> Preprocessor Definitions] to avoid this warning.

m) If error C1189 occurs, it means you have defined _UNICODE. You can remove the definition to avoid this error.

 Updating from ARX2006 to ARX 2008


a) ARX2008 adds some virtual functions.
For example, AcDbDwgFiler adds
virtual Acad::ErrorStatus readInt8(Adesk::Int8 *) = 0;
virtual Acad::ErrorStatus writeInt8(Adesk::Int8 ) = 0;
virtual Acad::ErrorStatus readString(AcString &) = 0;
virtual Acad::ErrorStatus writeString(const AcString &) = 0;
If there are some classes in your codes derived from abstract class like AcDbDwgFiler, you need to implement those newly added virtual functions.

b) ARX2008 removes some functions.
For example, AcDbDatabase::osmode(). You need to modify your codes accordingly.

c) ARX2008 changes parameters of some functions.
ARX2006ARX2008
virtual Adesk::Boolean ZcGiGeometry::shell
(
const Adesk::UInt32 nbVertex,
const AcGePoint3d* pVertexList,
const Adesk::UInt32 faceListSize,
const Adesk::Int32* pFaceList,
const AcGiEdgeData* pEdgeData = NULL,
const AcGiFaceData* pFaceData = NULL,
const AcGiVertexData* pVertexData = NULL,
const struct resbuf* pResBuf = NULL
) const = 0;
virtual Adesk::Boolean ZcGiGeometry::shell
(
const Adesk::UInt32 nbVertex,
const AcGePoint3d* pVertexList,
const Adesk::UInt32 faceListSize,
const Adesk::Int32* pFaceList,
const AcGiEdgeData* pEdgeData = NULL,
const AcGiFaceData* pFaceData = NULL,
const AcGiVertexData* pVertexData = NULL,
const struct resbuf* pResBuf = NULL,
const bool bAutoGenerateNormals = true
) const = 0;
AcDbDictionaryIterator * AcDbDictionary::newIterator
( enum AcRx::DictIterType )
AcDbDictionaryIterator AcDbDictionary::newIterator
( )
virtual enum Acad::ErrorStatus AcDbEntity::setLayer
(
class AcDbObjectId newVal;
Adesk::Boolean doSubents = true
)
virtual enum Acad::ErrorStatus AcDbEntity::setLayer
(
AcDbObjectId newVal,
Adesk::Boolean doSubents = true,
bool allowHiddenLayer = false);
virtual void AcGiSubEntityTraits:: setSelectionMarker
(const Adesk::Int32 markerId) = 0
virtual void AcGiSubEntityTraits:: setSelectionMarker (const Adesk::LongPtr markerId) = 0;
MoreMore

If you some functions are changed but not included in above list, please refer to .h files in ZRXSDK/inc.

 Tips
a) When fail loading a compiled ZRX file, there are some possible reasons:

1) When a .zrx file is the first time loaded with a developer version ZWCAD+, ZWCAD+ will write some information into it. So if ZWCAD+ do not have a full authority to write this file, the loading will fail.
2) Some third-party DLL files are missing.
3) The version of ZWCAD+ and ZRXSDK don’t match with each other.
4) Something wrong with the compiled ZRX file. It can be fixed by cleaning and then rebuilding.
AutoCAD_ARX_to_ZWCAD_ZRX_10.jpg
2013-7-24 12:03

5) .def file is not modified. Please refer to Step 4.


b) Any class derived from AcRxService must call registering function “XXXX::rxInit()” in the entry.

c) Mind the differences cause by file name changed. For example:
static const TCHAR* strArxName = _T("MySymbol.arx");
should be modified to
static const TCHAR* strArxName = _T("MySymbol.zrx");

d) If the ZRX file is successfully loaded, but all the commands defined in the file cannot be recognized, it may be:

1) There is no zcrxEntryPoint in .def file.
2) acrxEntryPoint is not yet modified to zcrxEntryPoint.


e) Since ZWCAD+ only provides the release version of ZRX.dll and relative library and dynamically links to MFC, if your application is compiled with DEBUG version, please make sure that it links to the release version of MFC. For your convenience, you could add following codes to StdAfx.h:
# ifdef _DEBUG
#undef _DEBUG
#endif


f) If your dialog doesn’t show:
BOOL CMyDialog::PreCreateWindow (CREATESTRUCT& cs)
{

if ( !CWnd::PreCreateWindow( cs ) )
{
return FALSE;
}
/***Add following codes to fix the problem***/

if (_MSC_VER == 1600)
{
if ((cs.hMenu != NULL) && (cs.style & WS_CHILD))
{
cs.hMenu = 0;
}
}


return TRUE;
}


g) The path in registry is different. The registry items of ZWCAD+ are mainly stored in HKEY_CURRENT_USER\Software\ZWSoft\ZWCAD, according to version and language. For example,
HKEY_CURRENT_USER\Software\ZWSoft\ZWCAD\2012\ENU\Profiles .
What’s more, the location of profile settings is a little different from AutoCAD.

AutoCAD:
HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R16.2\ACAD-4001:409\Profiles\\General

ZWCAD:
HKEY_CURRENT_USER\Software\ZWSoft\ZWCAD\2012\en-US\Profiles\\Config
means the name of current profile. Default is “default”.

For example,
Support file path of ZWCAD+:
HKEY_CURRENT_USER\Software\ZWSoft\ZWCAD\2012\en-US\Profiles\Default\Config
ZWCAD

Menus of ZWCAD+:
HKEY_CURRENT_USER\Software\ZWSoft\ZWCAD\2012\en-US\Profiles\Default\Menus

h) When compiling, “error C2664: 'zcutPrintf' : cannot convert parameter 1 from 'const unsigned short [19]' to 'const ZTCHAR *” occurs.
That’s because you should express a constant string in this way
_T(“string”)
rather than
L”string”
For your convenience, here is a way to use Visual Studio’s Quick Replace feature
AutoCAD_ARX_to_ZWCAD_ZRX_11.jpg
2013-7-24 12:03
tomodify your codes easily:
AutoCAD_ARX_to_ZWCAD_ZRX_12.jpg
2013-7-24 12:03


i) Appload command can load lsp/zpvb/zrx files.
Lisp function zrxload/arxload can load zrx files.
Menuload command can load mnu/mns files.
If you want to load files automatically, please write full names of your files to zwcad.lsp or zwcad.rx, which exist in the installation directory of ZWCAD+.
NOTE Please make sure the extension of any file in zwcad.lsp and zwcad.rx is modified from “.arx” to “.zrx”.
j) Currently ZWCAD+ doesn’t support CUI, .NET and some 3D functions.

k) About short cut macro.
You can use some parameter to customize the activity of ZWCAD+:

1) /p
The parameter “/p” specify which profile ZWCAD+ will start with. For example,
"C:\Program Files\ ZWCAD+ 2012\zwcad.exe" /p MyProfile

2) /s
The parameter “/s” specify the support file searching path. Path are separated by “;”. For example,
"C:\Program Files\ ZWCAD+ 2012\zwcad.exe" /s "D:\work";"D:\work1"

3) /t
The parameter “/t” specify which template would be the default template when creating a new drawing. For example,
"C:\Program Files\ ZWCAD+ 2012\zwcad.exe" /t "D:\work\MyTemplate.dwt"


l) How to locate ZWCAD+ installation directory?
You can find ZWCAD+ installation directory in register [HKEY_LOCAL_MACHINE\SOFTWARE\ZWSoft\ZWCAD\2012\< language version>], key “Location”. For example, if you are using English version, should be “en-US”. Below are the names of each version:
en-US - English
zh-CN - Simplified Chinese
zh-TW – Traditional Chinese
cs-CZ - Czech
de-DE - German
es-ES - Spanish
fr-FR - French
hu-HU - Hungarian
it-IT - Italian
ja-JP - Japanese
ko-KR - Korean
pl-PL - Polish
pt-BR - Portuguese
ru-RU - Russian
tr-TR - Turkish





Try ZWCAD+ free for 30 days:
http://www.zwsoft.com/zwcad/ZWCAD_Overview
See also