使用soui开发的mbc,只支持windows版本
w1146869587
2022-01-24 4905e2e7537d507f218e8e9595485e09d9f3a2b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// BaseFun.cpp : implementation file
//
 
#include "stdafx.h"
#include "BaseFun.h"
 
 
 
#define        REG_SUBKEY                    _T( "Software\\Activesoft\\MBClient" )
 
CString m_strBinPath;
// CBaseFun
 
CBaseFun::CBaseFun()
{
    m_strBinPath = _T("");
}
 
CBaseFun::~CBaseFun()
{
}
 
 
// CBaseFun member functions
bool CBaseFun::CStringToAnsi( LPCTSTR pszT,  LPSTR *ppszA  )
{
    ULONG        cbAnsi, cCharacters;
 
    if ( pszT == NULL )
    {
        *ppszA= NULL;
        return false;
    }
#ifdef _UNICODE  
    cCharacters = wcslen(pszT);
    cbAnsi = ::WideCharToMultiByte( CP_ACP, 0, pszT, -1, NULL, 0, NULL, NULL );
    *ppszA = (LPSTR) CoTaskMemAlloc(cbAnsi+1);
    if ( NULL == *ppszA )
        return false;
    ZeroMemory(*ppszA,cbAnsi+1);
    // Convert to ANSI.
    if (0 == WideCharToMultiByte(CP_ACP, 0, pszT, cCharacters, *ppszA,
                  cbAnsi, NULL, NULL))
    {
        CoTaskMemFree(*ppszA);
        *ppszA = NULL;
        return false;
    }
#else
    cCharacters = strlen(pszT);
    *ppszA = (LPSTR) CoTaskMemAlloc(cCharacters+1);
    if ( NULL == *ppszA )
        return false;
    ZeroMemory(*ppszA,cCharacters+1);
    memcpy(*ppszA,pszT,cCharacters);
#endif
     return true;
}
 
 
// Ð´ÈÕÖ¾
void CBaseFun::WriteLog( CString strLog )
{
    //return;
    CTime        tmCurrent    = CTime::GetCurrentTime();
    CString        strTime        = tmCurrent.Format( _T(" %Y-%m-%d %H:%M:%S = ") );
    CString        strEnter    = _T(" \r\n ");
    CString        strBuff;
    LPSTR        pDest ;
    CFile        file;
    CString        strLogFile;
    CString        strLogDir;
    DWORD        dwAttributes = DWORD(-1);
 
    strLogDir.Format( _T("E:\\Log"));
    dwAttributes = GetFileAttributes( strLogDir) ;
    if(dwAttributes == DWORD(-1) || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0 )
        ::CreateDirectory( strLogDir, NULL );
    strLogFile.Format( _T("%s\\STKInside.log"), strLogDir );
    if ( !file.Open( strLogFile, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate) )
    {
        return ;
    }
    file.Seek( 0, CFile::end );
 
    strBuff.Format( _T("%s%s%s"), strTime, strLog,strEnter );
    if ( CStringToAnsi(strBuff, &pDest))
    {
        file.Write( (void*)pDest, strlen(pDest));
        CoTaskMemFree(pDest);
    }
    file.Close();
}
 
CString CBaseFun::GetSTKWorkDir()
{
    CString        strWorkDir;
    CRegKey        reg;
    CString        strSubKey;
    TCHAR        szValue[256]    = { 0 };
    DWORD        dwReaded;
 
    strSubKey.Format( _T("%s"), REG_SUBKEY );
    if ( ERROR_SUCCESS == reg.Open( HKEY_LOCAL_MACHINE, strSubKey, KEY_READ ) )
    {
        dwReaded    = 255;
        if ( ERROR_SUCCESS == reg.QueryStringValue( _T( "WorkDir" ), szValue, &dwReaded ) && dwReaded > 0 )
        {
            strWorkDir     = szValue;
            strWorkDir.TrimRight();
            strWorkDir.TrimRight( '\\' );
        }
 
        reg.Close();
    }
    if ( strWorkDir.IsEmpty() )
        strWorkDir =GetModulePath();
    return    strWorkDir;
}
 
// »ñȡִÐгÌÐòËùÔÚµÄĿ¼
CString CBaseFun::GetModulePath()
{
    CString        strFileName;
     HINSTANCE    hInstance = NULL;
    hInstance = ::GetModuleHandle( _T("mbInside.dll") );
    if (m_strBinPath.IsEmpty( ))
    {
        GetModuleFileName( hInstance, strFileName.GetBuffer( MAX_PATH ), MAX_PATH );
        strFileName.ReleaseBuffer();
        strFileName = GetPathName( strFileName );
        return    strFileName;
    }
    else
        return m_strBinPath;
}
// È¡È«Â·¾¶ÎļþÃûÖеÄ·¾¶
CString CBaseFun::GetPathName( CString strFileName )
{
    int            nPos;
    CString        strPathName;
 
    if ( strFileName.IsEmpty() )
        return    _T( "" );
 
    nPos = strFileName.ReverseFind( '\\' );
    if ( nPos < 0 )
        return    _T( "" );
 
    strPathName    = strFileName.Left( nPos );
    return    strPathName;
}