Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ Wrapper Object??

Status
Not open for further replies.

JasonDBurke

Programmer
Jun 20, 2001
54
US
Ok,
Correct me if i wrong ( and its a strong to quite strong possibility that I am) ... is this an example of a C++ Wrapper Object???? If it isn't please give me an example..

MyClass *MyObject = new MyClass;

somethinghere = MyObject->field1;

so on and so forth...
Thanx,
Jason
 
Wrapper is a little else than it. When you do OOP in C you use HANDLE which are pointers to classes.
For example in WinAPI you have class object window. It has an identification name "xxx". You create in WinAPI such function for creating an object:
hWnd = CreateWindow("xxx",.......);
and use hWnd functions:
ShowWindow(hWnd.....);
abc(hWnd...);//hWnd in C is something as pointer this in C++
You want to make a wrapper in C++
class CWindow
{
HWND hWnd;
char* name;
public:
CWindow(){.....}
CWindow(char* name){}
SetName(){}//....
hWnd Create(){}
int Show(int x){return ShowWindow(hWnd,x);///implementations}
};

and you use
CWindow x;
x.SetPos(...)
x.Show(SW_SHOW);//as you see you hide the HWND handle

so you have a much better control of types, for example you can't assign a HWND instead of a HDC. You avoid many errors what are +- difficult to find. Also you put in the destructor the code for closing/destructing the opbject.
for example, when you use a HDC you have to get it and after use to release it. Put the releasing in the destructor, and forget about ReleaseDC. Many programmers forgets ofthen to Release/Close/Free and in C programs appears too many errors because of it. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top