|
Dear all,
I have two functions:
[code]
a) Member* get_member(Book* book);
b)Book* get_book(Member* member);
[/code]
The implementation code for the function prototypes is:
a)
[code]
template<class Book,class Member>
Member* AssociationList<Book,Member>::get_member(Book* book)
{
Member* member=0;
bool searching=true;
int index=0;
while(searching)
{
if (this->association_list[index])
if (this->association_list[index]->linked_book() ==book)
{
member=this->association_list[index]->linked_member();
searching=false;
}
else
index++;
else
index++;
if (searching && (index == LIST_SIZE))
{
searching=false;
}
}
return member;
}
[/code]
b)
[code]
template<class Book,class Member>
Book* AssociationList<Book,Member>::get_book(Member* member)
{
Book* book=0;
bool searching=true;
int index=0;
while(searching)
{
if (this->association_list[index])
if (this->association_list[index]->linked_member()==member)
{
book=this->association_list[index]->linked_book();
searching=false;
}
else
index++;
else
index++;
if (searching && (index == LIST_SIZE))
{
searching = false;
}
}
return book;
}
[/code]
All I want to do is use one generic function for the two, so that from the main.cpp:
[code]
void main()
{
List<Member>member1;
List<Book>book1;
char menuChoice;
do
{
cin>>menuChoice;
switch(menuChoice)
{
case '1': cout<<'\n';
book1.addElement("Books");
break;
case '2': cout<<'\n';
break;
case '3': cout<<'\n';
book1.displayElement("Books");
break;
case '4': cout<<'\n';
/*member1.addElement("Member");*/
break;
case '5': cout<<'\n';
break;
case '6': cout<<'\n';
/*member1.displayElement("Member");*/
break;
case '7': cout<<'\n';
//book1.borrowElement();
break;
case '8': cout<<'\n';
//book1.returnElement();
break;
default: cout<<'\n';
cout<<"Invalid Selection\n";
}
}while(menuChoice != '0' && !cin.eof());
}
[/code]
...to call each one and dispaly either the books from a book array or the members from a member array.
The'display' implementation code is:
[code]
template<class Object>
void List<Object>::displayElement(char* type)
{
if (num_elements == 0)
cout<<"No "<<type<<" is found in the "<<type<<" array.\n";
else
for(int element=0; element<this->num_elements; element++)
{
cout<<'\n';
this->element_list[element]->display(association_list.get_member(element_list[element]));
}
}
[/code]
But I'm having some errors trying to use
[code]
template<class R,class P>
R* get_member(P* pArg); instead of using the a,b function prototypes. The 'generic' function that I use and causes the problems is:
template<class R,class P>
R* AssociationList<Book,Member>::get_member(P* pArg)
{
R* member=0;
bool searching=true;
int index=0;
while(searching)
{
if (this->association_list[index])
if (this->association_list[index]->linked_book()==book)
{
member=this->association_list[index]->linked_member();
searching=false;
}
else
index++;
else
index++;
if (searching && (index == LIST_SIZE))
{
searching=false;
}
}
return member;
}
[/code]
The errors are:
[code]
'AssociationList<class Book, class Member>::get_member':unable to resolve function overload
and the second one is:
template definitions cannot nest(??)
[/code]
Could someone help me?
Regards,
grscot
|
|
|
|
|
Hello,
I am using VC++ 6.0. I want to convert a user defined object to the VARIANT type. I am not an expert in using variants. In c++ code it means:
function_takeVARIANT(VARIANT var);
function_do_something()
{
ClassA objA;
VARIANT varA;
....//Conversion here that would do varA=objA
function_takeVARIANT(varA);
}
function_takeVARIANT is a COM server's method and it uses an object of type ClassA. Is there anybody who can help me?
Thans a lot
Ahmad
Ahmad
|
|
|
|
|
Is there a C# file globbing library out there for MS Visual C 98? Or even one that can be easily tweaked to work with C#?
Any help is appreciated.
|
|
|
|
|
Hello
I've got a class that contains an event called hNewData that is manually resetted, initial not signalled and no security attributes.
The event is used to signal my workerthread when some new data should be sent.
In the workerthread I wait for some diffrent events:
hEvents[0] = pTP->hStopEvent;
hEvents[1] = pTP->hNewDataEvent;
hEvents[2] = osWriter.hEvent;
hEvents[3] = osReader.hEvent;
hEvents[4] = hDoReadEvent;
pTP is a point to a struct that is passed to the thread when I create it.
My problem is that WaitForMultipleObjects only detects that signal state randomly, and I have no f****n clue why. Starting to get desperate here, so please help.
The class is a socket communication class..
|
|
|
|
|
What do you mean "only detects that signal state randomly?" WaitForMultipleObject signals "Either any one or all of the specified objects are in the signaled state" according to MSDN.
Kuphryn
|
|
|
|
|
WaitForMultipleObjects wait for any of the events to get signalled.
But it only works sometimes when I signals the hNewDataEvent, i want to know why.
The event is created with the GUI thread and is passed to the workerthread when I create it.
|
|
|
|
|
It still would not become signaled even when you sign one or other events? Make sure the other handles are valid.
Kuphryn
|
|
|
|
|
kuphryn wrote:
It still would not become signaled even when you sign one or other events? Make sure the other handles are valid.
well.. That was the first thing I checked. It's valid alright.
|
|
|
|
|
so you have something like the below snippet?
ret = WaitForMultipleObject( 5, hEvents, FALSE, INFINITE );
if (ret == (WAIT_OBJECT_0 + 1)) //dosomething
the key points here are: 1) passing FALSE so that it doesn't have to wait for all objects 2) using INFINITE so that it blocks until an event is signalled and won't timeout, and 3) correctly determining which has become signalled. Since you didn't provide any code I can't really say what's the problem.
Joel Lucsy
|
|
|
|
|
I've solved it. I had named my event and that f***ed everything up.
|
|
|
|
|
Hi All,
I want to know if there is any mechanism for authentication of two code modules.In case the authentication fails, then the application should terminate. The authentication should be 2-way i.e. client knows that correct server is executing it and server knows that it is being executed by the correct client.
Some ideas or some existing methods on this would be helpful.
Thanks,
ITMan.
|
|
|
|
|
u have to think something like this
Client and Server knows a secret key
on connection client send a random public key
Server does the same
The client append the public key sent by the server to his private key and do an MD5 hash
The server does the same with the public key sent by the client and his private key
Then the client send the MD5 hash resulted so the server can know if the MD5 is correct by doing the same using the private and the public that the server used
The Client can do the same for the server
And if something appears wrong any side can cut the connection
Hope this helps
Any question
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I can use :
TCHAR someString[256];
someFunction(someString);
or
CString someString;
someFunction(someString.GetBuffer(256));
someString.ReleaseBuffer
Besides that fact that after the call, I still can append and modify the CString, without the need to mallocing/remallocing the string, is there an advantage of using one or the other, if only to fill in someString ?
Thanks.
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
The use of a TCHAR array or a CString object is totally up to you. In your example, the former comes from the stack while the latter will come from the heap.
If someFunction() can be changed to operate on a CString object rather than a char *, you can simplify things like:
CString someString;<br />
someFunction(someString);
|
|
|
|
|
The answer is, it depends. If you are always going to be using MFC, and have no need to share common functions with other non-MFC projects, then it would probably be easier to just use CString.
On the other hand, if you think you might want to reuse some code in non-MFC apps, then TCHAR is the way to go.
BTW, in your second example, most Win32 APIs take arguments of the form "LPCTSTR lpszArg" or perhaps "const TCHAR * lpszArg". The compiler is perfectly happy to pass a CString to such APIs without the need for "somString.GetBuffer()". In fact, overuse of GetBuffer() might be a sign that CStrings are not being used properly.
Best wishes,
Hans
|
|
|
|
|
I need to launch an executable multiple times passing in different argument list. Is there a way to use CreateProcess to launch the same executable but it shows in TaskManager as a different name? For e.g. ABC.exe gets launched as A1, A2 & A3.
The reason for this is logging & configuration setup uses the process name & it would be easier to manage them with unique names instead of the executable name.
Any pointers would be appreciated. TIA
Chen Venkataraman
|
|
|
|
|
Make copies of ABC.EXE, naming them ABC1.EXE, ABC2.EXE, and ABC3.EXE.
|
|
|
|
|
You can pass a command-line parameter to the app via the CreateProcess call that it can use to set it's main window caption to. Task manager (and the launch bar) will use the main window caption for display.
|
|
|
|
|
Tried setting the title attribute of the STARTUPINFO structure but it didn't help. Task Manager still shows the executable as ABC.exe to continue with my example.
But what i found is that if i specify both the lpApplicationName & lpCommandLine as follows, i can get a behavior close to what i want...
lpApplicationName = ABC.exe [need the .exe even though the doc says it is optional]
lpCommandLine = myABC arg1 arg2... etc
Since argv[0] is interpreted as to mean the app name, by specifying a different name as the first token for the command line i could get the app to use this name instead of the executable name for picking up config & log stuff.
I'm not sure if it is possible to get Task Manager to show a process with a different user-friendly name. Wondering how this is accomplished in the Unix world? [btw, this was an effort to simulate that behavior from the Unix side]
Thanks for the response, anyway
Chen Venkataraman
|
|
|
|
|
It's NOT possible to change the name in Task Manager. You must have some capability in the app that your launching to change the window title from a command line parameter in order to do what you want.
RageInTheMachine9532
|
|
|
|
|
Dear all,
I have two functions:
a) Member* get_member(Book* book);
b)Book* get_book(Member* member);
The implementation code for the function prototypes is:
a)
template<class Book,class Member>
Member* AssociationList<Book,Member>::get_member(Book* book)
{
Member* member=0;
bool searching=true;
int index=0;
while(searching)
{
if (this->association_list[index])
if (this->association_list[index]->linked_book()==book)
{
member=this->association_list[index]->linked_member();
searching=false;
}
else
index++;
else
index++;
if (searching && (index == LIST_SIZE))
{
searching=false;
}
}
return member;
}
b)
template<class Book,class Member>
Book* AssociationList<Book,Member>::get_book(Member* member)
{
Book* book=0;
bool searching=true;
int index=0;
while(searching)
{
if (this->association_list[index])
if (this->association_list[index]->linked_member()==member)
{
book=this->association_list[index]->linked_book();
searching=false;
}
else
index++;
else
index++;
if (searching && (index == LIST_SIZE))
{
searching = false;
}
}
return book;
}
All I want to do is use one generic function for the two, so that from the main.cpp:
void main()
{
List<Member>member1;
List<Book>book1;
char menuChoice;
do
{
cout<<'\n';
cout<<'\n';
cout<<"**** Main Menu ****"<<endl;
cout<<'\n';
cout<<"1: Add Book "<<endl;
cout<<'\n';
cout<<"2: Remove Book "<<endl;
cout<<'\n';
cout<<"3: Display Books "<<endl;
cout<<'\n';
cout<<"4: Add Member "<<endl;
cout<<'\n';
cout<<"5: Remove Member "<<endl;
cout<<'\n';
cout<<"6: Display Members "<<endl;
cout<<'\n';
cout<<"7: Borrow Book "<<endl;
cout<<'\n';
cout<<"8: Return Book "<<endl;
cout<<'\n';
cout<<"0: Quit "<<endl;
cout<<endl;
cout<<"Enter one of the above choices: ";cinFlush;
cin>>menuChoice;
switch(menuChoice)
{
case '1': cout<<'\n';
book1.addElement("Books");
break;
case '2': cout<<'\n';
break;
case '3': cout<<'\n';
book1.displayElement("Books");
break;
case '4': cout<<'\n';
/*member1.addElement("Member");*/
break;
case '5': cout<<'\n';
break;
case '6': cout<<'\n';
/*member1.displayElement("Member");*/
break;
case '7': cout<<'\n';
//book1.borrowElement();
break;
case '8': cout<<'\n';
//book1.returnElement();
break;
default: cout<<'\n';
cout<<"Invalid Selection\n";
}
}while(menuChoice != '0' && !cin.eof());
prompt_to_quit();
}
...to call each one and dispaly either the books from a book array or the members from a member array.
The'display' implementation code is:
template<class Object>
void List<Object>::displayElement(char* type)
{
if (num_elements == 0)
cout<<"No "<<type<<" is found in the "<<type<<" array.\n";
else
for(int element=0; element<this->num_elements; element++)
{
cout<<'\n';
this->element_list[element]->display(association_list.get_member(element_list[element]));
}
}
But I'm having some errors trying to use
template<class R,class P>
R* get_member(P* pArg); instead of using the a,b function prototypes. The 'generic' function that I use and causes the problems is:
template<class R,class P>
R* AssociationList<Book,Member>::get_member(P* pArg)
{
R* member=0;
bool searching=true;
int index=0;
while(searching)
{
if (this->association_list[index])
if (this->association_list[index]->linked_book()==book)
{
member=this->association_list[index]->linked_member();
searching=false;
}
else
index++;
else
index++;
if (searching && (index == LIST_SIZE))
{
searching=false;
}
}
return member;
}
The errors are:
'AssociationList<class Book, class Member>::get_member':unable to resolve function overload
and the second one is:
template definitions cannot nest(??)
Could someone help me?
Regards,
grscot
|
|
|
|
|
Hello
I've got a listview that I fill with information about mp3's.
The SQL query looks like this: SELECT * FROM mp3_info LEFT JOIN mp3_genre USING (genre_id) WHERE artist like 'a%' ORDER BY artist, album, title
The query returns about 5 columns and about 200 rows.
Then I use the following loop to populate the listview:
do
{
rs.GetFieldValue(1, nMp3Id);
rs.GetFieldValue(2, szName, 40);
nIndex = ctl.InsertItem(ctl.GetItemCount(), szName, -1);
ctl.SetItemData(nIndex, (DWORD_PTR)nMp3Id);
for (int i = 3; i < m_nColumnCount; i++)
{
rs.GetFieldValue(i, szName, 40);
ctl.SetItemText(nIndex, i-2, szName);
}
} while (rs.MoveNext());
The problem is that the loop is slow, It takes over 1 second to fill the listview.
The GetFieldValue function looks like this:
bool CODBCRecordset::GetFieldValue(int nField, char *szData, int nMaxLen)
{
//we are 1 based.
if (!nField) return false;
SQLRETURN ret;
ret = SQLGetData(m_hStmt, (SQLUSMALLINT)nField, SQL_C_CHAR, szData,
nMaxLen, NULL);
return ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO;
}
Why do it take such a long time to populate the list?
|
|
|
|
|
Try use SQLBindCol and SQLFetch.
Pavel
Sonork 100.15206
|
|
|
|
|
why? Is it faster? why are SqlGetData slow?
|
|
|
|
|
Hello everyone,
I have a little problem that I was hoping someone could help me out with. I have a data file (created by using serialization) that I want to read into a new program. Problem is, the new program class name is the same as the old one (and I can't change it since the code was done by a third-party). I want to use my old class to read the data in, then save it to the new class.
So, I created a new class (let's call it CAlar1, since the original class was CAlarm and I thought the class name length should be the same) and tried to read the file in, but after serializing the class, all the data is messed up. Since the class name is different, it doesn't seem to be reading the file correctly.
Is there any way around this? I would like to read the old data in, convert it to the new class, and save it back, so short of decoding the binary file format, is there anything else I can try?
Regards,
Brigg Thorp
Software Engineer
Timex Corporation
|
|
|
|