Random images with Gdi+

I am attempting to read a random image out of a directory using gdi+. I am attempting to do it by building a vector of all the files in the directory, then choose a random item out of that vector and use that to read the image. I can build the list of the files, using a while loop with push_back. This gives a vector of strings. However the Image class of gdi+ does not accept strings, only wchar*.

I will spare you the entirety of the code, as it is a bit of a mess at the moment, but here is the relevant parts.

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
#include <windows.h>
#include <string>
#include <vector>
#include <dirent.h>
#include <gdiplus.h>
#include <iostream>



        vector<string>	dirlist;
	DIR				*d;
	struct			dirent *dir;
	int i =0;
	d=opendir(".");
	if (d)
	{
		while ((dir=readdir(d)) != NULL)
		{
			i++;
			dirlist.push_back(dir->d_name);
//			cout << dirlist[i-1] << endl;
		}
		closedir(d);
	}



        Image	image(L"photo.jpg");   // obviously this needs to be changed, I just haven't done it yet.


I attempted to convert the string into a wstring, and then use .c_str() to convert it into wchar, but I am recieving errors relating to differing levels of indirection. I am wondering if there is a different way of doing it, that doesn't involve converting from string to wchar? Or a different way all together. I'm trying to keep the program as small as possible, so I would prefer to not use Boost. I am currently using dirent.h.

BTW I am working on a windows system.
Topic archived. No new replies allowed.