|
Thanks for the help (all). I got that part of it fixed. The problem is that it's now causing another error:
fatal error C1189: #error : WINDOWS.H is already included. MFC Apps must not #include <windows.h>.
I've checked every single include statement, and Windows.H isn't there. It might be a dependancy of one of the include files though. I'm also being forced to use cstringt.h in my MFC classes and atlstr.h in my non-MFC classes, all in the same project. It's unlikely but that might have something to do with it. Here is all of my include files, if someone could look at them please:
"phone_interface.cpp"
#include <cstringt.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <strstream>
#include "phone_interface.h"
#include <afxwin.h>
//File Name: "sort.rc"
#include <afxres.h>
#include <phone_ids.h>
//File Name: "phone_main.cpp"
#include <cstdlib>
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <strstream>
#include <phone_interface.h>
#include <afxwin.h>
#include <phone_ids.h>
//File Name: "phonebook_class.cpp"
//File Description: Implementation file for PhoneBook class
#include <iostream>
#include <string>
#include <fstream>
#include <cstddef>
#include <atlstr.h>
#include <sstream>
#include "phonebook_class.h"
#include "defenitions.h"
//File Name: "usermenu_class.cpp"
//File Description: Implementation file for UserMenu class
#include <iostream>
#include <string>
#include <cctype>
#include "usermenu_class.h"
#include "phonebook_class.h"
#include "defenitions.h"
//File Name: "Common_Defenetions.h"
//Description: Common header file for structure and enumeration defenitions.
#ifndef DEFENITIONS_H
#define DEFENITIONS_H
#include <iostream>
#include <string>
//File Name: "phone_interface.h"
#ifndef PHONE_INTERFACE_H
#define PHONE_INTERFACE_H
#include <iostream>
#include <string>
#include <strstream>
#include <fstream>
#include <afxwin.h>
#include "usermenu_class.h"
//File Name: "phonebook_class.h"
//File Description: Decleration file for PhoneBook class
#ifndef PHONEBOOK_CLASS_H
#define PHONEBOOK_CLASS_H
#include <iostream>
#include <cstddef>
#include <string.h>
#include <sstream>
#include <atlstr.h>
#include "defenitions.h"
//File Name: "usermenu_class.h"
//Description: Declaration file for UserMenu class
#include <iostream>
#include <string>
#include "defenitions.h"
#include "phonebook_class.h"
Sorry for the long post. Thanks for the help.
|
|
|
|
|
#include <afxwin.h> //<--- this pulls in windows.h
I would recommend creating a temp MFC project that is close to the type of project you are
working on. Then take the stdafx.cpp and stdafx.h from that temp project and copy them to your
project. stdafx.h is the default pre-compiled header file and should be included at the top of every
cpp file in your project. Make sure in your project settings - C/C++ - Precompiled headers -
Create/Use PCH through file setting is set to stdafx.h. This should give you most, if not all, of
the headers you'll commonly need.
|
|
|
|
|
I'm sorry, I think the forum chopped off the include file you were talking about. Can you check the "Ignore HTML tags in this message" box below the smilies please.
|
|
|
|
|
I always do that!
#include <afxwin.h> //<--- this pulls in windows.h
I would recommend creating a temp MFC project that is close to the type of project you are
working on. Then take the stdafx.cpp and stdafx.h from that temp project and copy them to your
project. stdafx.h is the default pre-compiled header file and should be included at the top of every
cpp file in your project. Make sure in your project settings - C/C++ - Precompiled headers -
Create/Use PCH through file setting is set to stdafx.h. This should give you most, if not all, of
the headers you'll commonly need.
|
|
|
|
|
Why are you not putting the standard include files (e.g., iostream , afxwin.h , string ) in your project's stdafx.h file? Your compiles will be noticeably faster.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
CoffeeAddict19 wrote: ...my compiler is spitting out errors and dosen't recognize CString. I can't figure out what's wrong.
CString is a class in MFC, which your project is apparently not using.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
replace the include <cstring> by <string>
and use std::string instead.
methink your are confused about the <cstring> header.
|
|
|
|
|
If you are using Visual C++ 2005, Unicode is the default.
#include <stdio.h>
#include <tchar.h>
#include <atlbase.h>
#include <atlstr.h>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
CString test;
test = _T("It worked!");
std::wcout << static_cast<LPCTSTR>(test) << std::endl;
return 0;
}
|
|
|
|
|
|
|
I am producing a mobile application using embedded VC++ 4 which contains multiple dialogs.
It was intended to step through the dialogs using a next button which would open the next dialog and close the current dialog. Also a previous button which does a similar thing.
The code used to open the next and close current is
Class2 dlgClass2(this);
nRetCode = dlgClass2.DoModal();
CDialog::OnCancel();
And for the previous button on the dlgClass2 button
Class1 dlgClass1(this);
nRetCode = dlgClass1.DoModal();
CDialog::OnCancel();
However by continually selecting next on the dlgClass1 and previous on dlgClass2 the application crashes after the 11th or 12th attempt.
Does anyone know please why this is happening? Are you able to close the current dialog or does it need to remain open?
Note also posted this on the mobile development section.
SDT
SDT
|
|
|
|
|
CDialog::DoModal() will not return until the dialog is dismissed, hence it's called modal.
So you have a dialog calling another dialogs DoModal that calls the first dialog's DoModal that calls the second dialog's DoModal().... you get the picture, right?
It's not even the same dialog you call the second time since you create a new instance on the stack, it's just the same class.
Eventually you will run out of stack space and the application will crash or worse.
What you need to do is either post messages to the container of the dialogs that calls DoModal for each dialog when handled, or create modeless dialogs so that your CDialog::OnCancel() call will be executed and the dialog can be dismissed.
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
This sounds like an odd design. Have you considered a wizard-type property sheet?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
EndDialog(), might help. Please check it and let me know if doesn't work.
|
|
|
|
|
Raj Prathap wrote: EndDialog(), might help.
Doubtful. The problem, as Roger has alrady mentioned, is that Dialog1 is calling Dialog2 is calling Dialog1 is calling Dialog2...
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thanks for all the responses.
Tried enddialog and this has the same results.
Looks like I may have gone for a poor design.
The application design has four dialogs. What I wanted to do was move forwards through each 1 to 4 or back 4 to 1 which I would have thought is OK using domodal to open up each and oncancel to move back. However dialog 2 contains a list control of data read from a file. After entering text into edit boxes on dialog 4 and accepting the data with a button press (which updates the file) I wanted to close dialog 4 and 3 (both containing data relevant to the list control choice on dialog 2) and refresh the list control on dialog 2 to remove the processed line.
Thought the best way to refresh dialog 2 was to close it and reopen it so that the OnInitDialog function refreshed the dialog from the updated file.
Also when completing the final choice in dialog 4 and there are no items left in the dialog 2 list control I wanted to go back from 4 to 1 so close 4, 3 and 2.
This is why I was attempting to open the next dialog and cancal the current one.
So not sure if I can do this kind of thing in VC++ using MFC. Does anyone no please if it can. The application appeared to work well until I noticed the first crash.
I will have a look at modeless dialogs to see if this is the answer.
Thanks
Steve
|
|
|
|
|
Have you considered a wizard-type property sheet?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thanks to all for your help with this problem I had. Looks like modeless dialogs have worked.
|
|
|
|
|
Hi, I am using MySql ODBC driver for connectivity with MySql database and my VC++.NET application. Now when I am using odbcDataReader to read some data some time I need to use another odbcDataReader for another table. But this gives me run time error “There is already an open DataReader associated with this Connection which must be closed first.” Can I know how can I use 2 odbcDataReaders at same time, or any other method to do this? Thanks in advance.
|
|
|
|
|
|
Hi All,
Very new to Excel Automation but have done a lot with Word Automation. Using VC++ V6 and Excel 2000.
I simply need to get a range object that corresponds to the current user selection. This is what I thought would work:
Excel::IRangePtr spRange = msp_excel->GetSelection();
There is an active sheet and a selection of cells but spRange (the smart pointer) is always returned as null???
I am also puzzled by the fact that there doesn't seem to be a Selection object, per se, something that could be returned and worked with via ISelectionPtr or the like???
Any help greatly appreciated! Thanks,
Doug
Doug Knudson
|
|
|
|
|
Make sure you have an interface pointer to the sheet you think you're using.
Try and do something else such as selecting "A1" and write something to it.
The application object contains a collection of workbooks that contains a collection of worksheets and so on. You need to get the correct sheet.
Is msp_excel really an interface opinter to a worksheet? The name that implies a opinter to the application object makes me wonder...;)
It's been a while since I automated Excel, but I remember a lot of calls to functions such as GetActiveWorkbook(), GetActiveSheet().
A good thing is to explicitly make the application visible to the user; you might have a second instance of Excel running.
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
Hi Roger,
Thanks very much for the response. In answer to your questions... msp_excel is a pointer to the "Application Object" defined as _ApplicationPtr and yes, though strange and at least in the wrapper files (.tlh and .tli) generated by the #import, the Selection is associated with the Application Object, not the sheet.
Another strange thing to me is that a Selection does not seem to be an object at all when using #import (no ISelectionPtr or equivalent) whereas in in the documentation (99.99% for VB, as I'm sure you know ) it appears to be an object with VB syntax like:
appObject.Selection.Font.Style = "bold"
I would expect to be able to use something like the following to get a range that corresponded to the selection:
msp_excel->GetSelection()->GetRange();
Since it seems that you need a range for nearly everything that you do in Excel, getting a range for the current selection seems like such a common and trivial thing to do, I can't help but feel I am really missing something fundamental here...
Thanks,
Doug
Doug Knudson
|
|
|
|
|
I suggest you read some about how to automate Excel.
Have a look in the references section in this article[^] and see if you can find anything useful for you.
I don't think the article itself is of any use for you, but the links may very well be.
Hope this helps
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
Can somebody help me ...
In my FTP application i need to get the size of the file or bytes transferred in uploading or downloading .
What is the suitable API for achieving this???
Thanks in advance
Shikha
|
|
|
|