Return array of strings

My goal is to make a dll file with a single function that will return the IE url history from the local computer. I found some code at:

http://www.codeguru.com/cpp/i-n/ieprogram/displayinginformation/article.php/c13353/

here that does a little bit more than what I am looking for. The ListURLs method does a bit more than what I want, but I can just comment out the lines that print out stuff I don't want. My problem is that since I am making a dll, I need to return an array of urls, but I can't seem to format url.pwcsUrl into a string so it can be added to an array and returned. Here is the function that contains the method to return an array of strings:

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
static int ListURLs(IUrlHistoryStgPtr stg)
{
	IEnumSTATURL *en = NULL;
	if (stg->EnumUrls(&en) != S_OK)
		return GetLastError();
	STATURL url;
	long i = 0;
	ULONG ures;
	while (en->Next(1, &url, &ures) == S_OK)
	{
		//wprintf(L"%3d: title = \"%s\"\n", i++, url.pwcsTitle);
		wprintf(L"     URL   = \"%s\"\n", url.pwcsUrl); //I want to add all of these into an array and return the array

		/*
		WCHAR lastVisited[DATE_LENGTH];
		TimeToStringW(&url.ftLastVisited, lastVisited, DATE_LENGTH);
		wprintf(L"     Last visited at %s\n", lastVisited);

		WCHAR lastUpdated[DATE_LENGTH];
		TimeToStringW(&url.ftLastUpdated, lastUpdated, DATE_LENGTH);
		wprintf(L"     Last updated at %s\n", lastUpdated);

		WCHAR expires[DATE_LENGTH];
		TimeToStringW(&url.ftExpires, expires, DATE_LENGTH);
		wprintf(L"     Expires      at %s\n", expires);
		*/

		if (!(url.dwFlags & STATURL_QUERYFLAG_NOURL))
			CoTaskMemFree(url.pwcsUrl);
		if (!(url.dwFlags & STATURL_QUERYFLAG_NOTITLE))
			CoTaskMemFree(url.pwcsTitle);
	}
	en->Release();
	//wprintf(L"\n");
	//wprintf(L"Found %d URLs\n", i);
	return 0;
}
*Bump*

Are the data types involved incompatible? If I can't use this, is there any other way to retrieve the history from the local computer and return an array of the results? Sorry for my helplessness, but I have only been using C++ for less than a week.
Try making an array of the URL type and adding the data to it with a for loop instead of a while. You would, however, need to figure out the amount of data you plan to read into it.
I googled up the structures you are manipulating, although I am not personally familiar with them, here is what I found:
1
2
3
4
5
6
7
8
9
typedef struct _STATURL {
    DWORD cbSize;
    LPWSTR pwcsUrl;
    LPWSTR pwcsTitle;
    FILETIME ftLastVisited;
    FILETIME ftLastUpdated;
    FILETIME ftExpires;
    DWORD dwFlags;
} STATURL, *LPSTATURL;

 
typedef wchar_t* LPWSTR, *PWSTR; 


So an array of LPWSTR (wchar_t *) is what you want, correct? For more information about arrays in C, please refer to the tutorial/reference section. If you are using C++, you could try an STL container of wstrings.
Last edited on
OK, I will try to move on from there. Haven't worked with arrays before, but I will try my best and come back with any questions I have.
Topic archived. No new replies allowed.