|
Yes.
A typical DoDataExchange is a bunch of DDX_??? and DDV_??? calls.
If you place an if block ahead of all these and check pDX->m_bSaveAndValidate to be true, you can do any checking you want to prior to the 'collection' of the data from the control's back into your member variables. If you don't like something, then you can call pDX->Fail()
The UpdateData is not supposed to be called if the user 'cancels' the dialog box, but it will be called if they press OK. You can then handle the validation in the DoDataExchange. If the DoDataExchange fails, then the dialog will not exit with the OK button.
You can also write your own DDV_ routines and then use them within your project. I have written all sorts of different ones to verify files exist, folders exist, numbers within a certain range, strings don't contains certain characters, etc. They work great. Just use the ones within the MFC source code as a starting point to guide you on creating your own.
|
|
|
|
|
I write a class by C++, in this class use string. For exsample:
#include "string"
using namespace std;
int exsample{}
{
string strTest;
......
}
I compile by Visual C++.NET. I get a lot of errors:
(Compile by Visual C++ 6, no Errors)
Compiling...
wmutility.cpp
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(862) : error C2143: syntax error : missing ';' before '<'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(935) : see reference to class template instantiation 'std::istreambuf_iterator<_Elem,_Traits>' being compiled
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(862) : error C2238: unexpected token(s) preceding ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(863) : error C2143: syntax error : missing ';' before '<'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(863) : error C2238: unexpected token(s) preceding ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2143: syntax error : missing ')' before '*'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2143: syntax error : missing ';' before '*'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2864: '_Sb' : only const static integral data members can be initialized inside a class or struct
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2501: 'std::istreambuf_iterator<_Elem,_Traits>::_Sb' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2143: syntax error : missing ';' before 'throw'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(871) : error C2143: syntax error : missing ')' before '&'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(871) : error C2143: syntax error : missing ';' before '&'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(871) : error C2059: syntax error : ')'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(871) : error C2143: syntax error : missing ';' before 'throw'
Please help me this problemp.
Thank you very much!
|
|
|
|
|
Best guess - your code is not standards compliant, but VC6 allowed it, in error. You're saying all you need to do is include the string class and these errors occur ?
EDIT
Apparently, if your file is named .c, instead of .cpp, you can get this error because the compiler will assume it's c and not C++.
/EDIT
EDIT3
#include "string" is wrong. It's #include<string>
/EDIT3
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thank for your reply!
My file is name .cpp, but it write flowing C standard. It run very best with Visual C++6. But when I convert to Visual C++.NET (open file .dsp by Visual C++.NET), I get a lot of errors:
I think so it errors at:
#include<string>
using namespace std;
I don't understand why?
Have you any idea for this problem?
My file
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<math.h>
#include<string>
using namespace std;
#include "utility.h"
typedef unsigned char u_char;
#define for if ( 0 ) ; else for
int bmp_flag;
int encode( )
{
string data;
..............
}
|
|
|
|
|
SAKURAVN wrote:
#include<malloc.h>
Why ? You should NEVER malloc in a C++ program without good reason.
SAKURAVN wrote:
#include<string.h>
#include<math.h>
These are deprecated
SAKURAVN wrote:
#include<string>
using namespace std;
You've just pulled ALL of std:: into the global namespace. Although it's generally better to only pull in what you need, in this case it is moot. string.h would include string as a class, and string is now conflicting with it. Get rid of the non standard header ( and replace the others with standard ones by dropping the .h ) and see how you go.
SAKURAVN wrote:
typedef unsigned char u_char;
BYTE is a typedef for unsigned char. unsigned by itself also defaults to unsigned char, I believe.
SAKURAVN wrote:
#define for if ( 0 ) ; else for
What is this ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
If I ignore //#include<string>
//using namespace std;
It not errors.
I don't write by C standard very much, I can not understand.
Can you advise me the way fix it.
|
|
|
|
|
SAKURAVN wrote:
I don't write by C standard very much, I can not understand.
Sure, no worries.
Basically, before there was a C++ standard, classes like string.h and iostream.h contained what existed of what eventually became the standard library. When the standard was ratified, the new headers were named without the .h. These new headers wrap everything in a namespace, called std. So, by including string.h AND string, you include two classes with the same name. If you used std::string everywhere and got rid of the using statement, you could do this. Otherwise, you have two classes of the same name trying to co-exist in the global namespace. Drop all references to string.h, replace them with string. So, reverse what you did above to make your code compile. The .h headers are deprecated, which means that in theory they could disappear one day, because they are not standard. Do the same with math.h and iostream, if you use it. Basically, anything in <>, try dropping the .h to see if it's deprecated.
Now, moving on, why do you include malloc.h ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Sorry! I don't use malloc.h
if in .cpp file oly have #include <string>
using namespace std;
It still errors:
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(862) : error C2143: syntax error : missing ';' before '<'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(935) : see reference to class template instantiation 'std::istreambuf_iterator<_Elem,_Traits>' being compiled
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(862) : error C2238: unexpected token(s) preceding ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(863) : error C2143: syntax error : missing ';' before '<'
|
|
|
|
|
SAKURAVN wrote:
Sorry! I don't use malloc.h
Great - remove it then
SAKURAVN wrote:
if in .cpp file oly have #include <string>
using namespace std;
Then you must have other cpp files that include the wrong thing. If I create a project that includes the right headers, it's not a problem. When I try to use the right headers on legacy projects I inherit, I get this same issue, and it's because someone else has written crappy code elsewhere in the system. You need to search for string.h throughout the project, and correct it every time.
Personally, I tend to include standard libraries in the stdafx and put the using statements I need in my cpp files.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
//I create a table A in the Oracle.Please see the follow
CREATE TABLE A
(
ID NUMBER(7) primary key
);
//Now ,I want to insert a reocrd in the table A;
_ConnectionPtr pConn=NULL;
pConn.CreateInstance(__uuidof(Connection));
_RecordsetPtr pRst=NULL;
pRst.CreateInstance(__uuidof(Recordset));
pConn->Provider="OraOLEDB.Oracle.1";
try
{
pConn->Open("","ISVISION","ISVISION",NULL);
pRst->CursorLocation=adUseClient;
pRst->Open("A",pConn.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdTable);
pRst->AddNew();
pRst->Fields->Item[0L]->Value=100L; //But it throw a excpetion here. I dont know the reason. If I alter the datatype of ID to CHAR(10) ,it is all right.
//这里就会出现异常,如果表A的ID的数据类型是CHAR(10)的,又不会出错?
pRst->Update();
pRst->Close();
pConn->Close();
}
catch (_com_error& e)
{
MessageBox(e.Description(),"error",MB_OK|MB_ICONWARNING);
return ;
}
if (pConn)
pConn.Release();
if (pRst)
pRst.Release();
|
|
|
|
|
How many times were you intending to ask this question ?
What is the type of Value ? Is it a VARIANT ? If so, try setting up a variant, perhaps _variant_t (100L) will work. Or otherwise, it's possible that it's looking for a BSTR.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
szcococut wrote:
lpCmdLine
This is the string that is passed in.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
The really odd thing about command line argument handling is that MFC itself uses __argc and __argv to parse its arguments but gives it to apps as one single string. It makes no sense at all to me. Any app can include stdlib.h and access each individual argument if it wants to.
|
|
|
|
|
Hi all,
I am a Visual C++ Developer using V6.0. Mostly I deal with MFC creating windows application.
What are your opinions about me upgrading to Visual C++.Net 2005? It seems to be quite different from V6.0 from what I see. If I develop applications using MFC in .Net 2005, are there any issues that I should watch out for?
What about manage and unmanaged code and the .Net framework? When I distribute my software, do I need to distribute the .Net framework for older OS such as Win98?
Please give me your comments.
|
|
|
|
|
desmondling78 wrote:
If I develop applications using MFC in .Net 2005, are there any issues that I should watch out for?
Yeah, lots.
1. VC6 is TERRIBLE at standards conformace. You've missed two iterations, there is a lot of stuff that used to compile and now will not, due to being non-conformant. How well do you know/code to the C++ standard ? One obvious example is this
for (int i = 0; i != 6; ++i)
{
}
int x = i;
According to the standard, this code should fail, i is not visible outside the scope of the loop. VC6 will accept it.
2. MFC has changed a bit in the years between as well, but all for the better as far as I can tell, and not too much ( the focus is on C#/Winforms IMO ).
desmondling78 wrote:
What about manage and unmanaged code and the .Net framework? When I distribute my software, do I need to distribute the .Net framework for older OS such as Win98?
No, C++ is the only language that you can use the .NET compiler for and not require the runtime. You can choose to use/require it if you want to, but you don't have to.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
Thanks for your reply.
How well do you know/code to the C++ standard ?
Well, I do a fair bit of development in C++. I suppose I would rate myself an average developer? Currently, I'm learning VB.Net including ASP.Net. And I have a basic understanding on .Net framework. (.Net's Quite cool actually!) For the example you gave, luckily I don't do that. (Phew). Since .Net has changed a lot, where do you think I should start so as to get myself up-to-date?
No, C++ is the only language that you can use the .NET compiler for and not require the runtime. You can choose to use/require it if you want to, but you don't have to.
I'm a little bit confused. Because there are people telling me this:
If I develop an application that uses the .Net framework (such as the Systems namespace), then I need to ensure Win98 has the .Net framework installed before it will run. is that right?
|
|
|
|
|
desmondling78 wrote:
Well, I do a fair bit of development in C++. I suppose I would rate myself an average developer?
Sure - the best thing to do is get a copy of the beta and see if your code compiles. If you've learned from reading books, you should be fine. If you've learned by seeing what the compiler accepts, you could be in trouble.
One other bit of good news, if you use the STL, the STL that comes with .NET is a world away from the VC6 one, the VC6 one is crap.
desmondling78 wrote:
Currently, I'm learning VB.Net including ASP.Net
Why not C#, given that you have a C++ background ? VB.NET syntax is really hard to get used to, compared to C#, if your background is in programming ( that is, C++ rather than VB6 ).
desmondling78 wrote:
Since .Net has changed a lot, where do you think I should start so as to get myself up-to-date?
Well, you don't need .Net to do C++, in fact you can't have it if you don't want to depend on the framework. If you're asking from the ASP.NET angle, I'd say still buy some good ASP.NET 1.1 books, then read on 2.0 later, because not so much has changed, stuff has been added.
And one other thing - C# 2.0 has some really cool features like templates, iterators, and anonymous methods. I don't know if VB.NET gets any of that, yet.
desmondling78 wrote:
I'm a little bit confused. Because there are people telling me this:
If I develop an application that uses the .Net framework (such as the Systems namespace), then I need to ensure Win98 has the .Net framework installed before it will run. is that right?
Absolutely, and in a lot of ways, obviously. ANY OS right now does not come with the framework preinstalled. The thing is, C++ is the only place where you CHOOSE to use the .NET framework, C# and VB.NET cannot live without it. So you will KNOWINGLY make your app rely on .NET ( the MFC app, this is ), but you can also choose not to add this dependancy.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
One other bit of good news, if you use the STL, the STL that comes with .NET is a world away from the VC6 one, the VC6 one is crap.
Really? Then I have to check it out. Cos STL is a really useful tool.
Why not C#, given that you have a C++ background ? VB.NET syntax is really hard to get used to, compared to C#, if your background is in programming ( that is, C++ rather than VB6 ).
Well, people have been asking me that question. Reason is for market value. There seems to be less work for vc++. Also, I wish to move to web applications. and VB.Net seems to be the way to go. But like you said it takes time to get used to VB syntax (and frankly i prefer C++ syntax).
So you will KNOWINGLY make your app rely on .NET
I see. Just one more last question then. The main reason for using Managed code is that it helps us handle garbage collection right? And that is provided by the .Net framework?
Oh and one more question. When Visual C++.Net 2005 is released, will Microsoft still sell Visual C++.Net 2003? I am deciding on which to buy, but I wish to wait for the release of Visual C++.Net 2005. (I heard from some Microsoft Spokes person that it is slated for July~Aug released.) I'm just afraid by then, will they stop selling .Net 2003 (as is threatened by my suppliers).
|
|
|
|
|
desmondling78 wrote:
Really? Then I have to check it out. Cos STL is a really useful tool.
It's THE reason to upgrade IMO. In Microsoft's defence, the STL in VC6 was sold to them by Dinkumware, they were bound to it by contract. Dinkum knew all about their STL bugs, they went on to make money selling a replacement STL, which in effect meant you paid for the bugfixes on what they sold to Microsoft.
desmondling78 wrote:
Well, people have been asking me that question. Reason is for market value. There seems to be less work for vc++. Also, I wish to move to web applications. and VB.Net seems to be the way to go. But like you said it takes time to get used to VB syntax (and frankly i prefer C++ syntax).
No, I'm asking why you don't write ASP.NET apps in C# instead of VB.NET, because the C# syntax is easier for a C++ programmer, because C#2.0 has compelling features for a C++ programmer, and because VB.NET is full of really crappy legacy stuff.
desmondling78 wrote:
I see. Just one more last question then. The main reason for using Managed code is that it helps us handle garbage collection right? And that is provided by the .Net framework?
IMO the main reaons to use managed C++ are if you want to provide a bridge between C# and C++, or because you want access to stuff in the class libraries, for example, regular expressions. Garbage collection is worth nothing to me.
desmondling78 wrote:
When Visual C++.Net 2005 is released, will Microsoft still sell Visual C++.Net 2003?
I doubt it very much.
desmondling78 wrote:
I am deciding on which to buy, but I wish to wait for the release of Visual C++.Net 2005.
It's out in November. If you're going to do ASP.NET, go for 2005, definately. ASP.NET 2.0 has heaps of cool new stuff, and in addition, C# 2.0 has a lot of compelling features that should make you seriously reconsider VB.NET. Amongst them is the fact that ASP.NET apps can have pages written in both, so if you have to work on a crappy VB.NET project ( I say this because every VB.NET project I've been called in on was poorly written crap ), you can still write C# pages for it, if you want to.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Garbage collection is worth nothing to me.
haha its funny you said that. I thought its quite a useful thing considering we need not worry about memory leaks.
No, I'm asking why you don't write ASP.NET apps in C# instead of VB.NET, because the C# syntax is easier for a C++ programmer, because C#2.0 has compelling features for a C++ programmer, and because VB.NET is full of really crappy legacy stuff.
Ohh. Because I wish to pick up VB.Net as well. I suppose I can learn C# on my own time and it will be easier since I know C++. The main reason is I wish to be all-rounder...hoping to jack up my value! hah
What are the improved features of Visual C++.Net 2005 compared to Visual C++.Net 2003 anyway?
|
|
|
|
|
desmondling78 wrote:
haha its funny you said that. I thought its quite a useful thing considering we need not worry about memory leaks.
It's a nice story, but it's not true. If you allocate large objects, you still need to clean up after them, or they will linger for ages.
desmondling78 wrote:
Ohh. Because I wish to pick up VB.Net as well.
Fair enough. Personally, I'd rather hammer nails into my head, but to each his own
desmondling78 wrote:
What are the improved features of Visual C++.Net 2005 compared to Visual C++.Net 2003 anyway?
Another 20 breaking changes for standards conformance. I was talking C#, the improved features include iterators, generics, anonymous methods, etc. The IDE has a lot of cool new stuff as well, including an XSLT debugger, if you're into that sort of thing.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Fair enough. Personally, I'd rather hammer nails into my head, but to each his own
Haha ok. I get what you mean. There are already lots of nails in my head
Hey thanx man. You're provided me with lots of info. Kudos!;)
|
|
|
|
|
desmondling78 wrote:
Haha ok. I get what you mean. There are already lots of nails in my head
Hell, I used to write asp websites, so I've got my fair share as well :P
No worries, glad to help
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
It's a nice story, but it's not true. If you allocate large objects, you still need to clean up after them, or they will linger for ages.
Most things are a trade-off but I'd rather have garbage collection than not have it. Language designers such as Gosling, Heljsberg and Meyer seem to have reached that conclusion too. They could all be wrong I suppose.
Kevin
|
|
|
|
|
desmondling78 wrote:
Ohh. Because I wish to pick up VB.Net as well. I suppose I can learn C# on my own time and it will be easier since I know C++. The main reason is I wish to be all-rounder...hoping to jack up my value! hah
I think it's certainly worthwhile being able to read the syntax of both languages. That way you can translate samples from one to the other when required.
Kevin
|
|
|
|
|