You Are Here:

Community: Blogs

Paul Todd's Forum Nokia Blog

Some tips on C classes

Paul.Todd | 25 February, 2007 21:51

Here are some reminders about C type classes for a typical question I saw on NewLC

Why does my C class not initialize the members to zero? Is this a bug?

1. Do not create C classes on the stack.
This is the reason the member variables do not get set to zero.

2. C classes allocate dynamic memory.
This will result in leaks if any of the methods following leave.

3. C classes almost always do two phase construction.
This is where the resources are allocated and at this point can leak if the object is not on the cleanup stack

4. R classes allocate handles.
- These handles may be leaked if any of the methods following the Open method leave.
Be very careful if you open a handle and do not put it on the cleanup stack!
People put returns in the middle of the function and forget to handle functions that leave.

5. Programming standards in Symbian are paramount.
-If the class allocates memory, derive it from CBase and put it on the cleanup stack.
-If it is using handles, use an R class and put it on the cleanup stack
See the Symbian Wiki for more information on standards

6. Follow Scott Meyers advice and make your constructors and ConstructL class private.
-So that the class cannot be inadvertantly created on the stack.
-Make you copy constructor and assignment operator private and unimplemented so you get compile errors if you accidentally use them.
-Always use NewLC or NewLC to force people to use the proper constructor
Effective C++: 50 Specific Ways to Improve your Programs and Design

7. Put the address of the item you expect to be at the top of the stack in the argument for PopAndDestroy
There are overloads on PopAndDestroy that allow you to provide a pointer for the item you expect to be on the top of the stack after popping and destroying items.
You will get a panic if this item is not at the top of the stack after the items have been popped.

Send a file bluetooth

Paul.Todd | 16 February, 2007 10:37

A number of people seem to have a problem using RSendAs to send a file via Bluetooth but its more or less the same as sending any other message.

To start,  you need to get hold of the bluetooth MTM UID, its in "SendUiConsts.h"

Then its simply a case of:

  1. Opening the SendAs session
  2. Creating a message using the session
  3. Adding the file as an attachment
  4. Sending the message

void SendFileL(const TDesC& aFilename)
    {
   // 1. Open session
   RSendAs session;
   User::LeaveIfError(session.Connect());
   CleanupClosePushL(session);

   // 2. Create message
   RSendAsMessage message;
   message.CreateL(session, KSenduiMtmBtUid);
   CleanupClosePushL(message);

    // 3. Add attachment
    TRequestStatus status;
    message.AddAttachment(aFilename.FullName(), status);
    User::WaitForRequest(status);

    // 4. Send message
    if (status.Int() == KErrNone)
        {  
        CleanupStack::Pop(&message);
        message.LaunchEditorAndCloseL();
        }
   else
       CleanupStack::PopAndDestroy(&message); 

   CleanupStack::PopAndDestroy(&session);
}

 

 
 

Rate This

 
 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia