|
Yep, ofstream s cannot be copied. So, you have several alternatives:
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Can anyone tell me about the easiest way to handle events that are fired from ATL dll ? I used ActiveX controls and when we developer client application in MFC, the event handling mechanism is very easy and automatically done by the framework. But this is not the case if our COM server is not an ActiveX but a dll. Can anyone point me out some sample app for sinking connection points in MFC ???
|
|
|
|
|
I have a vector of pointers vector <CPersons*> that is passed in a function by reference.
This function has access to another similar vector say m_Persons and i have to copy all entries from m_Persons to Persons
MyClass::MyFunc(vector<CPersons*>& Persons)
{
//This class has a member function vector<CPersons*> m_Persons
// i need to copy content of m_Persons into Persons
if (Persons.capacity() < Persons.size()+m_Persons.size())
Persons.resize(Persons.size()+m_Persons->size());
copy(m_Persons.begin(), m_Persons.end(), Persons.begin() );
}
but since this is a vector of pointer, my understanding is that anytime re-allocation of
destination vector Persons is needed, all these pointer would become invalid.
Is my understanding correct?
If yes, is this best of way doing it. If no, please advise how to attempt such problem.
|
|
|
|
|
this is probably ok. your understanding is incorrect - you will end up with two vectors containing the list of pointers. the only thing you need to be careful of is who does the clean up i.e. make sure the pointed-to objects don't get destroyed twice.
your resizing test is wrong though. capacity() returns the amount of space *allocated*, not necessarily *used*. you can just do:
<br />
Persons.resize( m_Persons.size() ) ;<br />
your misunderstanding is probably this: if you resize a vector, the memory used to store that vector's elements may be moved i.e. the memory used to store your pointers may change but not the pointers themselves.
Software is everything. It also sucks. Charles Fishman [^]
Awasu 1.0.2 (beta)[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Anonymous wrote:
anytime re-allocation of
destination vector Persons is needed, all these pointer would become invalid
No. They get copied, but still point to the same chunk of memory containing the person-object.
But who is responsible to cleaning up, e.g. calling 'delete'?
Using smart pointer can help you here - but NEVER EVER use std::auto_ptr!!!!
Try the shared_ptr from www.boost.org[^], it uses reference counting to delete the obect it points to when the last ptr pointing to it goes out of scope.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
I have a vector of pointers like
vector<cperson*> Persons
This vector is passed to method func by reference
This func has another vector of CPerson* m_Persons and i have to copy all entries from m_Persons to Persons
I am doing it in following way
func(vector<cperson*>& Persons)
{
if (Persons.capacity() < Persons.size()+m_Persons->size())
Persons.resize(Persons.size()+m_Persons->size());
copy(m_Persons.begin(), m_Persons.end(), Persons.begin() );
}
but seems to me doing this way i an losing some references CPerson* in Persons
Is this right way of doing this?
Am i in problem because anytime vector need to reallocated memory, i am loosing all previous references?
PS: Please oppologize any typos as i am only trying to give the concetp
|
|
|
|
|
What i wanted to say in first two lines is
I have a vector of pointers of a class Persons
vector<persons*>
|
|
|
|
|
Has anyone here used CMimeMessage to compose or decode a MIME encoded message and attachments etc?
Hush,hush...
thought I heard you call my name now.
Kula Shaker.
Amit Dey
Latest articles at CP - PocketPC New menu
Office addin
|
|
|
|
|
Yep, I did. But just some small tests, if and how it works. No real app.
|
|
|
|
|
I want to use CMimeMessage and other ATL7 classes to create and decode MIME messages and attachments.For example, I want to create a MIME message with a single attachment like:
IMultiLanguage *pLang = NULL;
CoInitialize(NULL);
CMimeMessage msg(pLang);
if(msg.SetSender("visualcdev@hotmail.com"))
if(msg.SetDisplayName("My custom mime message to be displayed in a string"))
{
msg.SetPriority(ATL_MIME_LOW_PRIORITY );
msg.SetSubject("custom subject");
msg.AddText(_T("hello world from a test message you should also end a string like this."));
msg.AddRecipient(_T("amitdey@softhome.net"),"amitdey@softhome.net",0);
msg.AttachFile("C:\\scantastic.bmp");
}
But when I view the contents of the message, by writing it to a file, the message is not a MIME formatted message( I cannot see the headers or anything.
DWORD dwWritten;
DWORD Ret = WriteFile(hFile,&msg,sizeof(msg),&dwWritten,NULL);
message does not have proper MIME headers.How can I use CMimeMessage to create/modify MIME messages?
Thanks.
Hush,hush...
thought I heard you call my name now.
Kula Shaker.
Amit Dey
Latest articles at CP - PocketPC New menu
Office addin
|
|
|
|
|
Hi,
the first part is OK and works. Your problem is in the WriteFile phase. You cannot use the WriteFile as you did, because then you will just save the CMimeMessage class as is in memory. And because CMimeMessage nearly stores only pointers to other classes (body, attachements etc.) you'll see nothing usefull.
The correct way how can you save the message is:
msg.WriteData( hFile, &overlapped );
This method makes more processing, stores also the aggregated classes etc and makes a mime message for you.
Hope this helps
|
|
|
|
|
Yes, the Overlapped i/o did it. Thanks. From the samples I have seen, CMimeMessage is more for composing and sending messages, what about translating/decoding messages and attachments.
Hush,hush...
thought I heard you call my name now.
Kula Shaker.
Amit Dey
Latest articles at CP - PocketPC New menu
Office addin
|
|
|
|
|
Also, if I have a mime-formatted message as an IStream, can I attach it anyway to a CMimeMessage and then use the classes to parse info? How?
TIA.
Hush,hush...
thought I heard you call my name now.
Kula Shaker.
Amit Dey
Latest articles at CP - PocketPC New menu
Office addin
|
|
|
|
|
I don't think that the CMimeMessage is ready for parsing. It was designed for creating the message & sending.
For parsing it will be required to use another class or build your own.
|
|
|
|
|
Interesting. I can see that the ATL7 CMimeMessage creates correct Outlook Express mail files. i.e. .eml format.
Yes, I guess I would have to write a class myself. But it should not be too difficult, esp with all decoding code in the ATL classes that I can use.
Hush,hush...
thought I heard you call my name now.
Kula Shaker.
Amit Dey
Latest articles at CP - PocketPC New menu
Office addin
|
|
|
|
|
I need to copy results of a multimap search to a vector.
Like in the example below, i need the contents of multimap
start -> end into copiedVector (i.e., copiedVector should have 21,22,23)
Can i use copy algorithm here? Any other efficient way of doing this?
multimap <int, int=""> Multimap;
Multimap.insert(pair<int,int> ( 1,11) );
Multimap.insert(pair<int,int> ( 1,12) );
Multimap.insert(pair<int,int> ( 2,21) );
Multimap.insert(pair<int,int> ( 2,22) );
Multimap.insert(pair<int,int> ( 2,23) );
int toFind = 2;
multimap <int, int="">::iterator start = Multimap.lower_bound(toFind);
multimap <int, int="">::iterator end = Multimap.upper_bound(toFind);
for ( ; start != end; start++ )
cout << start->second << endl;
vector<int> copiedVector;
|
|
|
|
|
If you use the copy algorithm, the vector needs to contain the same data as the multimap. This means that the vector has to contain pair data if you use copy.
So, the following works:
<br />
multimap<int,int> myMap;<br />
<br />
myMap.insert( pair<int,int>(1,11) );<br />
myMap.insert( pair<int,int>(1,12) );<br />
myMap.insert( pair<int,int>(2,21) );<br />
myMap.insert( pair<int,int>(2,22) );<br />
myMap.insert( pair<int,int>(2,23) );<br />
<br />
multimap<int,int>::iterator startRange = myMap.lower_bound(2);<br />
multimap<int,int>::iterator endRange = myMap.upper_bound(2);<br />
<br />
vector< pair<int,int> > myVector;<br />
<br />
copy( startRange, endRange, back_inserter(myVector) );<br />
If you want the vector to contain just the second element, you need to use some algorithm other than copy. One way to do this is to use the transform algorithm.
The following is one way to do this:
<br />
struct copysecond<br />
{<br />
int operator()( const pair<int,int>& value )<br />
{<br />
return value.second;<br />
}<br />
};<br />
<br />
<br />
<br />
<br />
vector<int> myVector;<br />
<br />
transform( startRange, endRange, back_inserter(myVector), copysecond() );<br />
|
|
|
|
|
Personally, I would stick with doing it with using the handwritten loop.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I would probably use a handwritten loop if I was only coding it for a single time. If I need to do it more than once, I would look at using transform.
John
|
|
|
|
|
Hi, I'm trying to host a WTL modeless dialog as a child window in another dialog. My modeless is WTL based and the dialog is not (it is CBuilder).
I did the same with a Win32 modeless and it works fine but although the WTL dialog behaves like a child window I still can see the borders and caption bar. I think I should change the style or declaration in the .rc to have a real control looking dialog.
Below is the code and .rc, please tell me chat's wrong.
btw The _Module is non functionnal has the main message proc is owned by CBuilder so I hooked the Cbuilder message map to get the WH_GETMESSAGE (tips from a code project article) maybe am I missing some other messages ?
class CMyDialog : public CDialogImpl<CMyDialog>, public CUpdateUI<CMyDialog>,
public CMessageFilter, public CControlWinTraits, public CIdleHandler
{
public:
enum { IDD = IDD_DIALOG1 };
CMyDialog()
{
}
virtual BOOL PreTranslateMessage(MSG* pMsg)
{
return IsDialogMessage(pMsg);
}
virtual BOOL OnIdle()
{
return FALSE;
}
BEGIN_MSG_MAP(CMyDialog)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
REFLECT_NOTIFICATIONS()
END_MSG_MAP()
BEGIN_UPDATE_UI_MAP(CMyDialog)
END_UPDATE_UI_MAP()
LRESULT OnInitDialog(UINT , WPARAM , LPARAM , BOOL& bHandled)
{
CenterWindow();
UIAddChildWindowContainer(m_hWnd);
return TRUE;
}
LRESULT OnCancel(WORD , WORD wID, HWND , BOOL& )
{
DestroyWindow();
return 0;
}
};
and the .rc declaration:
IDD_DIALOG1 DIALOGEX 0, 0, 187, 95
STYLE DS_MODALFRAME | DS_3DLOOK | WS_CHILD | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_NOPARENTNOTIFY | WS_EX_TOOLWINDOW | WS_EX_CONTROLPARENT
CAPTION "Hello World WTL"
FONT 8, "MS Sans Serif"
BEGIN
CONTROL "Check1",IDC_CHECK1,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,7,7,88,10
CONTROL "Check2",IDC_CHECK2,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,7,20,84,10
PUSHBUTTON "Button1",IDC_BUTTON1,130,7,50,14
PUSHBUTTON "Button2",IDC_BUTTON2,130,27,50,14
END
I've been working seriously on WTL for a couple of months now and it's really a powerfull framework base.
Of course the above technique works fine with MFC too
Yarp
http://www.senosoft.com/
|
|
|
|
|
I forgot to say the code to create the dialog is rather trivial:
CMyDialog m_myDialog;
m_myDialog.Create(this->hWnd);
Yarp
http://www.senosoft.com/
|
|
|
|
|
yarp wrote:
STYLE DS_MODALFRAME | DS_3DLOOK | WS_CHILD | WS_CAPTION | WS_SYSMENU
The styles in bold are why the dialog has a caption. The styles (in the resource editor) should be Style=Child, Border=None
--Mike--
THERE IS NO THERE IS NO BUT THERE IS
MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT
Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
Ok, it works fine, thanks a lot Mike - btw I love your articles especially the last one on WTL.
I now have a CBuilder frame and WTL controls inside, cool )
What I don't understand is that I did the same with a Win32 modeless and it was declared as follows:
IDD_TOOLBAR DIALOGEX 0, 0, 103, 63
STYLE DS_MODALFRAME | DS_3DLOOK | WS_CHILD | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_NOPARENTNOTIFY | WS_EX_TOOLWINDOW | WS_EX_CONTROLPARENT
CAPTION "Folders"
FONT 8, "MS Sans Serif"
BEGIN
PUSHBUTTON "&Press This Button",IDC_PRESS,9,19,79,14
PUSHBUTTON "&Or This One",IDC_OTHER,9,38,79,14
END
So I just copy/pasted those settings in my WTL dialog.
Tha fact is the Win32 dialog was hosted in a .dll but it was very simple with no style overriden:
g_hToolbar = CreateDialog((HINSTANCE)g_hModule, MAKEINTRESOURCE(IDD_TOOLBAR),
hWndParent, ToolDlgProc);
if (g_hToolbar != NULL) {
ShowWindow(g_hToolbar, SW_SHOW);
}
I can't understand the difference but it probably lies inside the WTL headers that overrides default Win32 behaviour ?
The fact is declare the Dialog as a child with no border is better because that's what we are loking for.
Thanks again.
Yarp
http://www.senosoft.com/
|
|
|
|
|
I have data in three separate vectors that I want to send over the network using the The Windows Sockets sendto function.
int sendto(
SOCKET s,
const char FAR *buf,
int len,
int flags,
const struct sockaddr FAR *to,
int tolen
);
But it requires a buffer, *buf, containing the data to be transmitted. How would I take the data from three different vectors and do this? Would I have to copy all the data into a new vector and use that vector to in the sendto function?
Thank you
|
|
|
|
|
One solution is memset(). Make sure you allocate enough memory for all three buffers. Use a pointer as a copy initial location.
Kuphryn
|
|
|
|
|