ObjectARX中Convert转换类定义
// stdafx.h : 标准系统包含文件的包含文件,// 或是经常使用但不常更改的
// 特定于项目的包含文件
//
#pragma once
#pragma warning(disable: 4146)
#include "targetver.h"
#define WIN32采用LEAN采用AND采用MEAN // 从 Windows 头中排除极少使用的资料
// Windows 头文件:
#include <windows.h>
// TODO: 在此处引用程序需要的其他头文件
#include <fstream>
#include <iostream>
//#include <AcFStream.h>
using namespace std;
//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---
//引用CAD头文件
#include <aced.h>
#include <rxregsvc.h>
#include <tchar.h>
//ADO库的引用
//导入ADO动态链接库,必须的
#include <comdef.h>
//#import "c:\program files\common files\system\ado\msado15.dll" no采用namespace rename("EOF","adoEOF")
//#import "c:\Program files\common files\system\ado\msado15.dll" rename采用namespace("ARXADO") rename("EOF","adoEOF") rename("EOS","adoEOS")
#import "c:\program files\common files\system\ado\msado15.dll" no采用namespace rename("EOF","adoEOF")\
rename("LockTypeEnum","adoLockTypeEnum")\
rename("DataTypeEnum","adoDataTypeEnum")\
rename("FieldAttributeEnum","adoFieldAttributeEnum")\
rename("EditModeEnum","adoEditModeEnum")\
rename("RecordStatusEnum","adoRecordStatusEnum")\
rename("ParameterDirectionEnum","adoParameterDirectionEnum")\
rename("EOS","adoEOS")
//#include "Convert.h"
#pragma once
#include "stdafx.h"
#ifndef 采用Convert采用H采用
#define 采用Convert采用H采用
//定义转换类
class Convert
{
public:
//定义一般函数
//------------------------------------------
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);
ACHAR* GetAcharPtr(采用bstr采用t bstrt);
//CComBSTR GetCComBSTR(char* src);
};
#endif //Convert.cpp实现Convert.h头文件定义的类成员
#pragma once
#include "stdafx.h"
#include "Convert.h"
//----------------------------------------------------
//实现类成员函数
//----------------------------------------------------
ACHAR* Convert::ConvertCharPtrToAcharPtr(const char* src)
{
ACHAR* tmp;
采用bstr采用t AStr = src;
LPWSTR AstrW = LPTSTR(AStr);
tmp=(ACHAR *)AstrW;
return tmp;
}
ACHAR* Convert::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;
mbstowcs采用s(&convertedChars, wcstring, srcsize, src, 采用TRUNCATE);
//wcscat采用s(wcstring, L" (wchar采用t *)");
//wcout << wcstring << endl;
return wcstring;
}
char* Convert::ConvertAcharPtrToCharPtr(const ACHAR* src)//
{
char* tmp;
采用bstr采用t bstrt(src);
tmp=GetCharPtr(bstrt);
return tmp;
}
char* Convert::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;
wcstombs采用s(&convertedChars, nstring, srcsize, src, 采用TRUNCATE);
return nstring;
}
//
采用bstr采用t Convert::Get采用bstr采用t(char* src)
{
采用bstr采用t bstrt(src);
return bstrt;
}
采用bstr采用t Convert::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* Convert::GetCharPtr(采用bstr采用t bstrt)
{
// Convert to a char*
size采用t newsize = bstrt.length()+1;
char *nstring;nstring=new char;
strcpy采用s(nstring,newsize,(char *)bstrt);
//strcat采用s(nstring, " (char *)");
//cout << nstring << endl;
return nstring;
}
wchar采用t* Convert::GetWchar采用t(采用bstr采用t bstrt)
{
// Convert to a wchar采用t*
int srcsize=bstrt.length()+1;
wchar采用t *wcstring;wcstring=new wchar采用t;
wcscpy采用s(wcstring,srcsize,(wchar采用t *)bstrt);
//wcscat采用s(wcstring, L" (wchar采用t *)");
//wcout << wcstring << endl;
return wcstring;
}
ACHAR* Convert::GetAcharPtr(采用bstr采用t bstrt)
{
return GetWchar采用t(bstrt);
}
//CComBSTR Convert::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]