Need help to identify error

Jul 9, 2010 at 2:14 PM

Hi,

I wrote a simple program to read pst using sdk as:

// pst_sdk_8_4.43.cpp : Defines the entry point for the console application.//

#include <iostream>

#include <iomanip>

#include <string>

#include <vector>

#include "stdafx.h"

#include "pst.h"

using namespace std;

using namespace pstsdk;

pstsdk::pst sample(L"submessage.pst");

void Ado_stuff(attachment& attach);

void Mdo_stuff(message& m);

void do_stuff(folder& fold);

class E {

public:

const char* error;

E(

const char* arg) : error(arg) { }

};

void Mdo_stuff(message& m){

try

{

wstring subject = m.get_subject();

wstring body = m.get_body();

wstring htmlbody = m.get_html_body();

prop_stream bodystream(m.open_body_stream());

prop_stream htmlbodystream(m.open_html_body_stream());

size_t num_attachments = m.get_attachment_count();

size_t num_recipients = m.get_recipient_count();

std::wcout << L"subject[" << subject<< L']' << std::endl;

std::wcout << L"body[" << body<< L']' << std::endl;

if(m.get_attachment_count()> 0){

for(message::attachment_iterator iter = m.attachment_begin(); iter != m.attachment_end(); ++iter){

Ado_stuff(*iter);

// *iter is an attachment on this message}

}

}

catch (E& e) {

cout << e.error << endl;

}

}

void Ado_stuff(attachment& attach){

try

{

wstring filename = attach.get_filename();

std::wcout << L"attachment_name[" << filename<< L']' << std::endl;vector<byte> content = attach.get_bytes();

prop_stream content_stream(attach.open_byte_stream());

std::wstring wfilename = attach.get_filename();

std::string filename1(wfilename.begin(), wfilename.end());

ofstream newfile(filename.c_str(), ios::out | ios::binary);

newfile << attach;

if(attach.is_message()){

message m = attach.open_as_message();

// throws bad_cast if is_message() == falseMdo_stuff(m);

}

}

catch (E& e) {

cout << e.error << endl;

}

}

void

do_stuff(folder& fold){

try

{

std::wcout << L

"folder[" << fold.get_name()<< L']' << std::endl;

for(folder::message_iterator iter = fold.message_begin(); iter != fold.message_end();iter++){

Mdo_stuff(*iter);

// *iter is a message in this folder}

}

catch (E& e){

cout << e.error << endl;

}

}

int

main(int argc, _TCHAR* argv[]){

try

{

/*folder fold = sample.open_root_folder();*/

for(pst::folder_iterator iter = sample.folder_begin(); iter != sample.folder_end();++iter){

do_stuff(*iter);

}

cin.get();

return 0;}

catch (E& e){

cout << e.error << endl;

}

}

 

when i run this it breaks and gives the error "Unhandled exception at 0x7c812afb in pst_sdk_8_4.43.exe: Microsoft C++ exception: pstsdk::key_not_found<unsigned short> at memory location 0x0012eaf0.." which points to file btree.h

when i click continue then the output is same as expected,no problem with it.I am unable to identify why this break is coming and how to remove it.Any help regarding this woud be thankful.

**I am using visual studio2008 and boost 42 and pstsdk's latest version for the project

 

Coordinator
Jul 9, 2010 at 5:55 PM

key_not_found is thrown whenever you try to lookup a property which doesn't exist on the item. For example, calling get_html_body() on a message object could throw this exception if the message doesn't have an HTML body.

Visual Studio should give you a callstack of where the exception is being thrown (specifically, what call).