new to vc++, getting all messages

Oct 18, 2010 at 11:33 PM


Since I'm more of a .Net guy, I never used C++ before, I tried to wrap the pstsdk in a CLI/C++ DLL and use the result of a function in C#. Only when I run my app, it says something about error thrown by external component. When I step through my code, it throws here:

pst store(wpath);

for(pst::folder_iterator iter = store.folder_begin(); iter != store.folder_end(); ++iter) {
					for(folder::message_iterator miter = (*iter).message_begin(); miter != (*iter).message_end(); ++miter) {
						mailList->Add(process_message(*miter)); // Error here

Since I am unfamiliar with pointers and VC++ (.Net 4.0) and just hacked something together, I don't know what's wrong. mailList is a List<EmailMessage> and process_message returns EmailMessage and accepts message&. The execution never arrives at process_message though.


Can somebody give me a hint?

Oct 18, 2010 at 11:46 PM

Hmm, my best guess is that right now it looks like you're comparing iterators from two different folder objects, since folder_iterator is a proxy iterator and a new folder object is created everytime it's deferenced.

Basically, try creating a named folder object inside the first loop before you start the second loop. Call message_begin() and message_end() on that folder object, instead of on (*iter).

Oct 19, 2010 at 8:29 AM

Looks like that was it, thanks.

Oct 24, 2010 at 8:44 PM
Edited Oct 25, 2010 at 1:03 PM

nevermind what was here.


Nov 9, 2010 at 1:33 PM

I downloaded the entry_id patch from github, but I want to convert the vector<pstsdk::byte> to a string. How do I do that?

Nov 9, 2010 at 3:17 PM

Look into Base64 Encoding.

Nov 14, 2010 at 12:04 PM

I have this, to create a (managed) hex string from a vector of bytes:


// EntryID
try {

	std::vector<pstsdk::byte> entry_id = m.get_entry_id();

	ostringstream  s;
	for (int i = 0; i < entry_id.size(); ++i) {
			s << hex << (int)entry_id[i];

	string temp = s.str();

	emsg->Id = gcnew String(temp.c_str());
catch (Exception ^ ex) {
	// can't get EntryID: submessage or subnode?

-first get the vector of bytes
-convert byte to int
-convert int to hex
-add hex to stringstream
-create string of stringstream
-(create a managed string of the string)

Only my entry id is not the same as yours for sample1. I get '00006a552b813c43f94384f18b7da2393e95240200' and in the pstlevel-test patch it says it should be '000000006a552b813c43f94384f18b7da2393e9524002000'. I should double every zero, but how?

Nov 14, 2010 at 4:06 PM

Look at setw(2) as well as the other ostream formatting commands.

Nov 14, 2010 at 9:34 PM

Thanks for pointing in the right direction once again!

s << setfill ('0') << setw (2) << hex << (int)entry_id[i];