|
So, can i take that, the class that encapsulates Win32 api in it is the only type of class that we can call a wrapper class...so if i derive a class that enhances the existing classes then it cannot be called as a wrapper class...!
is it true.....?
Thanks for ur interest
|
|
|
|
|
I don't know about that, but certainly if class B derives from class A, I would not call class B a wrapper class, no.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
|
|
|
|
|
As I understand it, a "wrapper" class is simply a way to put a new front-end on a piece of code. I have never seen a formal definition of it, so you can call it CB a wrapper if you really want.
A common situation is where a set of C functions (like the GDI example above) is wrapped by a very simple C++ class. Like a "wrapper" in real life, a wrapper class generally adds very little functionality to what it wraps (maybe some cleanup in the destructor, etc.). It's really just a grouping or packaging.
-c
Garbage collection, making life better - for weenies!
|
|
|
|
|
You could name your example class as a "wrapper", but strictly speaking this is not what wrapper usually refers to in the design patterns literature. A wrapper (aka adaptor) is a class that conforms to a given interface using the services of another, non-related class that actually does the stuff. Here's an example. Consider the following interface (or abstract class in C++ terminlogy):
class stream
{
virtual void write(const char* data,size_t len)=0;
virtual size_t read(char * data,size_t len)=0;
}; Now suppose we got the following class for handling sockets:
class TCPsocket
{
void send(const char* data,size_t len);
void recv(const char* data,size_t len,size_t * read);
} You can see TCPsocket gives essentially the functionality required by stream , but the methods simply don't match. The following wrapper make the adjustments:
class TCPsocket_wrapper:public stream, private TCPsocket
{
void write(const char* data,size_t len)
{
send(data,len);
}
size_t read(char * data,size_t len)
{
size_t read;
recv(data,len,&read);
return read;
}
} The complexity of the adaptation could range from a simple forwarding to more elaborate rearrangements ot the arguments passed.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Dear Mr. lopez,
Thank you for your lucid description.
However, I have one small nagging issue that I need to sort out. I had defined the class CB to inherit from CA. (please refer the first link) In Cb I have mapped my send and write statements much like yours. I want to know if it is mandatory for a wrapper class, to inherit its interface from a abstract base class.
If you want a helping hand, you'll find one at the edof your arm.
|
|
|
|
|
Well, this is just terminology. Actually, you can call a wrapper to whatever it seems a warpper to you. But if we stay within the limits of what this idiom is defined to be in the patterns literature, then a wrapper must inherit the abstract class it adapts the preexisting object to. The key idea behind wrappers is that they allow third party components (the wrapees) to be used in another environment (that defines the interface.) If you don't derive from an abstratc class (or implement an interface in Java), then your adatation can still be used but only as an isolated component, not within a more general framework dealing with multiple implementations of the same functionality.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I've a question about this example: It opens excel and inserts an eventsink to catch the events inside excel.
HOWTO: Catch Microsoft Excel Application Events Using VC++ Q186427
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q186427
I've tried this example using an MFC-EXE, and all works fine. When you press start, the excel application shows up. Clicking with the mouse results in a event messagebox.
But, if you want to include this functionality inside an MFC-DLL, it will not work. Excel shows up alright, but when you click something or press a button, the excel application will block. After a while a messagebox shows up saying: "Microsoft Excel is waiting for another application to complete an OLE action."
Short: using a .exe works fine, but the .dll blocks.
Why?
What's the difference here? (I've used MFC in both cases)
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
I may not be correct but just a guess here..
There is nothing to do with EXE or DLL But with SINK_ENTRY macro's
Microsoft accepts Event Sinking implementation (DispEventImpl) has bugs in ATL and MFC.
And i saw this hanging problem when the signature of the function varied. Just check automation parameters across the basic and supported native types.
For Ex:
SINK_ENTRY(1, OnButtonClick)
try
OnButtonClick(_bstr_t bstrparam1, _variant_t vtParam2)
vis-versa
OnButtonClick(BSTR bstrparam1, VARIANT vtParam2)
This should not be an issue if "raw_interfaces_only" is used with #import.
Thanks,
Ramu
|
|
|
|
|
mmm...
you are right, it has nothing to do with the exe-dll thing.
I'm pretty shure it's a thread problem.
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
I write those code :
...
#include <map>
using namespace std;
map<int,int> aMap;
...
many compile warnings occur: all of warnings are same. ( c4786 )
warning C4786: '?rbegin@?$_Tree@HU?$pair@HH@std@@U_Kfn@?$map@HHU?$less@H@std@@V?$allocator@H@2@@2@U?$less@H@2@V?$allocator@H@2@@std@@QAE?AV?$reverse_bidirectional_iterator@Viterator@?$_Tree@HU?$pair@HH@st
d@@U_Kfn@?$map@HHU?$less@H@std@@V?$allocator@H@2@@2@U?$less@H@2@V?$allocator@H@2@@std@@U?$pair@HH@3@AAU43@PAU43@H@2@XZ' : identifier was truncated to '255' characters in the browser information
What can I do ? I use VC++ compile the code? thanks
|
|
|
|
|
The warning is quite silly. Either ignore it, or add a
#pragma warning(disable:4786)
before you use any parts of the map class.
|
|
|
|
|
|
Two solutions come to mind:
1- Put a pragma to disable the warning
2- switch to next version of VC++
Daniel
|
|
|
|
|
|
Hi
I am having trouble trying to derive one class from a template class.
I keep getting the following error when I try to derive the class CFlashText from the class CFlash.
error C2059: syntax error : ','
My code code looks like this:
Header file:
class CFlashText : public CText, public CFlash< CFlashText >
{
public:
CFlashText();
virtual ~CFlashText();
};
cpp file:
CFlashText::CFlashText()
: CText, CFlash< CFlashText > //<-- it is in this line the compiler gives me the error
{
}
CFlashText::~CFlashText()
{
}
Does anyone know why this error appears?
Klaus Petersen
|
|
|
|
|
cpp file:
CFlashText::CFlashText(): CText, CFlash< CFlashText >
{
}
Why are u doing this?
Why not just use the second constructor?? Any const members?
Papa
Murex Co.
|
|
|
|
|
CFlashText is an text object that has the ability to flash an object.
It gets the flash specific methods from CFlash and the text specific methods from CText.
CFlash flashes an object by calling draw and erase methods in the object it is flashing (here CText).
To do this it needs to know the type of the object it is flashing.
To make CFlash useable on other objects than CText I want to implement CFlash as a template.
Hereby giving it the ability to flash another object if desired.
|
|
|
|
|
You'll need : CText(), CFlash<CFlashText>()
|
|
|
|
|
Wups I forgot the () after the constructors
Thank you for helping me out.
The program compiles now
The only problem is that now it shows a linker error.
Linker errors:
FlashText.obj : error LNK2001: unresolved external symbol "public: __thiscall CFlash<class cflashtext="">::CFlash<class cflashtext="">(void)" (??0?$CFlash@VCFlashText@@@@QAE@XZ)
FlashText.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CFlash<class cflashtext="">::~CFlash<class cflashtext="">(void)" (??1?$CFlash@VCFlashText@@@@UAE@XZ)
|
|
|
|
|
Klaus Petersen wrote:
FlashText.obj : error LNK2001: unresolved external symbol "public: __thiscall CFlash::CFlash(void)" (??0?$CFlash@VCFlashText@@@@QAE@XZ)
FlashText.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CFlash:CFlash(void)" (??1?$CFlash@VCFlashText@@@@UAE@XZ)
tells you there are no implementations for the constructor and destructor of CFlash. If you explicitly declare them, you'll need to implement them aswell (with at least empty {}).
|
|
|
|
|
The implementation is done in the cpp file, as usual. It doesn't seem to work but I can't see there
is anything wrong with the code. My code looks like this:
header file:
#if !defined(AFX_FLASHTEXT_H__50B175B8_B909_4161_BDB7_B4960ECF9B0E__INCLUDED_)
#define AFX_FLASHTEXT_H__50B175B8_B909_4161_BDB7_B4960ECF9B0E__INCLUDED_
#include "Text.h"
#include "Flash.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CFlashText : public CText, public CFlash< CFlashText >
{
public:
CFlashText();
virtual ~CFlashText();
};
#endif // !defined(AFX_FLASHTEXT_H__50B175B8_B909_4161_BDB7_B4960ECF9B0E__INCLUDED_)
cpp file //implementation
#include "stdafx.h"
#include "FlashText.h"
CFlashText::CFlashText()
: CText(), CFlash< CFlashText >()
{
}
CFlashText::~CFlashText()
{
}
does anyone know why this code doesn't work???
The linker gives the following linker error on the code:
FlashText.obj : error LNK2001: unresolved external symbol "public: __thiscall CFlash<class cflashtext="">::CFlash<class cflashtext="">(void)" (??0?$CFlash@VCFlashText@@@@QAE@XZ)
FlashText.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CFlash<class cflashtext="">::~CFlash<class cflashtext="">(void)" (??1?$CFlash@VCFlashText@@@@UAE@XZ)
|
|
|
|
|
hmmm....I don't know if there is anything wrong with what you are trying to do. My only thought would be that the CFlash<cflashtext> is relying on the constructor of CFlash and for some reason, it is not accpeting that. FYI, this is how we do it.
template <class type="">
class foo_template
{
};
class foo
{
};
class foo2 : public foo_template<foo>
{
};
|
|
|
|
|
It's not CFlashText that is the problem, it's CFlash that is missing its constructor and destructor, just as the linker messages states. You will need CFlash::CFlash() {} and CFlash:: ~CFlash() {} somewhere.
|
|
|
|
|
Hi,
I only want to know who have a VC++ version of the software
named CDex ? or some same experience? I have some problems for compiling it with VC6.0 at windows2000.
Thanks in advance!
chen
|
|
|
|
|
Hi,
I've to impement idle time out to my dialog application. can anyone give me an idea abt how to go on abt it. I don't want to go on and handle every event.
thanks in advance
|
|
|
|