login about faq

The LoadTaskResult() method of the CkEmailBundle class is throwing an access violation exception. Any ideas why an access violation exception is being thrown?

The following code sample works fine:

mailman.put_MailHost(Pop3HostName.c_str());
mailman.put_PopUsername(Pop3UserName.c_str());
mailman.put_PopPassword(Pop3Password.c_str());

CkEmailBundle *bundle = 0;
bundle = mailman.CopyMail();

The following code sample throws an Access Violation Exception

mailman.put_MailHost(Pop3HostName.c_str());
mailman.put_PopUsername(Pop3UserName.c_str());
mailman.put_PopPassword(Pop3Password.c_str());

//  Call the async version of the CopyMail method to return a task object.
//  The task object is loaded, but is in the Inert state -- meaning it is
//  not yet scheduled to run on Chilkat's background thread pool.
CkTask *task = mailman.CopyMailAsync();
if (task == 0) 
{
    cout << mailman.lastErrorText() << "\r\n";
    return (1);
}

//  Schedule the task for running on the thread pool.  This changes the task's state
//  from Inert to Live.
bool success = task->Run();
if (success != true)
{
    std::cout << task->lastErrorText() << endl;
    delete task;
    return (1);
}

int curPctDone = 0;
int sleep_cnt = 0;
while (task->get_Finished() != true && sleep_cnt<120)
{
    if (task->get_PercentDone() != curPctDone) {
        curPctDone = task->get_PercentDone();
        std::cout << curPctDone << " percent done" << "\r\n";
    }
    //  Sleep 1000 ms.
    task->SleepMs(1000);
    sleep_cnt++;
}

if (task->get_StatusInt() != 7)
{
    std::cout << "Task did not complete." << "\r\n";
    std::cout << "task status: " << task->status() << "\r\n";
    delete task;
    return (1);
}

CkEmailBundle *bundle = 0;
success = bundle->LoadTaskResult(*task);

asked Aug 08 at 18:37

dwilliEAM's gravatar image

dwilliEAM
31


Look at these two lines of code carefully and let me know if you see the problem:

    CkEmailBundle *bundle = 0;
    success = bundle->LoadTaskResult(*task);
link

answered Aug 08 at 18:40

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Thanks. Went back and looked at the method specification. I blindly copied the example code for running asynchronous tasks and didn't pay attention to what I had written.

(Aug 08 at 18:53) dwilliEAM

Thanks! That's what I guessed -- copy & paste errors get me too!

(Aug 08 at 18:57) chilkat ♦♦

Figured out the bug. Needed to allocate space for the CkEmailBundle object.

link

answered Aug 08 at 18:49

dwilliEAM's gravatar image

dwilliEAM
31

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×184
×10

Asked: Aug 08 at 18:37

Seen: 146 times

Last updated: Aug 08 at 18:57

powered by OSQA