Rev 70 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 70 | Rev 71 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #ifndef _UD2_UTILS_H_ |
1 | #ifndef _UD2_UTILS_H_ |
2 | #define _UD2_UTILS_H_ |
2 | #define _UD2_UTILS_H_ |
3 | 3 | ||
4 | #include <windows.h> |
4 | #include <windows.h> |
5 | #include <assert.h> |
- | |
6 | 5 | ||
7 | #include "ud2_api.h" |
6 | #include "ud2_api.h" |
8 | 7 | ||
9 | // #define USE_OLE32 |
- | |
10 | - | ||
11 | #ifdef USE_OLE32 |
- | |
12 | #pragma comment(linker, "-lOle32") |
- | |
13 | #define __GUID(x) _StringToGUID(L ## x) |
- | |
14 | const GUID _StringToGUID(LPCWSTR lpcstrGUID) { |
- | |
15 | GUID guid; |
- | |
16 | assert(SUCCEEDED(CLSIDFromString(lpcstrGUID, &guid))); |
- | |
17 | return guid; |
- | |
18 | } |
- | |
19 | #else |
- | |
20 | #define __GUID(x) _StringToGUID(x) |
- | |
21 | const bool StringToGUID(const char* szGUID, GUID* g) { |
- | |
22 | // Check if string is a valid GUID |
- | |
23 | if (strlen(szGUID) != 38) return false; |
- | |
24 | for (int i=0; i<strlen(szGUID); ++i) { |
- | |
25 | char g = szGUID[i]; |
- | |
26 | - | ||
27 | if (i == 0) { |
- | |
28 | if (g != '{') return false; |
- | |
29 | } else if (i == 37) { |
- | |
30 | if (g != '}') return false; |
- | |
31 | } else if ((i == 9) || (i == 14) || (i == 19) || (i == 24)) { |
- | |
32 | if (g != '-') return false; |
- | |
33 | } else { |
- | |
34 | if (!((g >= '0') && (g <= '9')) && !((g >= 'A') && (g <= 'F')) && !((g >= 'a') && (g <= 'f'))) { |
- | |
35 | return false; |
- | |
36 | } |
- | |
37 | } |
- | |
38 | } |
- | |
39 | - | ||
40 | char* pEnd; |
- | |
41 | g->Data1 = strtol(szGUID+1,&pEnd,16); |
- | |
42 | g->Data2 = strtol(szGUID+10,&pEnd,16); |
- | |
43 | g->Data3 = strtol(szGUID+15,&pEnd,16); |
- | |
44 | char b[3]; b[2] = 0; |
- | |
45 | memcpy(&b[0], szGUID+20, 2*sizeof(b[0])); g->Data4[0] = strtol(&b[0], &pEnd, 16); |
- | |
46 | memcpy(&b[0], szGUID+22, 2*sizeof(b[0])); g->Data4[1] = strtol(&b[0], &pEnd, 16); |
- | |
47 | for (int i=0; i<6; ++i) { |
- | |
48 | memcpy(&b[0], szGUID+25+i*2, 2*sizeof(b[0])); g->Data4[2+i] = strtol(&b[0], &pEnd, 16); |
- | |
49 | } |
- | |
50 | return true; |
- | |
51 | } |
- | |
52 | const GUID _StringToGUID(const char* szGUID) { |
- | |
53 | GUID g; |
- | |
54 | assert(StringToGUID(szGUID, &g)); |
- | |
55 | return g; |
- | |
56 | } |
- | |
57 | #endif |
- | |
58 | - | ||
59 | BOOL UD2_IsMultilineW(LPCWSTR lpSrc) { |
8 | BOOL UD2_IsMultilineW(LPCWSTR lpSrc) { |
60 | return wcschr(lpSrc, UD2_MULTIPLE_ITEMS_DELIMITER) != NULL; |
9 | return wcschr(lpSrc, UD2_MULTIPLE_ITEMS_DELIMITER) != NULL; |
61 | // return wcspbrk(lpSrc, L"\r\n") != NULL; |
10 | // return wcspbrk(lpSrc, L"\r\n") != NULL; |
62 | } |
11 | } |
63 | 12 | ||
64 | UD2_STATUS UD2_WriteStrW(LPWSTR lpDest, DWORD cchDestSize, LPCWSTR lpSrc) { |
13 | UD2_STATUS UD2_WriteStrW(LPWSTR lpDest, DWORD cchDestSize, LPCWSTR lpSrc) { |
65 | if (wcslen(lpSrc) > cchDestSize-1) return UD2_STATUS_ERROR_BUFFER_TOO_SMALL; |
14 | if (wcslen(lpSrc) > cchDestSize-1) return UD2_STATUS_FAILURE_BUFFER_TOO_SMALL; |
66 | wcscpy(lpDest, lpSrc); |
15 | wcscpy(lpDest, lpSrc); |
67 | if (wcslen(lpSrc) == 0) return UD2_STATUS_NOTAVAIL_UNSPECIFIED; |
16 | if (wcslen(lpSrc) == 0) return UD2_STATUS_NOTAVAIL_UNSPECIFIED; |
68 | if (UD2_IsMultilineW(lpSrc)) return UD2_STATUS_OK_MULTILINE; |
17 | if (UD2_IsMultilineW(lpSrc)) return UD2_STATUS_OK_MULTILINE; |
69 | return UD2_STATUS_OK_SINGLELINE; |
18 | return UD2_STATUS_OK_SINGLELINE; |
70 | } |
19 | } |