COM Component Development Practice (d)---from C + + to COM:P Art 1

Source: Internet
Author: User
Tags definition contains table name

One, C + + customers reuse C + + objects

Suppose you already have a class that you can reuse, we can reuse it in our own program, just add its definition and implementation file to our own project, and include this type of definition file in the file that uses it, which is our most common method of C + + standard reuse. On my own, I encountered the better control code on CodeProject, so I used it directly to my project.

Here's the first code example of my series, and in the next few articles, the code will continue to improve from C + + to COM.

A brief introduction to the C + + object We want to reuse is a simple database-like object that manages the data in memory, which contains an array of pointers to all the tables in the database, which is actually an array of strings, each representing a row of the table. In addition, this class contains an array of table names for the data table.

DBSRV.h file:

typedef long hresult;//simulate HRESULT in COM
Memory Database Classes
Class CDB
{
Interfaces
Public
Interface for data access
HRESULT Read (short ntable, short nrow, LPTSTR lpszdata)/Read data, ntable specify data table, nrow specify data row
HRESULT Write (short ntable, short nrow, LPCTSTR lpszdata)/write data, ntable specify data table, nrow specify data rows
Interface for database management
HRESULT Creation (short &ntable, LPCTSTR lpszname);//create datasheet with table named Lpszname
HRESULT Delete (short ntable);//Delete datasheet
Interface for database information
HRESULT getnumtables (short &nnumtables);//Get Data table count
HRESULT Gettablename (short ntable, LPTSTR lpszname);//get the specified datasheet table name, ntable as the data table index number
HRESULT getnumrows (short ntable, short &nrows); Gets the number of data rows for the specified data table, ntable to the data table index number, and nrows the number of rows returned
Implementation
Private
CPtrArray M_arrtables; An array of pointers to all tables in the database
CStringArray M_arrnames; Array of data table names
Public
~CDB ();
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.