1 // SoftEther VPN Source Code - Stable Edition Repository
2 // Cedar Communication Module
3 //
4 // SoftEther VPN Server, Client and Bridge are free software under the Apache License, Version 2.0.
5 //
6 // Copyright (c) Daiyuu Nobori.
7 // Copyright (c) SoftEther VPN Project, University of Tsukuba, Japan.
8 // Copyright (c) SoftEther Corporation.
9 // Copyright (c) all contributors on SoftEther VPN project in GitHub.
10 //
11 // All Rights Reserved.
12 //
13 // http://www.softether.org/
14 //
15 // This stable branch is officially managed by Daiyuu Nobori, the owner of SoftEther VPN Project.
16 // Pull requests should be sent to the Developer Edition Master Repository on https://github.com/SoftEtherVPN/SoftEtherVPN
17 //
18 // License: The Apache License, Version 2.0
19 // https://www.apache.org/licenses/LICENSE-2.0
20 //
21 // DISCLAIMER
22 // ==========
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 // SOFTWARE.
31 //
32 // THIS SOFTWARE IS DEVELOPED IN JAPAN, AND DISTRIBUTED FROM JAPAN, UNDER
33 // JAPANESE LAWS. YOU MUST AGREE IN ADVANCE TO USE, COPY, MODIFY, MERGE, PUBLISH,
34 // DISTRIBUTE, SUBLICENSE, AND/OR SELL COPIES OF THIS SOFTWARE, THAT ANY
35 // JURIDICAL DISPUTES WHICH ARE CONCERNED TO THIS SOFTWARE OR ITS CONTENTS,
36 // AGAINST US (SOFTETHER PROJECT, SOFTETHER CORPORATION, DAIYUU NOBORI OR OTHER
37 // SUPPLIERS), OR ANY JURIDICAL DISPUTES AGAINST US WHICH ARE CAUSED BY ANY KIND
38 // OF USING, COPYING, MODIFYING, MERGING, PUBLISHING, DISTRIBUTING, SUBLICENSING,
39 // AND/OR SELLING COPIES OF THIS SOFTWARE SHALL BE REGARDED AS BE CONSTRUED AND
40 // CONTROLLED BY JAPANESE LAWS, AND YOU MUST FURTHER CONSENT TO EXCLUSIVE
41 // JURISDICTION AND VENUE IN THE COURTS SITTING IN TOKYO, JAPAN. YOU MUST WAIVE
42 // ALL DEFENSES OF LACK OF PERSONAL JURISDICTION AND FORUM NON CONVENIENS.
43 // PROCESS MAY BE SERVED ON EITHER PARTY IN THE MANNER AUTHORIZED BY APPLICABLE
44 // LAW OR COURT RULE.
45 //
46 // USE ONLY IN JAPAN. DO NOT USE THIS SOFTWARE IN ANOTHER COUNTRY UNLESS YOU HAVE
47 // A CONFIRMATION THAT THIS SOFTWARE DOES NOT VIOLATE ANY CRIMINAL LAWS OR CIVIL
48 // RIGHTS IN THAT PARTICULAR COUNTRY. USING THIS SOFTWARE IN OTHER COUNTRIES IS
49 // COMPLETELY AT YOUR OWN RISK. THE SOFTETHER VPN PROJECT HAS DEVELOPED AND
50 // DISTRIBUTED THIS SOFTWARE TO COMPLY ONLY WITH THE JAPANESE LAWS AND EXISTING
51 // CIVIL RIGHTS INCLUDING PATENTS WHICH ARE SUBJECTS APPLY IN JAPAN. OTHER
52 // COUNTRIES' LAWS OR CIVIL RIGHTS ARE NONE OF OUR CONCERNS NOR RESPONSIBILITIES.
53 // WE HAVE NEVER INVESTIGATED ANY CRIMINAL REGULATIONS, CIVIL LAWS OR
54 // INTELLECTUAL PROPERTY RIGHTS INCLUDING PATENTS IN ANY OF OTHER 200+ COUNTRIES
55 // AND TERRITORIES. BY NATURE, THERE ARE 200+ REGIONS IN THE WORLD, WITH
56 // DIFFERENT LAWS. IT IS IMPOSSIBLE TO VERIFY EVERY COUNTRIES' LAWS, REGULATIONS
57 // AND CIVIL RIGHTS TO MAKE THE SOFTWARE COMPLY WITH ALL COUNTRIES' LAWS BY THE
58 // PROJECT. EVEN IF YOU WILL BE SUED BY A PRIVATE ENTITY OR BE DAMAGED BY A
59 // PUBLIC SERVANT IN YOUR COUNTRY, THE DEVELOPERS OF THIS SOFTWARE WILL NEVER BE
60 // LIABLE TO RECOVER OR COMPENSATE SUCH DAMAGES, CRIMINAL OR CIVIL
61 // RESPONSIBILITIES. NOTE THAT THIS LINE IS NOT LICENSE RESTRICTION BUT JUST A
62 // STATEMENT FOR WARNING AND DISCLAIMER.
63 //
64 // READ AND UNDERSTAND THE 'WARNING.TXT' FILE BEFORE USING THIS SOFTWARE.
65 // SOME SOFTWARE PROGRAMS FROM THIRD PARTIES ARE INCLUDED ON THIS SOFTWARE WITH
66 // LICENSE CONDITIONS WHICH ARE DESCRIBED ON THE 'THIRD_PARTY.TXT' FILE.
67 //
68 //
69 // SOURCE CODE CONTRIBUTION
70 // ------------------------
71 //
72 // Your contribution to SoftEther VPN Project is much appreciated.
73 // Please send patches to us through GitHub.
74 // Read the SoftEther VPN Patch Acceptance Policy in advance:
75 // http://www.softether.org/5-download/src/9.patch
76 //
77 //
78 // DEAR SECURITY EXPERTS
79 // ---------------------
80 //
81 // If you find a bug or a security vulnerability please kindly inform us
82 // about the problem immediately so that we can fix the security problem
83 // to protect a lot of users around the world as soon as possible.
84 //
85 // Our e-mail address for security reports is:
86 // softether-vpn-security [at] softether.org
87 //
88 // Please note that the above e-mail address is not a technical support
89 // inquiry address. If you need technical assistance, please visit
90 // http://www.softether.org/ and ask your question on the users forum.
91 //
92 // Thank you for your cooperation.
93 //
94 //
95 // NO MEMORY OR RESOURCE LEAKS
96 // ---------------------------
97 //
98 // The memory-leaks and resource-leaks verification under the stress
99 // test has been passed before release this source code.
100 
101 
102 // WinJumpList.cpp
103 // HTML display module source code for Win32
104 
105 #include <GlobalConst.h>
106 
107 #ifdef	WIN32
108 
109 //#define NTDDI_WIN7                          0x06010000
110 //#define	_WIN32_WINNT	_WIN32_WINNT_VISTA
111 //#define NTDDI_VERSION NTDDI_VISTA  // Specifies that the minimum required platform is Windows 7.
112 #define WIN32_LEAN_AND_MEAN       // Exclude rarely-used stuff from Windows headers
113 #define STRICT_TYPED_ITEMIDS      // Utilize strictly typed IDLists
114 
115 //#include <objectarray.h>
116 #include <shobjidl.h>
117 #include <propkey.h>
118 #include <propvarutil.h>
119 //#include <knownfolders.h>
120 //#include <shlobj.h>
121 
122 
123 #ifdef StrCpy
124 #undef StrCpy
125 #endif
126 
127 #ifdef StrCat
128 #undef StrCat
129 #endif
130 
131 #ifdef StrCmp
132 #undef StrCmp
133 #endif
134 
135 
136 #define	WIN32COM_CPP
137 
138 //#define	_WIN32_WINNT		0x0502
139 //#define	WINVER				0x0502
140 #include <winsock2.h>
141 #include <windows.h>
142 #include <wincrypt.h>
143 #include <wininet.h>
144 #include <comdef.h>
145 #include <Mshtmhst.h>
146 //#include <shlobj.h>
147 #include <commctrl.h>
148 #include <Dbghelp.h>
149 #include <stdio.h>
150 #include <stdlib.h>
151 #include <string.h>
152 #include <wchar.h>
153 #include <stdarg.h>
154 #include <time.h>
155 #include <errno.h>
156 
157 extern "C"
158 {
159 #include <Mayaqua/Mayaqua.h>
160 #include <Cedar/Cedar.h>
161 }
162 #include "../PenCore/resource.h"
163 
164 extern "C"
165 {
166 
167 	//////////////////////////////////////////////////////////////////////////
168 	//JumpList
169 	//#define NTDDI_WIN7                          0x06010000
170 	//#define NTDDI_VERSION NTDDI_WIN7  // Specifies that the minimum required platform is Windows 7.
171 	//#define WIN32_LEAN_AND_MEAN       // Exclude rarely-used stuff from Windows headers
172 	//#define STRICT_TYPED_ITEMIDS      // Utilize strictly typed IDLists
173 	//
174 	//
175 	//#include <shobjidl.h>
176 	//#include <propkey.h>
177 	//#include <propvarutil.h>
178 	//#include <knownfolders.h>
179 	//#include <shlobj.h>
180 	//
181 	//#pragma comment(lib, "propsys.lib")
182 	//#pragma comment(lib, "shlwapi.lib")
183 
184 	#define CREATE_PROPERTYKEY(l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, pid) { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }, pid }
185 
186 
187 	// Determines if the provided IShellItem is listed in the array of items that the user has removed
_IsItemInArray(IShellItem * psi,IObjectArray * poaRemoved)188 	bool _IsItemInArray(IShellItem *psi, IObjectArray *poaRemoved)
189 	{
190 		bool fRet = false;
191 		UINT cItems;
192 		if (SUCCEEDED(poaRemoved->GetCount(&cItems)))
193 		{
194 			IShellItem *psiCompare;
195 			for (UINT i = 0; !fRet && i < cItems; i++)
196 			{
197 				if (SUCCEEDED(poaRemoved->GetAt(i, IID_PPV_ARGS(&psiCompare))))
198 				{
199 					int iOrder;
200 					fRet = SUCCEEDED(psiCompare->Compare(psi, SICHINT_CANONICAL, &iOrder)) && (0 == iOrder);
201 					psiCompare->Release();
202 				}
203 			}
204 		}
205 		return fRet;
206 	}
207 
208 
JL_CreateCustomDestinationList(JL_PCustomDestinationList * poc,wchar_t * appID)209 	JL_HRESULT JL_CreateCustomDestinationList(JL_PCustomDestinationList* poc, wchar_t* appID)
210 	{
211 		ICustomDestinationList *pcdl;
212 
213 		//CLSID_DestinationList = 6332DEBF-87B5-4670-90C0-5E57-B408-A49E
214 
215 		GUID destList;
216 
217 		destList.Data1 = 2012286192;
218 		destList.Data2 = 15797;
219 		destList.Data3 = 18790;
220 
221 		destList.Data4[0] = 181;
222 		destList.Data4[1] = 32;
223 		destList.Data4[2] = 183;
224 		destList.Data4[3] = 197;
225 		destList.Data4[4] = 79;
226 		destList.Data4[5] = 211;
227 		destList.Data4[6] = 94;
228 		destList.Data4[7] = 214;
229 
230 		//destList = CLSID_DestinationList;
231 
232 		//HRESULT hr = CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pcdl));
233 		HRESULT hr = CoCreateInstance(destList,
234 			NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pcdl));
235 
236 		if (SUCCEEDED(hr))
237 		{
238 			pcdl->SetAppID(appID);
239 			(*poc) = (void*)pcdl;
240 		}
241 		else
242 		{
243 			(*poc) = NULL;
244 		}
245 
246 		return hr;
247 	}
248 
JL_ReleaseCustomDestinationList(JL_PCustomDestinationList poc)249 	JL_HRESULT JL_ReleaseCustomDestinationList(JL_PCustomDestinationList poc)
250 	{
251 		ICustomDestinationList *pcdl = (ICustomDestinationList*)poc;
252 		if(pcdl != NULL)
253 		{
254 			pcdl->Release();
255 		}
256 
257 		return 0;
258 	}
259 
JL_BeginList(JL_PCustomDestinationList poc,JL_PObjectArray * oaRemoved)260 	JL_HRESULT JL_BeginList(JL_PCustomDestinationList poc, JL_PObjectArray* oaRemoved)
261 	{
262 		UINT cMinSlots;
263 		IObjectArray *poaRemoved;
264 
265 		ICustomDestinationList *pcdl = (ICustomDestinationList*)poc;
266 
267 		HRESULT hr = pcdl->BeginList(&cMinSlots, IID_PPV_ARGS(&poaRemoved));
268 
269 		(*oaRemoved) = poaRemoved;
270 
271 		return hr;
272 	}
273 
JL_CommitList(JL_PCustomDestinationList cdl)274 	JL_HRESULT JL_CommitList(JL_PCustomDestinationList cdl)
275 	{
276 		ICustomDestinationList *pcdl = (ICustomDestinationList*)cdl;
277 
278 		return pcdl->CommitList();
279 	}
280 
281 
282 	//JL_HRESULT JL_AddTasksToList(JL_PCustomDestinationList pcdl, JL_PObjectCollection poc)
283 	//{
284 	//	return 0;
285 	//}
286 
JL_CreateObjectCollection(JL_PObjectCollection * jpoc)287 	JL_HRESULT JL_CreateObjectCollection(JL_PObjectCollection* jpoc)
288 	{
289 
290 		//CLSID_EnumerableObjectCollection = 2D3468C1-36A7-43B6-AC24-D3F0-2FD9-607A
291 
292 
293 		GUID enumObjCol;
294 
295 		enumObjCol.Data1 = 758409409;
296 		enumObjCol.Data2 = 13991;
297 		enumObjCol.Data3 = 17334;
298 
299 		enumObjCol.Data4[0] = 172;
300 		enumObjCol.Data4[1] = 36;
301 		enumObjCol.Data4[2] = 211;
302 		enumObjCol.Data4[3] = 240;
303 		enumObjCol.Data4[4] = 47;
304 		enumObjCol.Data4[5] = 217;
305 		enumObjCol.Data4[6] = 96;
306 		enumObjCol.Data4[7] = 122;
307 
308 		//enumObjCol = CLSID_EnumerableObjectCollection;
309 
310 		IObjectCollection *poc;
311 		//HRESULT hr = CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC, IID_PPV_ARGS(&poc));
312 		HRESULT hr = CoCreateInstance(enumObjCol,
313 			NULL, CLSCTX_INPROC, IID_PPV_ARGS(&poc));
314 
315 		if (SUCCEEDED(hr))
316 		{
317 			(*jpoc) = poc;
318 		}
319 		else{
320 			(*jpoc) = NULL;
321 		}
322 		return hr;
323 	}
324 
JL_ReleaseObjectCollection(JL_PObjectCollection jpoc)325 	JL_HRESULT JL_ReleaseObjectCollection(JL_PObjectCollection jpoc)
326 	{
327 		IObjectCollection *poc = (IObjectCollection *)jpoc;
328 		if(poc != NULL)
329 		{
330 			return poc->Release();
331 		}
332 
333 		return 0;
334 	}
335 
JL_ObjectCollectionAddShellLink(JL_PObjectCollection jpoc,JL_PShellLink jpsl)336 	JL_HRESULT JL_ObjectCollectionAddShellLink(JL_PObjectCollection jpoc, JL_PShellLink jpsl)
337 	{
338 		IObjectCollection *poc = (IObjectCollection *)jpoc;
339 		IShellLink *psl = (IShellLink *) jpsl;
340 
341 		return poc->AddObject(psl);
342 
343 	}
344 
345 
JL_AddCategoryToList(JL_PCustomDestinationList jpcdl,JL_PObjectCollection jpoc,wchar_t * categoryName,JL_PObjectArray jpoaRemoved)346 	JL_HRESULT JL_AddCategoryToList(JL_PCustomDestinationList jpcdl,
347 		JL_PObjectCollection jpoc,
348 		wchar_t* categoryName,
349 		JL_PObjectArray jpoaRemoved)
350 	{
351 		ICustomDestinationList *pcdl = (ICustomDestinationList*)jpcdl;
352 		IObjectCollection *poc = (IObjectCollection *)jpoc;
353 		 IObjectArray *poaRemoved = (IObjectArray*)jpoaRemoved;
354 
355 		//for (UINT i = 0; i < ARRAYSIZE(c_rgpszFiles); i++)
356 		//{
357 		//	IShellItem *psi;
358 		//	if (SUCCEEDED(SHCreateItemInKnownFolder(FOLDERID_Documents, KF_FLAG_DEFAULT, c_rgpszFiles[i], IID_PPV_ARGS(&psi))))
359 		//	{
360 		//		// Items listed in the removed list may not be re-added to the Jump List during this
361 		//		// list-building transaction.  They should not be re-added to the Jump List until
362 		//		// the user has used the item again.  The AppendCategory call below will fail if
363 		//		// an attempt to add an item in the removed list is made.
364 		//		if (!_IsItemInArray(psi, poaRemoved))
365 		//		{
366 		//			poc->AddObject(psi);
367 		//		}
368 		//		psi->Release();
369 		//	}
370 		//}
371 
372 		IObjectArray *poa;
373 		HRESULT hr = poc->QueryInterface(IID_PPV_ARGS(&poa));
374 		if (SUCCEEDED(hr))
375 		{
376 
377 			// Add the category to the Jump List.  If there were more categories, they would appear
378 			// from top to bottom in the order they were appended.
379 			hr = pcdl->AppendCategory(categoryName, poa);
380 			//hr = pcdl->AddUserTasks(poa);
381 			poa->Release();
382 
383 			if (SUCCEEDED(hr))
384 			{
385 			}
386 			else
387 			{
388 				Print("Failed AppendCategory\n");
389 			}
390 		}
391 		else
392 		{
393 			Print("Failed QueryInterface\n");
394 		}
395 
396 
397 		return hr;
398 	}
399 
400 
401 
JL_CreateShellLink(wchar_t * pszPath,wchar_t * pszArguments,wchar_t * pszTitle,wchar_t * iconLocation,int iconIndex,wchar_t * description,JL_PShellLink * ppsl)402 	JL_HRESULT JL_CreateShellLink(
403 		wchar_t* pszPath,
404 		wchar_t* pszArguments,
405 		wchar_t* pszTitle,
406 		wchar_t* iconLocation,
407 		int iconIndex,
408 		wchar_t* description, JL_PShellLink *ppsl)
409 	{
410 		IShellLinkW *psl;
411 		HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&psl));
412 		if (SUCCEEDED(hr))
413 		{
414 			// Determine our executable's file path so the task will execute this application
415 			//WCHAR szAppPath[MAX_PATH];
416 			//if (GetModuleFileName(NULL, szAppPath, ARRAYSIZE(szAppPath)))
417 			//{
418 				//hr = psl->SetPath(L"C:\\Program Files\\PacketiX VPN Client\\vpncmgr.exe");
419 				//hr = psl->SetArguments(L"50792311B00B9E01E7534AAA881087AB2BB83A1F");
420 
421 
422 			psl->SetPath(pszPath);
423 			psl->SetArguments(pszArguments);
424 			if(iconLocation != NULL)
425 			{
426 				psl->SetIconLocation(iconLocation,iconIndex);
427 			}
428 
429 			if(description != NULL)
430 			{
431 				psl->SetDescription(description);
432 			}
433 				if (SUCCEEDED(hr))
434 				{
435 					// The title property is required on Jump List items provided as an IShellLink
436 					// instance.  This value is used as the display name in the Jump List.
437 					IPropertyStore *pps;
438 					hr = psl->QueryInterface(IID_PPV_ARGS(&pps));
439 					if (SUCCEEDED(hr))
440 					{
441 						PROPVARIANT propvar;
442 						hr = InitPropVariantFromString(pszTitle, &propvar);
443 						if (SUCCEEDED(hr))
444 						{
445 
446 							////PKEY_Title
447 							//#define DEFINE_PROPERTYKEY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, pid)
448 							//EXTERN_C const PROPERTYKEY DECLSPEC_SELECTANY name
449 							//	= { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }, pid }
450 							//DEFINE_PROPERTYKEY(PKEY_Title, 0xF29F85E0, 0x4FF9, 0x1068, 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9, 2);
451 
452 							PROPERTYKEY pkey_title =
453 								CREATE_PROPERTYKEY(0xF29F85E0, 0x4FF9, 0x1068, 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9, 2);
454 
455 
456 							//hr = pps->SetValue(PKEY_Title, propvar);
457 							hr = pps->SetValue(pkey_title, propvar);
458 
459 
460 							if (SUCCEEDED(hr))
461 							{
462 								hr = pps->Commit();
463 								if (SUCCEEDED(hr))
464 								{
465 									IShellLink *tpsl;
466 									hr = psl->QueryInterface(IID_PPV_ARGS(&tpsl));
467 									(*ppsl) = tpsl;
468 								}
469 							}
470 							PropVariantClear(&propvar);
471 						}
472 						pps->Release();
473 					}
474 				}
475 
476 				/*
477 				hr = psl->SetPath(szAppPath);
478 				if (SUCCEEDED(hr))
479 				{
480 				hr = psl->SetArguments(pszArguments);
481 				if (SUCCEEDED(hr))
482 				{
483 				// The title property is required on Jump List items provided as an IShellLink
484 				// instance.  This value is used as the display name in the Jump List.
485 				IPropertyStore *pps;
486 				hr = psl->QueryInterface(IID_PPV_ARGS(&pps));
487 				if (SUCCEEDED(hr))
488 				{
489 				PROPVARIANT propvar;
490 				hr = InitPropVariantFromString(pszTitle, &propvar);
491 				if (SUCCEEDED(hr))
492 				{
493 				hr = pps->SetValue(PKEY_Title, propvar);
494 				if (SUCCEEDED(hr))
495 				{
496 				hr = pps->Commit();
497 				if (SUCCEEDED(hr))
498 				{
499 				hr = psl->QueryInterface(IID_PPV_ARGS(ppsl));
500 				}
501 				}
502 				PropVariantClear(&propvar);
503 				}
504 				pps->Release();
505 				}
506 				}
507 				}
508 				*/
509 			//}
510 			//else
511 			//{
512 			//	hr = HRESULT_FROM_WIN32(GetLastError());
513 			//}
514 			psl->Release();
515 		}
516 		return hr;
517 	}
518 
JL_ReleaseShellLink(JL_PShellLink jpsl)519 	JL_HRESULT JL_ReleaseShellLink(JL_PShellLink jpsl)
520 	{
521 		IShellLink *psl = (IShellLink *) jpsl;
522 
523 		if(psl != NULL)
524 		{
525 			return psl->Release();
526 		}
527 
528 		return 0;
529 	}
530 
531 	// Removes that existing custom Jump List for this application.
JL_DeleteJumpList(JL_PCustomDestinationList jpcdl,wchar_t * appID)532 	JL_HRESULT JL_DeleteJumpList(JL_PCustomDestinationList jpcdl,wchar_t* appID)
533 	{
534 		ICustomDestinationList *pcdl = (ICustomDestinationList *)jpcdl;
535 		//HRESULT hr = CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pcdl));
536 
537 		HRESULT	hr = pcdl->DeleteList(appID);
538 
539 
540 		return hr;
541 	}
542 
543 
544 
545 	//////////////////////////////////////////////////////////////////////////
546 	//SetApplicationID for Windows 7
JL_SetCurrentProcessExplicitAppUserModelID(wchar_t * appID)547 	JL_HRESULT JL_SetCurrentProcessExplicitAppUserModelID(wchar_t* appID)
548 	{
549 #ifdef UNICODE
550 		HMODULE hModule = LoadLibraryW( L"shell32.dll");
551 #else
552 		HMODULE hModule = LoadLibraryA( "shell32.dll");
553 #endif
554 		HRESULT (__stdcall *SetAppID) (PCWSTR);
555 
556 		if( hModule == NULL )
557 		{
558 			//// Load failure (there is no DLL)
559 			// MessageBoxW( NULL, L"shell32.dll not found", L"Error", MB_OK );
560 			Print("Not Found shell32.dll");
561 		}
562 		else
563 		{
564 			// Get the address of the function in the DLL
565 			SetAppID = (HRESULT (__stdcall *)(PCWSTR))
566 				GetProcAddress( hModule, "SetCurrentProcessExplicitAppUserModelID" );
567 			if( SetAppID != NULL )
568 			{
569 				FreeLibrary( hModule );
570 				return SetAppID(appID);
571 			}
572 			else
573 			{
574 				//MessageBoxW( NULL, L"There may not be a function", L"Error", MB_OK );
575 				Print("Not Found SetCurrentProcessExplicitAppUserModelID");
576 
577 			}
578 
579 			// Release the loaded DLL
580 			FreeLibrary( hModule );
581 		}
582 		return 0;
583 
584 
585 	}
586 
587 
588 
589 }
590 
591 #endif
592 
593 //////////////////////////////////////////////////////////////////////////
594 // Size Rect
595 //
596 
GetBoundingRect(CT_RectF_c * rect)597 CT_Rect GetBoundingRect(CT_RectF_c* rect)
598 {
599 	CT_Rect r = CT_Rect((int)rect->X,(int)rect->Y,(int)rect->Width,(int)rect->Height);
600 	if(r.Right() < (rect->X + rect->Width))
601 		r.Width+=1;
602 	if(r.Bottom() < (rect->Y + rect->Height))
603 		r.Height+=1;
604 
605 	return r;
606 }
607 
608 
609 CT_ARGB32 CT_GetAAPix32(UCHAR* srcPtr, int width, int height, int xFix, int yFix);
610 
611 //////////////////////////////////////////////////////////////////////////
612 // DrawImage method
CT_DrawImage(UCHAR * dest,CT_RectF_c destRect,int destWidth,int destHeight,UCHAR * src,CT_RectF_c srcRect,int srcWidth,int srcHeight)613 void CT_DrawImage(UCHAR* dest, CT_RectF_c destRect, int destWidth, int destHeight,
614 				  UCHAR* src, CT_RectF_c srcRect, int srcWidth, int srcHeight)
615 {
616 
617 	double scaleW = destRect.Width / srcRect.Width;
618 	double scaleH = destRect.Height / srcRect.Height;
619 
620 
621 	CT_ARGB32* dest32 = (CT_ARGB32*)(dest);
622 	CT_ARGB32* src32 =  (CT_ARGB32*)(src);
623 
624 	float dfx = (float)(1 / scaleW);
625 	float dfy = (float)(1 / scaleH);
626 
627 	float srcSX = srcRect.X;
628 	float srcSY = srcRect.Y;
629 
630 	int srcSXFix = (int)(srcSX*65536);
631 	int srcSYFix = (int)(srcSY*65536);
632 	int dfxFix = (int)(dfx*65536);
633 	int dfyFix = (int)(dfy*65536);
634 
635 	//CT_Rect dRect = destRect.GetBoundingRect();
636 
637 	CT_Rect dRect = GetBoundingRect(&destRect);
638 
639 	// Clipping not supported: ToDo
640 	dRect.X = ct_max(0,dRect.X);
641 	dRect.Y = ct_max(0,dRect.Y);
642 	dRect.Right((int)ct_min(destRect.X + destRect.Width,dRect.Right()));
643 	dRect.Bottom((int)ct_min(destRect.Y + destRect.Height,dRect.Bottom()));
644 
645 	//CT_ARGB32* dPix = dest32->GetPixelAddressNC(dRect.X, dRect.Y);
646 	CT_ARGB32* dPix = &(dest32[destWidth*dRect.Y + dRect.X]);
647 
648 	//int dpW = dest32->GetWidth() - dRect.Width;
649 	int dpW = destWidth - dRect.Width;
650 	for (int dy = dRect.Y; dy < dRect.Bottom(); dy++)
651 	{
652 
653 		int syFix = srcSYFix;
654 		int sxFix = srcSXFix;
655 
656 		// Anti-aliasing
657 		for (int dx = dRect.X; dx < dRect.Right(); dx++)
658 		{
659 			int rPixX = ( ((sxFix >> 15) & 0x00000001) == 1) ? (sxFix >> 16)+1 : (sxFix >> 16);
660 			int rPixY = ( ((syFix >> 15) & 0x00000001) == 1) ? (syFix >> 16)+1 : (syFix >> 16);
661 
662 			//CT_ARGB32* sPix = &(src32[rPixY * srcWidth + rPixX]);
663 
664 			//*dPix = *sPix;
665 			//if(sPix != NULL)
666 			{
667 				//*dPix = src32->GetAAPix32(sxFix,syFix);
668 				*dPix = CT_GetAAPix32((UCHAR*)src32, srcWidth, srcHeight,sxFix, syFix);
669 			}
670 
671 			sxFix += dfxFix;
672 			dPix++;
673 		}
674 
675 
676 		srcSYFix += dfyFix;
677 		dPix += dpW;
678 	}
679 
680 }
681 
isWhiteColor(CT_ARGB32 col)682 bool isWhiteColor(CT_ARGB32 col)
683 {
684 	return
685 		(col.R == 255 &&
686 		 col.G == 255 &&
687 		 col.B == 255);
688 }
689 
690 
CT_GetAAPix32(UCHAR * srcPtr,int width,int height,int xFix,int yFix)691 CT_ARGB32 CT_GetAAPix32(UCHAR* srcPtr, int width, int height, int xFix, int yFix)
692 {
693 
694 	//return CT_ARGB32(255,255,255,255);
695 
696 	//CT_Bitmap32* src = this;
697 	CT_ARGB32* src = (CT_ARGB32*)(srcPtr);
698 
699 	int fixx = xFix;
700 	int fixy = yFix;
701 
702 	int fx = (fixx >> 8) & 0xFF;
703 	int fy = (fixy >> 8) & 0xFF;
704 
705 	int f[4];
706 	f[0] = ((255 - fx) * (255 - fy)) >> 8;
707 	f[1] = (fx * (255 - fy)) >> 8;
708 	f[2] = ((255 - fx) * fy) >> 8;
709 	f[3] = (fx * fy) >> 8;
710 
711 	int px = fixx >> 16;
712 	int py = fixy >> 16;
713 
714 	int a, r, g, b;
715 	a = r = g = b = 0;
716 	CT_Size size = CT_Size(width, height);
717 	CT_ARGB32 col = CT_ARGB32(0,255,255,255);
718 
719 	CT_ARGB32 pixs[4];
720 	for(int j = 0; j < 2; j++)
721 	{
722 		for (int i = 0; i < 2; i++)
723 		{
724 			int sx = px + i;
725 			int sy = py + j;
726 
727 			CT_ARGB32* c;
728 
729 			if(sx < 0 || sx >= width || sy < 0 || sy >= height)
730 			{
731 				c = &col;
732 			}
733 			else
734 			{
735 				//c = src->GetPixelAddressNC(sx, sy);
736 				c = &(src[sy * width + sx]);
737 			}
738 			pixs[j*2+i] = *c;
739 
740 			a += c->A * f[j*2 + i];
741 			r += c->R * f[j*2 + i];
742 			g += c->G * f[j*2 + i];
743 			b += c->B * f[j*2 + i];
744 
745 		}
746 	}
747 
748 	bool isAllWhite = true;
749 	for(int k = 0; k < 4; k++)
750 	{
751 		if(!isWhiteColor(pixs[k]))
752 		{
753 			isAllWhite = false;
754 			break;
755 		}
756 	}
757 
758 	if(isAllWhite)
759 	{
760 		//
761 		return CT_ARGB32(0, 255, 255, 255);
762 	}
763 	else
764 	{
765 		a = a >> 8;
766 		r = r >> 8;
767 		g = g >> 8;
768 		b = b >> 8;
769 
770 		return CT_ARGB32(a, r, g, b);
771 	}
772 
773 }
774 
775 //
776 
777