使用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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
ÿþ// dui-demo.cpp : main source file
//
 
#include "stdafx.h"
#include "MainDlg.h"
//ÎNPE‡eöN R} ÿèlaÎN‡eöN R}ï„_MOn
#define RES_TYPE 0
//#define SYSRES_TYPE 0
// #define RES_TYPE 0   //PE
// #define RES_TYPE 1   //ZIP
// #define RES_TYPE 2   //7z
// #define RES_TYPE 2   //‡eöN
//»S‰cYy˜/ec ÿåNMQãNx>f—_÷mqN
#if (RES_TYPE==1)
#include "resprovider-zip\zipresprovider-param.h"
#else 
#if (RES_TYPE==2)
#include "resprovider-7zip\zip7resprovider-param.h"
#endif
#endif
#ifdef _DEBUG
#define SYS_NAMED_RESOURCE _T("soui-sys-resourced.dll")
#else
#define SYS_NAMED_RESOURCE _T("soui-sys-resource.dll")
#endif
 
CString        g_szPropName = _T("");
 
//š[IN/UN„vN*NR,UIRESù[aŒ,ROBJ_IN_CPP/fresource.h-Nš[IN„v[0
ROBJ_IN_CPP
 
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int /*nCmdShow*/)
{
    HRESULT hRes = OleInitialize(NULL);
    SASSERT(SUCCEEDED(hRes));
 
    int nRet = 0;
 
    SComMgr *pComMgr = new SComMgr;
    TCHAR szCurrentDir[MAX_PATH] = { 0 };
    GetModuleFileName(NULL, szCurrentDir, sizeof(szCurrentDir));
 
    LPTSTR lpInsertPos = _tcsrchr(szCurrentDir, _T('\\'));
#ifdef _DEBUG
    _tcscpy(lpInsertPos + 1, _T("..\\mbupdate"));
#else
    _tcscpy(lpInsertPos + 1, _T("\0"));
#endif
    SetCurrentDirectory(szCurrentDir);
    {
        BOOL bLoaded = FALSE;
        CAutoRefPtr<SOUI::IImgDecoderFactory> pImgDecoderFactory;
        CAutoRefPtr<SOUI::IRenderFactory> pRenderFactory;
        bLoaded = pComMgr->CreateRender_Skia((IObjRef**)&pRenderFactory);
        SASSERT_FMT(bLoaded, _T("load interface [render] failed!"));
        bLoaded = pComMgr->CreateImgDecoder((IObjRef**)&pImgDecoderFactory);
        SASSERT_FMT(bLoaded, _T("load interface [%s] failed!"), _T("imgdecoder"));
 
        pRenderFactory->SetImgDecoderFactory(pImgDecoderFactory);
        SApplication *theApp = new SApplication(pRenderFactory, hInstance);
#ifdef _DEBUG
        //    éb†NÅN(WReleaseHr,gSbSDnRû|ß~Dn(WDEBUG NËYÈ~O(uDLL R}
        {
            HMODULE hModSysResource = LoadLibrary(SYS_NAMED_RESOURCE);
            if (hModSysResource)
            {
                CAutoRefPtr<IResProvider> sysResProvider;
                CreateResProvider(RES_PE, (IObjRef**)&sysResProvider);
                sysResProvider->Init((WPARAM)hModSysResource, 0);
                theApp->LoadSystemNamedResource(sysResProvider);
                FreeLibrary(hModSysResource);
            }
            else
            {
                SASSERT(0);
            }
        }
#else        
        //ÎNDLL R}û|ß~Dn
        {
            HMODULE hModSysResource = LoadLibrary(SYS_NAMED_RESOURCE);
            if (hModSysResource)
            {
                CAutoRefPtr<IResProvider> sysResProvider;
                CreateResProvider(RES_PE, (IObjRef**)&sysResProvider);
                sysResProvider->Init((WPARAM)hModSysResource, 0);
                theApp->LoadSystemNamedResource(sysResProvider);
                FreeLibrary(hModSysResource);
            }
            else
            {
                SASSERT(0);
            }
        }
#endif
    g_szPropName.Format( _T("%s-%s"), _T("Asoft"),  _T("MBUpdate") );
    CString strCmd;
    BOOL bAutoStart;
    HANDLE hSem = CreateSemaphore(NULL, 1, 1, g_szPropName );
    if ( GetLastError() == ERROR_ALREADY_EXISTS )
        bAutoStart = FALSE;
    else
        bAutoStart = TRUE;
    
    strCmd = lpstrCmdLine;
    
    if ( !bAutoStart )
    {
        CloseHandle( hSem );
        if(strCmd.IsEmpty())
        {
            return FALSE;
        }
        HWND hWndPrevious = ::GetWindow(::GetDesktopWindow(), GW_CHILD);
        while ( ::IsWindow(hWndPrevious ))
        {
            if ( ::GetProp(hWndPrevious, g_szPropName) )
            {
                if ( ::GetLastActivePopup(hWndPrevious) == hWndPrevious )
                {
                    LPTSTR    lpData;
 
                    //mutex
                    HANDLE hMyIESem = CreateMutex(NULL, TRUE, _T("MBUpdateMutex") );
                    WaitForSingleObject(hMyIESem, INFINITE);
 
                    HANDLE hMapping = CreateFileMapping
                    ((HANDLE)0xFFFFFFFF,NULL,
                    PAGE_READWRITE,0,2560,_T("MBUpdateSHARE") );
                    if (hMapping==NULL)
                    {
                        AfxMessageBox( _T("Fail to create share memory!") );
                    }
                    else
                    {
                        lpData = (LPTSTR) MapViewOfFile(hMapping,FILE_MAP_ALL_ACCESS,0,0,0);
                        if (lpData==NULL)
                        {
                            AfxMessageBox( _T("MapViewOfFile Fail") );
                        }
                        else 
                        {
                            _stprintf(lpData,_T("%s"), strCmd );
                            {
                                ::SendMessage( hWndPrevious, WM_USER_SHELL_OPEN, (long)&strCmd, 0 );
                            }
                        }
                        CloseHandle(hMapping);
                    }
                    ReleaseMutex(hMyIESem);
                }
 
                return FALSE;
            }
 
            hWndPrevious = ::GetWindow(hWndPrevious, GW_HWNDNEXT);
        }
 
        return FALSE;
    }
        CAutoRefPtr<IResProvider>   pResProvider;
 
#ifdef _DEBUG        
        //    éb†NÅN(WReleaseHr,gSbSDnR(WDEBUG NËYÈ~O(u‡eöN R}
        {
            CreateResProvider(RES_FILE, (IObjRef**)&pResProvider);
            bLoaded = pResProvider->Init((LPARAM)_T("uires"), 0);
            SASSERT(bLoaded);
        }
#else
        {
            CreateResProvider(RES_PE, (IObjRef**)&pResProvider);
            bLoaded = pResProvider->Init((WPARAM)hInstance, 0);
            SASSERT(bLoaded);
        }
#endif
        theApp->InitXmlNamedID(namedXmlID, ARRAYSIZE(namedXmlID), TRUE);
        theApp->AddResProvider(pResProvider);
 
        // BLOCK: Run application
        {
            CMainDlg dlgMain;
            dlgMain.Create(GetActiveWindow());
            dlgMain.SendMessage(WM_INITDIALOG);
            dlgMain.CenterWindow(dlgMain.m_hWnd);
            #ifndef _DEBUG
                dlgMain.ShowWindow(SW_HIDE);
            #else
                dlgMain.ShowWindow(SW_SHOWNORMAL);
            #endif
            
            nRet = theApp->Run(dlgMain.m_hWnd);
        }
        delete theApp;
    }
    delete pComMgr;
    OleUninitialize();
    return nRet;
}