|
Or if the XP machine is connected via LAN then try Remote Debugging - this works GREAT!
Gero
|
|
|
|
|
I have found that when I try to create a dialog to manage a thread, it fails to create. I am passing the same parameters to Create() as I found in the sample program from Microsoft so this part should be correct. I can only figure that there is some memory problem which I can't find or since the program was originally written on Win2K, it doesn't like the way it is being compiled on WinXP. The dialog boxes haven't changed since they were compiled on Win2K. The Win2K compiled program won't run on XP either. Any ideas?
dinger
|
|
|
|
|
Bit my bit I'm trying to make more use of STL, but it is a painfull process at times.
The following code is text book stuff, but I can't get it to compile. In particular I would like to call class member function which has a parameter from for_each(), find_if() etc.
Here is the code:
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
using std::vector;
using std::for_each;
using std::bind2nd;
using std::mem_fun_ref;
using std::string;
void Test_find();
int main(int argc, char* argv[])
{
Test_find();
return 0;
}
class Person
{
public:
Person() {};
Person( char* pszName ) { m_Name = pszName; }
int print()
{ std::cout << m_Name << std::endl; return 0; }
int printWithPrefix( std::string prefix )
{ std::cout << prefix << m_Name << std::endl; return 0; }
std::string m_Name;
};
void GPrint( Person person )
{
std::cout << person.m_Name << std::endl;
}
void
Test_find()
{
std::vector<Person> col1;
col1.push_back( Person( "Neville" ) );
col1.push_back( Person( "Cherryl" ) );
for_each( col1.begin(), col1.end(), &GPrint );
for_each( col1.begin(), col1.end(), mem_fun_ref( &Person::print ) );
for_each( col1.begin(), col1.end(), bind2nd( mem_fun_ref( &Person::printWithPrefix ), "person: " ) );
}
Blank lines somehow are missing above!
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
std::bind2nd requires that the function have two parameters. Otherwise, you can't bind anything to the second parameter Change Person::printWithPrefix() to accept two std::string arguments. The first will be the vector element, and the second will be the string bound with bind2nd.
I think.
|
|
|
|
|
Thanks, but...
The example I gave was straight from: "The C++ Standard Library" by
Nioclai M. Josuttis, so one would like to think it would work.
Changing printWithPrefix()to accept two std::string arguments gives:
for_each( col1.begin(), col1.end(), bind2nd( mem_fun_ref( &Person::printWithPrefix ), "person: ", "abc" ) );
d:\libs\tests\teststl.cpp(71) : error C2784: 'class std::mem_fun_ref_t<_R,_Ty> __cdecl std::mem_fun_ref(_R (__thiscall _Ty::*)(void))' : could not deduce template argument for '<Unknown>' from 'int (__thiscall Person::*)(class std::basic_string<char
,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)'
d:\libs\tests\teststl.cpp(71) : error C2780: 'class std::binder2nd<_Bfn> __cdecl std::bind2nd(const _Bfn &,const _Ty &)' : expects 2 arguments - 3 provided
g:\program files\microsoft visual studio\vc98\include\functional(189) : see declaration of 'bind2nd'
I'm not sure if you are right about bind2nd(), but having not used this before anything is possible. I just tried bind1st to no avail.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
Well, seems to me there are three problems here:- The offending line should be using
mem_fun1_ref :
for_each( col1.begin(), col1.end(), bind2nd( std::mem_fun1_ref( &Person::printWithPrefix ), "person: " ) );
- Even so, the probem doesn't compile due to (what it seems to me) a bug in the STL implementation for VC++:
mem_fun1_ref is defined as returning a std::binary_function<T *, A, R> , when it should return a std::binary_function<T, A, R> !
- The last problem is that
bind2nd passes as its first argument a const reference, which doesn't match with what mem_fun1_ref expects; basically, the standard is broken in this aspect.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for that. Chris Losinger also suggested mem_fun1_ref which I tried, and also found didn't work.
I spent several hours on this earlier today, assuming it was simply my lack of understanding of STL and there had to be an solution.
The example in the book I refered to declares printWithPrefix as:
void printWithPrefix(..) const; but I had to change the return type to int and remove the const to get print() to work.
If anyone has STLPort etc. installed I'd be interested to know if this code works with them.
I'm sure this really should be so hard.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
You might try Boost.Functional[^]. It fixes a number of errors of the standard wiith respect to binders and functional adapters.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
If you add the const back in, it works with STLport (4.5.something - the current version). Note that mem_fun1_ref isn't part of the standard (AFAIR). Single argument member functions are supported (in the Standard & STLPort) through overloading mem_fun_ref.
I'd second Joaquín Muñoz - Boost has a nice substitute for functional that works very nicely...as does most of the rest of Boost . The following line of code is the Boost equivalent of the STL code...the '_1' is a placeholder for the iterator parameter supplied in for_each .
for_each( col1.begin(), col1.end(), boost::bind( &Person::printWithPrefix , _1, "person: " ) );
One other thing you can do with the Boost version - make the parameter to printWithPrefix a const std::string& - Boost works around the C++ rule that you can't take a reference to a reference.
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Hi Stuart,
Thanks for that. Am I right in assuming that STLPort is the STL implementation of choice these days? I've downloaded it, but haven't got as far as building the library yet.
There is no doubt that Boost has some good stuff in it. I've just started using boost::scoped_ptr because VC auto_ptr doesn't have reset(), which I find quite astonishing. scoped_ptr is a better choice any way as it turns out.
Will using Boost functional as per your example work with VC STL or is this only with STLPort?
I'm also using LibSigC++ which I can do nothing but highly recomend. And as just recently noted on CP, Boost has just released their own implementation of signals and slots, which I look forward to trying when a get some spare time.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
Well...it's my implementation of choice . I use it for VC6 because it's more standard compliant than the one that ships with VC6 and also has some nice extra features (rope s and hash_map s, for example - rope s are nice for incrementally building up a big (Mb) string - three times faster than strings in some basic benchmarks I did). One other very nice feature is the debug version - iterators that tell you when you're using them incorrectly!!! Told me off about several things in my code!
The main downside is that it seems to pull more dross than the Dunkumware STL implementation because of the way it initialises it's iostream s (but, on the other hand, their fstream implementation uses memory mapping, which should boost (no pun) performance). That may not be true - I tend to statically link to STLport, but dynamically link to the VC6 STL, because of the availability of the respective DLLs.
As for Boost.functions , AFAIR, they work with both STL implementations. I've not used their signals yet - I rolled my own version about 18 months ago, which I'm still using.
Stuart Dootson
'How can you give a f**k when nothing seems to matter at all' - Mission of Burma, Vs
|
|
|
|
|
I define this data in header file.
---------------------------------------------------
#define Hash[0] "208803DD4D"
#define Hash[1] "146DB1CB1C"
#define Hash[2] "26D2199CFA"
#define Hash[3] "7CAFF3D504"
#define Hash[4] "6C40AB0E42"
#define Hash[5] "1E1D7486BE"
#define Hash[6] "A03E54D487"
#define Hash[7] "7ACC08F3F7"
#define Hash[8] "6B0133E813"
#define Hash[9] "114CFE0C12"
---------------------------------------------------
when I compile there is error message show
"error C2008: '[' : unexpected in macro definition"
If you know how to declare these array in header file,please tell me. Thank you.
|
|
|
|
|
YOu can't do it with #define. You should declare it as a const array, like this, using a CString or an STL string:
const CStirng Hash[] =
{
"data",
"data",
...
};
Or you could use char * in a similar way (I believe... no compiler with me at the moment so the syntax might not be 100% correct... ):
const char **hash =
{
"data",
"data",
"data",
...
};
Even a broken clock is right twice a day.
|
|
|
|
|
define it as:
<br />
char *Hash[10] = <br />
{"208803DD4D",<br />
"146DB1CB1C",<br />
"26D2199CFA",<br />
"7CAFF3D504",<br />
"6C40AB0E42",<br />
"1E1D7486BE",<br />
"A03E54D487",<br />
"7ACC08F3F7",<br />
"7ACC08F3F7",<br />
"6B0133E813",<br />
"114CFE0C12"<br />
};<br />
|
|
|
|
|
That won't work. Lose the *
Signature space for rent. Apply by email to....
|
|
|
|
|
|
How to convert float numbers to a CString class or a char type?
And how to convert a char type to a float number?
Thks in advance!
Appstmd
http://www.appstmd.com
|
|
|
|
|
|
|
Look up CString::Format
Jason Henderson start page articles "If you are going through hell, keep going." - Sir Winston Churchill
|
|
|
|
|
use std::ostringstream .
You use its << operator to shift the number in, and get the textual representation of it via its str() memberfunction.
|
|
|
|
|
anyone can kindly help me with this? thx a lot in advance.
i created a subclass from CListCtrl named uiCtrlListCtrl.
in the new class i implemented a message handler for OnLButtonDown, but i don't know how to get the Control List's Identifier inside the handler of this message.
the message handler is as below:
void caauiCtrlListCtrl::OnLButtonDown(UINT nFlags, CPoint point){
...
CWnd* pwndParent = GetParent();
pwndParent->SendMessage(UI_WM_LBTNDOWN, ?what should i put here for the list control's ID? );
...
}
|
|
|
|
|
I guess this should have to work:
pwndParent->SendMessage(UI_WM_LBTNDOWN, ::GetWindowLong(m_hWnd,GWL_ID));
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
it works! really appreciate your help!
i just found another means, but not so simple as this way.
i added one variable and then use it to store the control id from calling GetDlgCtrlID().
int nIdFrom;
nIdFrom = GetDlgCtrlID();
pwndParent->SendMessage(UI_WM_LBTNDOWN, (WPARAM)nIdFrom);
|
|
|
|
|
Hi Friends
I want the check the class name of the window being created with a given string. Or to write all class names to a file. I am using WH_CBT Hook..
But the following code is giving a memory cant read error. Any idea?
Regads.
Gaurika.
LRESULT CALLBACK FindToolbarProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// watch window creation:
if (nCode == HCBT_CREATEWND)
{
CBT_CREATEWND* pcw = (CBT_CREATEWND*)lParam;
// watch for Notepad creation, set toolbar name
if (pcw->lpcs->lpszClass &&
0 != strstr(pcw->lpcs->lpszClass, "Notepad")) //
{
Beep(1000,100); // Just to Identify…..
}
}
return CallNextHookEx(g_hkCBT, nCode, wParam, lParam);
}
Gaurika Wijeratne. // www.gaurika.com
|
|
|
|
|