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
|
/*
* GETICON.CPP
*
* Functions to create DVASPECT_ICON metafile from filename or classname.
*
* OleMetafilePictFromIconAndLabel
*
* (c) Copyright Microsoft Corp. 1992-1993 All Rights Reserved
*/
/*******
*
* ICON (DVASPECT_ICON) METAFILE FORMAT:
*
* The metafile generated with OleMetafilePictFromIconAndLabel contains
* the following records which are used by the functions in DRAWICON.CPP
* to draw the icon with and without the label and to extract the icon,
* label, and icon source/index.
*
* SetWindowOrg
* SetWindowExt
* DrawIcon:
* Inserts records of DIBBITBLT or DIBSTRETCHBLT, once for the
* AND mask, one for the image bits.
* Escape with the comment "IconOnly"
* This indicates where to stop record enumeration to draw only
* the icon.
* SetTextColor
* SetTextAlign
* SetBkColor
* CreateFont
* SelectObject on the font.
* ExtTextOut
* One or more ExtTextOuts occur if the label is wrapped. The
* text in these records is used to extract the label.
* SelectObject on the old font.
* DeleteObject on the font.
* Escape with a comment that contains the path to the icon source.
* Escape with a comment that is the ASCII of the icon index.
*
*******/
#include "precomp.h"
#include "common.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <commdlg.h>
#include <memory.h>
#include <cderr.h>
#include "utility.h"
OLEDBGDATA
static const TCHAR szSeparators[] = TEXT(" \t\\/!:");
#define IS_SEPARATOR(c) ( (c) == ' ' || (c) == '\\' \
|| (c) == '/' || (c) == '\t' \
|| (c) == '!' || (c) == ':')
#define IS_FILENAME_DELIM(c) ( (c) == '\\' || (c) == '/' || (c) == ':' )
#define IS_SPACE(c) ( (c) == ' ' || (c) == '\t' || (c) == '\n' )
/*
* GetAssociatedExecutable
*
* Purpose: Finds the executable associated with the provided extension
*
* Parameters:
* lpszExtension LPSTR points to the extension we're trying to find
* an exe for. Does **NO** validation.
*
* lpszExecutable LPSTR points to where the exe name will be returned.
* No validation here either - pass in 128 char buffer.
*
* Return:
* BOOL TRUE if we found an exe, FALSE if we didn't.
*
*/
BOOL FAR PASCAL GetAssociatedExecutable(LPTSTR lpszExtension, LPTSTR lpszExecutable)
{
HKEY hKey;
LRESULT lRet = RegOpenKey(HKEY_CLASSES_ROOT, NULL, &hKey);
if (ERROR_SUCCESS != lRet)
return FALSE;
LONG dw = MAX_PATH_SIZE;
TCHAR szValue[OLEUI_CCHKEYMAX];
lRet = RegQueryValue(hKey, lpszExtension, szValue, &dw); //ProgId
if (ERROR_SUCCESS != lRet)
{
RegCloseKey(hKey);
return FALSE;
}
// szValue now has ProgID
TCHAR szKey[OLEUI_CCHKEYMAX];
lstrcpy(szKey, szValue);
lstrcat(szKey, TEXT("\\Shell\\Open\\Command"));
dw = MAX_PATH_SIZE;
lRet = RegQueryValue(hKey, szKey, szValue, &dw);
if (ERROR_SUCCESS != lRet)
{
RegCloseKey(hKey);
return FALSE;
}
// szValue now has an executable name in it. Let's null-terminate
// at the first post-executable space (so we don't have cmd line
// args.
LPTSTR lpszTemp = szValue;
while ('\0' != *lpszTemp && IS_SPACE(*lpszTemp))
lpszTemp = CharNext(lpszTemp); // Strip off leading spaces
LPTSTR lpszExe = lpszTemp;
while ('\0' != *lpszTemp && !IS_SPACE(*lpszTemp))
lpszTemp = CharNext(lpszTemp); // Step through exe name
*lpszTemp = '\0'; // null terminate at first space (or at end).
lstrcpy(lpszExecutable, lpszExe);
return TRUE;
}
/*
* PointerToNthField
*
* Purpose:
* Returns a pointer to the beginning of the nth field.
* Assumes null-terminated string.
*
* Parameters:
* lpszString string to parse
* nField field to return starting index of.
* chDelimiter char that delimits fields
*
* Return Value:
* LPSTR pointer to beginning of nField field.
* NOTE: If the null terminator is found
* Before we find the Nth field, then
* we return a pointer to the null terminator -
* calling app should be sure to check for
* this case.
*
*/
LPTSTR FAR PASCAL PointerToNthField(LPTSTR lpszString, int nField, TCHAR chDelimiter)
{
if (1 == nField)
return lpszString;
int cFieldFound = 1;
LPTSTR lpField = lpszString;
while (*lpField != '\0')
{
if (*lpField++ == chDelimiter)
{
cFieldFound++;
if (nField == cFieldFound)
return lpField;
}
}
return lpField;
}
|