Skip to Content
Programming Visual Basic for the Palm OS
book

Programming Visual Basic for the Palm OS

by Matt Holmes, Patrick Burton, Roger Knoell
April 2002
Intermediate to advanced
440 pages
12h 37m
English
O'Reilly Media, Inc.
Content preview from Programming Visual Basic for the Palm OS

Windows Component Implementation

We now have stub code for the TagParse component. In this section, we show how to fill in the method stubs and compile this code into a Windows DLL. Add the output files listed earlier in Table 9-9 to the ParseServer project.

Tip

It is a good idea to verify that the stub component successfully compiles before proceeding.

Smart Pointer

We use the IPtr smart pointer interface template in the implementation of the CTagParse class and ITagParse interface.[64] A smart pointer automatically releases the interface to which it points when it goes out of scope. This alleviates some of the messy code that can accompany COM programming when an error occurs in the middle of a method, and existing interfaces need to be released before returning.

For example, in the code below, if bSuccess is set to false, we need to make sure and call Release on pMyString before returning. Otherwise, we will have a memory leak.

HRESULT MyMethod(  )
{
   IString* pMyString;
   pCoCreateString(L"MyString", &pMyString);
   bool bSuccess = true;
   //...Processing ...
   if(bSuccess == false)
   {
      pMyString->Release(  );
      return E_FAIL;
   }
   return S_OK;
}

Contrast this approach with using a smart pointer.

HRESULT MyMethod(  )
{
   IPtr<IString, &IID_IString> spMyString;
   pCoCreateString(L"MyString", &spMyString);
   bool bSuccess = true;
   //...Processing ...
   if(bSuccess == false)
      return E_FAIL;
   return S_OK;
}

Here, we can simply return E_FAIL. The smart pointer automatically calls Release on its interface when it ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Palm OS Programming, 2nd Edition

Palm OS Programming, 2nd Edition

Julie McKeehan, Neil Rhodes
Learning C# 2005, 2nd Edition

Learning C# 2005, 2nd Edition

Jesse Liberty, Brian MacDonald

Publisher Resources

ISBN: 0596002009Catalog PageErrata