天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 57|回复: 0

ObjectARX中Convert转换类定义

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
// 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[newsize];
    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[newsize];
    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[newsize];
    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[srcsize];
    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;
//}

 

 

 

 

ObjectARX中Convert转换类定义
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 11:38 , Processed in 0.141363 second(s), 25 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表