|
- // MyArxFirst.cpp : 定义 DLL 应用程序的导出函数。
- //ObjectArx开发对txt文本文件的操作一例
-
- #include "stdafx.h"
- #include <aced.h>
- #include <rxregsvc.h>
- #include <tchar.h>
-
- #include <fstream>
- #include <iostream>
- //
- #include <comdef.h>
-
-
- using namespace std;
-
- //定义两个函数
- void initApp();
- void unloadApp();
-
- //定义命令函数
- //------------------------------------------
- //打印"Hello world!"在AutoCAD Command上 的命令
- void hello();
-
- //打印文件内容 的命令
- void pfvalue();
-
- //ado连接数据库的方法 的命令
- void pdbvalue();
-
- //定义一般函数
- //------------------------------------------
- ACHAR* ConvertCharPtrToAcharPtr(const char* src);
- ACHAR* ConvertCharPtrToAcharPtr2(const char* src);
- //
- char* ConvertAcharPtrToCharPtr(const ACHAR* src);
- char* ConvertAcharPtrToCharPtr2(const ACHAR* src);
- //通用转换函数
- 采用bstr采用t Get采用bstr采用t(char* src);
- 采用bstr采用t Get采用bstr采用t采用W(wchar采用t* src);
- char* GetCharPtr(采用bstr采用t bstrt);
- wchar采用t* GetWchar采用t(采用bstr采用t bstrt);
-
- //打印函数
- void pfvalue采用default(const ACHAR* filepath);
-
- //打印文件内容2 函数
- void pfvalue2(const ACHAR* filepath);
-
- //ado连接数据库的方法 函数
- void pdbvalue(const ACHAR *filepath);
- //------------------------------------------
-
- extern "C"
- AcRx::AppRetCode
- acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
- //void acrxEntryPoint(void* pkt)
- {
- switch (msg)
- {
- case AcRx::kInitAppMsg:
- acrxDynamicLinker->unlockApplication(pkt);
- acrxRegisterAppMDIAware(pkt);
- initApp();
- break;
- case AcRx::kUnloadAppMsg:
- unloadApp();
- break;
- default:
- break;
- }
- return AcRx::kRetOK;
- }
-
-
-
- void initApp()
- {
- //register a command with the AutoCAD command mechanism
- //string macro 用法:
- //采用T("helloworld") or 采用采用T("helloworld") or ACRX采用T("helloworld")
- acedRegCmds->addCommand(ACRX采用T("HELLOWORLD采用COMMANDS"),
- ACRX采用T("ArxHsgBag"),
- ACRX采用T("Hello"),
- ACRX采用CMD采用TRANSPARENT,
- hello);
- acedRegCmds->addCommand(ACRX采用T("PFVALUE采用COMMANDS"),
- ACRX采用T("ArxHsgBag"),
- ACRX采用T("pfvalue"),
- ACRX采用CMD采用TRANSPARENT,
- pfvalue);
- acedRegCmds->addCommand(ACRX采用T("PDBVALUE采用COMMANDS"),
- ACRX采用T("ArxHsgBag"),
- ACRX采用T("pdbvalue"),
- ACRX采用CMD采用TRANSPARENT,
- pdbvalue);
- //
- }
-
-
- void unloadApp()
- {
- acedRegCmds->removeGroup(ACRX采用T("HELLOWORLD采用COMMANDS"));
- acedRegCmds->removeGroup(ACRX采用T("PFVALUE采用COMMANDS"));
- acedRegCmds->removeGroup(ACRX采用T("PDBVALUE采用COMMANDS"));
- }
-
-
- //----------------------------------------------------
- //hello命令
- void hello()
- {
- acutPrintf(ACRX采用T("\n第一个Arx程序Hello World!"));
-
- }
- //打印文件内容 命令
- void pfvalue()
- {
- acutPrintf(采用T("开始输出文件内信息:\n"));
- const ACHAR* filepath=ACRX采用T("d:\\test.txt"); //OK
- acutPrintf(filepath); //OK
- pfvalue采用default(filepath); //OK
- pfvalue2(filepath); //OK
- }
- //输出数据库表内记录的命令
- void pdbvalue()
- {
- acutPrintf(采用T("开始输出数据库表内记录:\n"));
- //...
- }
- //----------------------------------------------------
- ACHAR* ConvertCharPtrToAcharPtr(const char* src)
- {
- ACHAR* tmp;
- 采用bstr采用t AStr = src;
- LPWSTR AstrW = LPTSTR(AStr);
- tmp=(ACHAR *)AstrW;
- return tmp;
- }
- ACHAR* ConvertCharPtrToAcharPtr2(const char* src)
- {
- // Convert to a wchar采用t*
- size采用t srcsize = strlen(src) + 1;
- size采用t newsize = srcsize;
- size采用t convertedChars = 0;
- wchar采用t *wcstring;
- wcstring=new wchar采用t[newsize];
- mbstowcs采用s(&convertedChars, wcstring, srcsize, src, 采用TRUNCATE);
- //wcscat采用s(wcstring, L" (wchar采用t *)");
- //wcout << wcstring << endl;
- return wcstring;
- }
- char* ConvertAcharPtrToCharPtr(const ACHAR* src) //
- {
- char* tmp;
- 采用bstr采用t bstrt(src);
- tmp=GetCharPtr(bstrt);
- return tmp;
- }
- char* ConvertAcharPtrToCharPtr2(const ACHAR* src)
- {
- // Convert to a char*
- size采用t srcsize = wcslen(src) + 1;
- size采用t newsize = srcsize;
- size采用t convertedChars = 0;
- char *nstring;
- nstring=new char[newsize];
- wcstombs采用s(&convertedChars, nstring, srcsize, src, 采用TRUNCATE);
- return nstring;
- }
- //
- 采用bstr采用t Get采用bstr采用t(char* src)
- {
- 采用bstr采用t bstrt(src);
- return bstrt;
- }
- 采用bstr采用t Get采用bstr采用t采用W(wchar采用t* src)
- {
- // Convert to a 采用bstr采用t
- 采用bstr采用t bstrt(src);
- //bstrt += " (采用bstr采用t)";
- //cout << bstrt << endl;
- return bstrt;
- }
- char* GetCharPtr(采用bstr采用t bstrt)
- {
- // Convert to a char*
- size采用t newsize = bstrt.length()+1;
- char *nstring;nstring=new char[newsize];
- strcpy采用s(nstring,newsize,(char *)bstrt);
- //strcat采用s(nstring, " (char *)");
- //cout << nstring << endl;
- return nstring;
- }
- wchar采用t* GetWchar采用t(采用bstr采用t bstrt)
- {
- // Convert to a wchar采用t*
- int srcsize=bstrt.length()+1;
- wchar采用t *wcstring;wcstring=new wchar采用t[srcsize];
- wcscpy采用s(wcstring,srcsize,(wchar采用t *)bstrt);
- //wcscat采用s(wcstring, L" (wchar采用t *)");
- //wcout << wcstring << endl;
- return wcstring;
- }
- //CComBSTR GetCComBSTR(char* src)
- //{
- // // Convert to a CComBSTR
- // CComBSTR ccombstr(src);
- // /*if (ccombstr.Append(L" (CComBSTR)") == S采用OK)
- // {
- // CW2A printstr(ccombstr);
- // cout << printstr << endl;
- // }*/
- // return ccombstr;
- //}
- //----------------------------------------------------
- //打印文件内容1 C文件操作函数 OK
- void pfvalue采用default(const ACHAR* filepath)
- {
- acutPrintf(采用T("\n-----下面是c文件操作函数打开的内容-----\n"));
- acutPrintf(filepath);acutPrintf(采用T("\n"));
- FILE *fp;
- int linesize=4000;
- char *line;line=new char[linesize];
- const char* path=ConvertAcharPtrToCharPtr(filepath);
- ACHAR* wtmp=ConvertCharPtrToAcharPtr(path);
- acutPrintf(wtmp);acutPrintf(采用T("\n"));
- if((fp=fopen(path,"r"))==NULL)
- {
- acutPrintf(采用T("\nfile cannot be opened\n"));
- }
- else
- {
- const ACHAR* tmp;
- while(!feof(fp))
- {
- if(fgets(line,linesize,fp)!=NULL)
- {
- tmp=ConvertCharPtrToAcharPtr(line);
- acutPrintf(tmp);
- }
- }
- fclose(fp);
- }
- }
-
- //打印文件内容2 ifstream类 OK
- void pfvalue2(const ACHAR* filepath)
- {
- //--file2 open
- //filepath="d:\\test.txt";
- acutPrintf(ACRX采用T("\n"));
- acutPrintf(filepath);
- ifstream r(filepath,ifstream.in);
- if(!r)
- {
- acutPrintf(ACRX采用T("打开文件出错!"));
- }
- else
- {
- const ACHAR* tmpAchar;
- //char line[4000]; //[100]2000
- int linesize=4000;
- char* line;line=new char[linesize];
- while(r>>line)
- {
- tmpAchar=ConvertCharPtrToAcharPtr(line);
- acutPrintf(tmpAchar);
- acutPrintf(ACRX采用T("\n"));
- }
- r.close();
- acutPrintf(ACRX采用T("输出文件内容完毕!"));
- }
- }
-
-
- //ObjectARX offers the following input functions.
- //Refer to the ObjectARX Online Help for a complete description of
- //how to use these functions.
- //acedGetInt used to get an integer value
- //acedGetReal used to get a real value
- //acedGetString used to get a string
- //acedGetAngle used to get a angle value
- //acedGetKword used to get a key word
- //acedInitGet used to initialize acedGetXXXX functions
- //acedGetFileD used to retrieve file selection from a file dialog
- //acedGetPoint used to pick a point
- //acedGetDist used to get the distance between two points
- //acedGetCorner see Online Help for a complete description
- //
- //ObjectARX offers the following functions for selection of AutoCAD entities.
- //(Again refer to the ObjectARX Online Help for a complete description of
- //how to use these functions).
- //
- //acedEntSel used to select a single entity
- //acedNEntSel used to select a single, nested entity
- //acedNEntSelP used to select a single, nested entity
- //acutSSGet used to select multiple entities
-
- //--the---end---
复制代码 |
|