|
The busy loop is just for testing right now. The code is part of a larger project I am working on. I couldn't find the problem with pipes so I made a small isolated testcase.
If I wait on ReadFile it just sits there waiting forever. For example if I do something like
while (true)
{
data = ReadFile( readEnd, 1 )
if error and error==ERROR_BROKEN_PIPE then break
print(data)
}
then it will print the data the server has written and stop printing anything. Even after the 3rd process and the server which wrote the data are long gone the client is still waiting on the ReadFile call. It just never returns.
Any ideas?
-Matthias
|
|
|
|
|
I found out the problem. I wasn't closing the handles to the write end of the pipe cleanly. Wasn't passing them properly from 3rd process to server process. After I fixed that it works now and calls like PeekNamedPipe and ReadFile actually fail
Thanks for your help!
-Matthias
|
|
|
|
|
Cool
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In stdafx.h, I wrote
<br />
#include <Guilib.h><br />
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename ("EOF","adoEOF")<br />
There are lots of enum redefinitions.
How to correct it?
Thanks.
-- modified at 21:07 Thursday 22nd November, 2007
|
|
|
|
|
I need to be able to take the collected data from several vectors and place them inside a "Main Vector" that will hold all of the data collected.
Here's some code:
class CMyTrailer {
public:
// Varable
CString m_csData;
CMyTrailer();
~CMyTrailer();
};
typedef std::vector<CMyTrailer> ITEM;
typedef std::vector<CMyTrailer> MFG;
typedef std::vector<CMyTrailer> ID;
typedef std::vector<CMyTrailer>::iterator ITItem;
typedef std::vector<CMyTrailer>::iterator ITMFG;
typedef std::vector<CMyTrailer>::iterator ITID;
vector <CMyTrailer> m_Item;
vector <CMyTrailer> m_MFG;
vector <CMyTrailer> m_ID;
// iterators:
vector<CMyTrailer>::iterator m_ITItem;
vector<CMyTrailer>::iterator m_ITMFG;
vector<CMyTrailer>::iterator m_ITID;
Here's my code to copy it:
void CTrlMasterDlg::AddVecItem(const ITEM& vec)
{
vector<CMyTrailer>::iterator m_ITItemvec;
m_ITItem = m_Item.end();
m_ITItemvec = vec.begin();
while(m_ITItemvec != vec.end())
{
m_Item.pushback(vec.);
m_ITItemvec++;
}
}
I get this error on compile:
C2039: 'pushback' : is not a member of 'std::vector<_Ty>'
1> with
_Ty=CMyTrailer
Any ideas on how to solve this?
A C++ programming language novice, but striving to learn
|
|
|
|
|
vector <CMyTrailer> m_Item;
vector <CMyTrailer> m_MFG;
...fill...
m_Item.insert( m_Item.end(), m_MFG.begin(), m_MFG.end());
BTW.
the name of the function is push_back
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
but for this, you have to iterate yourself thru the vector to be copied...
STL provide very powerful algorithms. check my other post.
|
|
|
|
|
std::vector<int> v1;
std::vector<int> v2;
std::copy(v1.begin(), v1.end(), std::back_inserter(v2));
|
|
|
|
|
How exactly does your code work? I'm not too famular with vector(S) or the STL in general. Will std::copy copy anything or is it just for vector(s)? The way you presented: std::copy(v1.begin(), v1.end(), std::back_inserter(v2)); I thinkl thats what I'm looking for; but I'm not sure. I want the (in your example) v1 vector loaded at the end of it's current data: with the v2 vector (beginning at the front of v2(begin()) to v2's end (end()).
Also How do I show the data in each CMyTrailer::m_csData ? (console example is sufficient). I want to verify that everything is doing what I want it to do before I placed it in a ListBox in my program.
Thanks,
A C++ programming language novice, but striving to learn
-- modified at 14:12 Thursday 22nd November, 2007
What I mean, is I don't know how to extract CMyTrailer::m_csData from each iteration of the vector.
|
|
|
|
|
ok, i'm detailing a bit more.
the STL is a set of classes, all in the standard of C++.
some of the classes are containers (vector is one of these).
some other classes are called algorithms. they are designed to do common actions on the containers. copying a part of a container into another is one of those common things we can except of it.
if you have a vector v1, which contains say {4, 7, -1} and a vector v2, which has {2, 9}, then you just copy the line of code just like I did and after that, v2 will contain {2, 9, 4, 7, -1}.
actually, v1 is copied entierely because i told the copy() algorithm to do so. i said to start the copy from the first element of v1 (v1.begin()) and to copy to the end (v1.end()).
also, the elements of v1 are copied at the end of v2 because I use the back_inserter() alorithm, which is designed to insert at the back.
|
|
|
|
|
void CTrlMasterDlg::AddVecItem(const ITEM& vec)
{
// vector to be copied: iterator
//vector<CMyTrailer>::iterator m_ITItemvec;
//vector to hold all copied data: id m_Item
// set iterator at back of m_Item:
m_ITItem = m_Item.end();
// set vector to be copied at the front of it's vector:
m_ITItemvec = vec.begin();
while(m_ITItemvec != vec.end())
{
/*
m_Item.pushback(vec.);
m_ITItemvec++;
*/
// Is this right?
//std::copy(v1.begin(), v1.end(), std::back_inserter(v2));
std::copy(vec.begin(),vec.end(),back_insertor(m_Item));
}
}
So using my vectors: if I want everything from from vec to go into m_Item vector start at m_Itetm's last data(MyTrailer), is the above code correct? If not would you show me?
A C++ programming language novice, but striving to learn
|
|
|
|
|
actually, where you're wrong is that you don't need to iterate yourself. the std::copy() algorithm does it for you :
void CTrlMasterDlg::AddVecItem(const ITEM& vec) {
std::copy(vec.begin(), vec.end(), std::back_insertor(m_Item));
}
and for your personnal knowledge, this was quite the same as the following :
void CTrlMasterDlg::AddVecItem(const ITEM& vec) {
for (ITEM::iterator it = vec.begin(); it != vec.end(); it++) {
m_Item.push_back(*it);
}
}
|
|
|
|
|
I certainly appreciate all of your help. I'm new to the STL; but I want to learn it. I really only have CodeProject as a learning vehicle. Limited resources if you get my drift.
One other question. How do I get the CMyTrailer::m_csData Data out of the vector? What the vector does is copy the data the User has entered from various Wizard pages(hence the need to copy that data into one vector) and display it on the final Wizard page; then save it to file, and other things. I'm a little lost as to how to get each ("*it") in your example to become the class CMyTrailer. Could you explain how to get each CMyTrailer out of the vector?
Thanks in advance.
A C++ programming language novice, but striving to learn
|
|
|
|
|
I don't know what is m_csData, but it's a member of your class CMyTrailer, which class has several instances into the vector. you agree with that ?
i'm not sure to understand exactly why you're trying to access m_csData; not in the copy achievement, right ?
anyway, let's say you have an iterator on the vector :
ITEM::iterator it = vec.begin();
like i declared it, and initialized it, it is now an iterator which can go thru ITEM's elements, and is told to be placed on the first element of the vector.
basically, you can see an iterator as an "involved" pointer. just remember that, like pointers, you access the element pointed to by "dereferencing" it : *it
so, *it now returns the CMyTrailer element pointed to by it.
as m_csData is public, you can just access it like that :
(*it).m_csData;
or even better
it->m_csData;
for your learning, here is THE web site reference for STL : http://www.sgi.com/tech/stl/[^]
also, you can find at codeproject some good articles, like This One[^].
but feel free to continue asking me if you need
|
|
|
|
|
I tried to do this: std::vector<CString> m_Item; but the compiler wouldn't let me. to work around that I created the CMyTrialer class whose only purpose is to have a CString (m_csData) as it's only purpose. the compiler accepted that but when I just put vector<CString> the compiler said error: CString is not a class, union,etc. so I just created CMyTrailer to hold a CString and the compiler accepted that.
I will take each of the CMyTrailer.m_csData data and put them into a listbox on the final page of the Wizard.
A C++ programming language novice, but striving to learn
|
|
|
|
|
if you're dealing with STL, why do you go to the end and use std::string, rather that mixing STL and MFC ?
std::vector<std::string> would have done your job though.
|
|
|
|
|
I got the same compiler error when I used std::vector<string> m_Item. Thats why I tried std::vector<CString> m_Item.
A C++ programming language novice, but striving to learn
|
|
|
|
|
maybe because you didn't include the correct headers...
have you thought of #include <string> ?
|
|
|
|
|
Hi All,
I'm having a win32 dll. I need to provide a version number for the DLL.
How can we achieve this through code?
I'm using VC++6.0 for building the dll.
Many thanks,
Rajesh
|
|
|
|
|
|
Hi,
I'm actually writing a CLIENT/SERVER TCP/IPv6 application, under Microsoft Visual Studio C++. In which the SERVER is a file server application and the CLIENT is a "Multiple Document Interface (MDI)" and "RichEdit Text" application that can open multiple files from the server.
I would like to add a Toolbar window into my MDI frame window, to do this, I've created the Toolbar window with the "CreateToolBarEx" function.
But the created Toolbar window is located in the client area of the MDI frame window and each time a new MDI child window is created to hold a new document, it erases the Toolbar window in the client area.
My question is how can I do :
1) To change the client area size so that fits
height(MDI Frame window) - height(Toolbar window)
OR
2) To include the Toolbar window into the
non-client area like the Menubar and the Titlebar
So that the MDI client window can't anymore erase the Toolbar window in the client area.
Thanks,
Alain NGUYEN
|
|
|
|
|
add a class derived from ccontrolbar.
and then use dockcontrolbar().
prasann
who else
|
|
|
|
|
Hi all,
it's very helpful for me. i have created an application to install an printer Locally through INF file.when a call AddPrinter() function it fails with error code 126(specified module could not be found) Although i have initalise all the parameter as mention in MSDN( You must specify non-NULL values for the pPrinterName, pPortName, pDriverName, and pPrintProcessor members of this structure before calling AddPrinter. ). but it failed and initialisation is correct for that from my end......is there any reson to fails this function.
plz help me.Thanks in Advance.
Ashish
|
|
|
|
|
Have you checked the path to the *.inf file?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Hi,
Is that possible to run an executable file that is part of a data file by passing the begining (disk offset) inside this data file ?
Regards,
sdancer75
|
|
|
|