|
Writing your iostream class is not hard, but it's not trivial either. Basically you have to make CPrinter derive from std::ostream and provide a special std::streambuf class:
class CPrinter: public std::ostream
{
typedef std::ostream super;
CPrinterStreambuf sbuf;
public:
CPrinter():super(&buf){}
...
}; Now, std::ostream handles all the IO via the provided CPrinterStreambuf object, which derives from the virtual base class std::streambuf . Depending on where you want the bytes to be sent, you might consider writing CPrinterStreambuf from scratch or deriving from say std::filebuf or std::stringbuf . Now you can intercept outgoing data by overriding overflow and sync . Here[^] is an example provided by MS that might be useful.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
|
hello
i create a vector where i store the random number but when i compile it use only the last couple of number that had generated by random.
where is the problem ,is that the vector don't work or it don't store the firsts numbers or it's me who don't well use the vector?????
void foufou::CreateCharacter(int amount) <br />
{ <br />
int randomX =0,randomY =0,randomZ =0; <br />
<br />
foufou *PtrCreat; <br />
<br />
for(int i=0;i<amount;i++) <br />
{ <br />
PtrCreat = new foufou();
VectorOfCharacter.push_back(PtrCreat); <br />
<br />
initPosX = ( ( 1 + rand( ) % 120) - 70 ); <br />
initPosY = ( ( 1 + rand( ) % 120 ) - 70 ); <br />
<br />
<br />
<br />
<br />
NumCharacter++; <br />
} <br />
<br />
} <br />
<br />
<br />
<br />
<br />
<br />
void foufou:rawCharacterOnInitSimulation() <br />
{ <br />
<br />
for(int i=0 ;i<VectorOfCharacter.size() ;i++) <br />
{ <br />
<br />
DrawCreatedCharacter(VectorOfCharacter[i]->initPosX, VectorOfCharacter[i]->initPosY); <br />
<br />
} <br />
<br />
<br />
<br />
} <br />
<br />
|
|
|
|
|
If I understand your code, the line
initPosX = ( ( 1 + rand( ) % 120) - 70 ); should be
PtrCreat->initPosX = ( ( 1 + rand( ) % 120) - 70 ); (and the same for the next line).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
i have a listview with LVS_EX_FULLROWSELECT style.I use AddItem to add an icon into the view.When i run the app,everything appears to be good.However,when i click the row to select it,the texts in the row are highlighted but icons DISAPPEARED!I tried several other ways (InsertItem or SendMessage),but these made no difference.I wonder if there is any possibility to insert icons to a listview?!
BTW:i want icons inserted in both headers and items,but the background colors of them are different,but one ImageList can have only one bkcolor(maybe more,i'm not sure).so is there any solution to this problem?
modified 1-May-21 21:01pm.
|
|
|
|
|
I used ATL create a Dll project,
I want get current DLL directory, I used ::GetCurrentDirectory() API,
but I only get the EXE 's current path.
I want get Dll's directory
what can I do ?
I believe I can touch the sky
|
|
|
|
|
GetModuleFileName will return the full path of the module you specify. If you give it NULL for the hInstance, then it will return the path of the main executable.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thanks you get me this help
I used GetModuleFileName() by your's suggest.
It's good
I believe I can touch the sky
|
|
|
|
|
|
I know CFileDialog class is MFC Class,
But I want used this class in WTL project.
I include afxdlgs.h at my project but is error
"WINDOWS.H already included. MFC apps must not #include <windows.h>"
I want know have similar calss in WTL ?
I believe I can touch the sky
|
|
|
|
|
I haved find similar class - CFileDialog in atldlgs.h
Thanks myself;P
I believe I can touch the sky
|
|
|
|
|
Hey,
I am trying to use CString in my ATL IE Toolbar. I had some compiler errors and then read an article that said I had to include atlstr.h. I have VC 6.0 but cannot find atlstr.h, can anyone show me where I can get it or send it to me?
Thanks in advance.
|
|
|
|
|
Upgrade to VC7. It isn't available in VC6.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
|
Michael Dunn wrote:
VC 7 has a shared CString class between ATL and MFC. Since you're using 6, you should use WTL, which has its own CString.
How do I use WTL when its programmed in ATL? Or are they almost the same? Sorry, I don't really know much about either of the languages.
|
|
|
|
|
|
Hey Guys,
I'm trying to port a plain WIN32 dll over to another system which uses ATL to implement the interface. I know nothing about ATL but I've sort of got it working aside from the fact I can't figure out how to get the HINSTANCE of my DLL.
The DLLmain does the following
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_My_Plugin, CMyPlugin)
END_OBJECT_MAP()
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID )
{
if (dwReason == DLL_PROCESS_ATTACH)
{
_Module.Init(ObjectMap, hInstance);
DisableThreadLibraryCalls(hInstance);
}
else if (dwReason == DLL_PROCESS_DETACH)
_Module.Term();
return TRUE;
}
I can see the _Module gets the HINSTANCE here but how do I get to it from the CMyPlugin class?
Cheers
James
|
|
|
|
|
_Module.GetModuleInstance();)
|
|
|
|
|
Thanks. Didn't realise it was that straightforward.
Cheers
James
|
|
|
|
|
I found a solution to build myDLL, using yourDLL, with /FORCE:MULTIPLE only...hope you got the problem...it was something like /Gw option but I dont have yourDLL code thats why I could this /FORCE:MULTIPLE only.
It kills me every time when I build it by saying" image may not run"
Is there any other solution to this?
part-2------------------------------------------------------------------------
In trying to use yourDLL in myDLL. I've declared it as private member and Initialized it one function, first function. It works fine here. When I call this existing object from second function, it says "cant read the memory". Of Course a test-client calls myDLL to raise these errors otherwise myDLL builds OK.
I'm always wrong....whats appropriate way?
thanx to HELPERS!
I'll pray for YOU!
Swimming in a fish bowl.
|
|
|
|
|
What is the best way to define a map of string to CComPtr<iunknown> using MFC's CMap?
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
I'm trying to use a bitset that would be the key for a map.
Something like map< bitset<100>, CMyClass * >
The problem with that the bitset is not LessThan Comparable.
And I have no idea about how to compare two bitsets. I cannot convert to ulong since it is 100 bits! Anybody has already implemented a comparison operator for bitsets?
Help greatly appreciated!
|
|
|
|
|
The following is not the most efficient way, but it should work (not compiled it, expect typos):
template<size N>
int compare(const std::bitset<N>& x,const std::bitset<N>& y)
{
for(size_t s=N;s--;){
if(x[s]){
if(!y[s])return 1;
}
else{
if(y[s])return -1;
}
}
return 0;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, that looks good.
In the mean time, I found the Boost C++ library on http://www.boost.org/ which implements a dynamic_bitset class which supports the lessThan comparison.
They use a method that is close to your sample except that they work on a higher lever (unsigned longs?), not bits which is certainly faster (about 32 times faster ).
I'm not keen about using the whole lib just for this class, so I will try to dig in the STL source code in order to implement something similar.
Thanks for the idea.
|
|
|
|
|
Ok. In the Visual C++ version of STL, there is a undocumented public direct access on the "unsigned longs" that compose the actual bitfield of bitset.
That is the _W(_I) function which we can use to compare two bitset. Here is the struct that compares two bitset. Not fully tested yet but that gives an idea.
template<size_t _n=""> struct LessThanBitset
{
bool operator()(const std::bitset<_N>& bs1, const std::bitset<_N>& bs2) const
{
typedef unsigned long _Ty;
enum
{
_Nb = CHAR_BIT * sizeof (_Ty),
_Nw = _N == 0 ? 0 : (_N - 1) / _Nb
};
// Since we are storing the most significant bit
// at pos == size() - 1, we need to do the memcmp in reverse.
// Compare a block at a time
for (int _I = _Nw; 0<_I ; --_I)
if (bs1._W(_I) < bs2._W(_I)) return true;
else if (bs1._W(_I) > bs2._W(_I)) return false;
return (bs1._W(0) < bs2._W(0));
}
};
|
|
|
|