|
Something is wrong other than in the code snippet you've provided. Try this. Create a dummy SDI application. Add a CString variable to the document class, and assign it a value in the document's constructor. Modify the Serialize() method to write that variable to the archive. Run the app and then close it. When asked for a file to save to, pick something that you don't mind overwriting. Now open that file as binary using Visual Studio. Do you see the correct value?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
When I did what you suggested I did see the string in the file. I am not sure what is going on. COuld you please explain. One more thing, I can overwrite a file, but am unable to create new files. Would greatly appreciate any help.
|
|
|
|
|
TUMB wrote:
When I did what you suggested I did see the string in the file. I am not sure what is going on. COuld you please explain.
Go ahead and add a few more member variables (e.g., int, float) to the document class. Then modify the Serialize() method to load and store these new variables. To more closely mimic what your original application was doing, put the CString variable in between the other two.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I did the following
void CEX1Doc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
ar << m_nInt;
ar << strName;
ar << fFloat;
}
else
{
// TODO: add loading code here
ar >> m_nInt;
ar >> strName;
ar >> fFloat;
}
}
When I view the file in Notepad, I see the string but the rest are only boxes. Thanks for being so patient. This is the first time I am using Serialize to save Data. AS you said there is something wrong with the code. It can only save on an existing file, but if I enter a new FileName, It is giving me the following error.
filecore.cpp
Line 238
Thanks once again for all the help
|
|
|
|
|
TUMB wrote:
When I view the file in Notepad...
Notepad is a poor choice for viewing serialized (i.e., binary) files. Use Visual Studio instead.
TUMB wrote:
but if I enter a new FileName, It is giving me the following error.
filecore.cpp
Line 238
Have you looked at line 238 of FileCore.cpp?
I know why the assertion itself fires, but I don't know why the file has not been opened at that point. I dummied up an SDI application just now and it worked fine. The only additional thing I added that was not mentioned before is a call to SetModifiedFlag(TRUE) inside if the OnNewDocument() method (right before the return statement). Something like:
CMyDoc::CMyDoc()
{
m_nAge = 26;
m_strName = "Crow, David";
m_dPay = 12.34;
}
BOOL CMyDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
SetModifiedFlag(TRUE);
return TRUE;
}
void CMyDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar << m_nAge;
ar << m_strName;
ar << m_dPay;
}
else
{
ar >> m_nAge;
ar >> m_strName;
ar >> m_dPay;
}
} Run this as is. Close the application. When prompted, enter a filename. Comment out the initialization in the document's constructor. Set a breakpoint in the Serialize() method. Run the code again. The three variables should hold assigned the contents of the file. Yes?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
You're not using the << operator in conjunction with ReadString() are you?
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
|
I am writing visual C++6.0 to read in a HTML document and modify it programmatically. I can successfully create a web browser object and navigate to the document. I also can successfully locate buttons and checkbox types and cause them to click. I am having problems with input type "text" that uses onKeyUp to navigate to a function and fill
in edit boxes. If anyone can help me with this, I would surely appreciate it.
Freeman Taylor
Freeman Taylor
|
|
|
|
|
You've not specified exactly what it is you are wanting to do. Saying that "I am having problems with input type..." is not very descriptive.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
There is an input field on the HTML page to type a file name.
This is the code in the HTML document to handle it:
.RDF
onByCollectionFilenameChange() is the function that it jumps to and builds a download path to the 'C' drive with the file name. I can't programmatically cause this to happen.
|
|
|
|
|
Freeman Taylor wrote:
I can't programmatically cause this to happen.
This is still unclear to me at least. If you are saying that you want to call onByCollectionFilenameChange() from your C++ code then yes this is possible. See this article: http://www.codeproject.com/com/jscalls.asp[^]
You can call JS code from C++ and vice-versa. I do this in Surfulater (see sig).
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
I have a textbox that I'm using CFontDialog to change the font of. That works, but it also changes the font for every other control on the dialog as they're repainted. For instance, a command button will have its same font until I click on it, at which time the font changes to some big, ugly, bold font (maybe some type of default system font). I think that somehow the dialog's font is getting set to nothing because I tried opening up the font dialog sending in the dialog's current font and it's set the first time, but the next time I open up the font dialog, nothing is selected like I have no font for my dialog. Here's what I have:
ZeroMemory(&m_Font,sizeof(LOGFONT));
CFont* pFont = m_LockEdit.GetFont();
pFont->GetLogFont(&m_Font);
CFontDialog dlg(&m_Font);
dlg.m_cf.Flags |= CF_TTONLY;
if(dlg.DoModal() == IDOK)
{
LOGFONT lgfnt;
dlg.GetCurrentFont(&lgfnt);
m_cFont.DeleteObject();
m_cFont.CreateFontIndirect( &lgfnt );
m_LockEdit.SetFont( &m_cFont, TRUE );
pFont->DeleteObject();
}
[insert witty comment here]
bdiamond
|
|
|
|
|
The last line in your code
pFont->DeleteObject() is deleting the font you just created. That causes Windows to draw the text using the default font.
Software Zen: delete this;
|
|
|
|
|
hi any body can give me some client server application examples for serial port communication in VC++. My requirement is server will be always listening on the serial port for receing the messages from client. client only will send messages to the server.
Pls help me in this regard, it's kinda urgent..
thanks in advance..
|
|
|
|
|
Hi,
Can anybody let me know the conversion function/method which will convert the TCHAR* to numeric (int/decimal).
Actually I fetch the values from the database, bind it to an two dimentional array of type TCHAR. The values will look something like this.
Value in database column is 100000 (numeric).
TCHAR colNameArray[256][256];
I bind the database column to array colNameArray. And the value appears like this as given below.
colNameArray[0][0] = 160
colNameArray[0][1] = 134
colNameArray[0][2] = 1
colNameArray[0][3] = 0
Which is actually 160 + 134*(256) + 1*(256^2) = 100000.
I am looking for some method which would take colNameArray as input as convert to to a string (ascii) or to integer or to numeric.
Converting to string is quite ok, so that I could convert to appropriate data types later.
Thanks in advance.
Prashant.
|
|
|
|
|
TCHAR is defined as
<br />
typedef wchar_t TCHAR;<br />
so you can use the function below including <stdlib.h>
<br />
long _wtol(<br />
const wchar_t *string <br />
);<br />
don't understand what you doo below, hope I helped you
|
|
|
|
|
Yes I could have used _wtol if I was able to read the number as a string, but I am not able to see the number as string as explained in my question above.
So I am actually looking for a method to first convert the value to string or w_string then go on to convert to numeric.
- Prashant
|
|
|
|
|
How about:
x = colNameArray[0][0] + colNameArray[0][1]*256 + colNameArray[0][2]*65536 + colNameArray[0][3]*16777216;
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
This works fine for an integer, thats true.
But I could as well get a float/double, date-time, etc. So I was looking for some method which would convert this data to a string (ASCII). Later using atol, atof etc I could convert to the appropriate data type.
Thanks
|
|
|
|
|
I mostly understand what you are asking for, but I'm not sure we are yet on the same page. By using a TCHAR array, the values stored in that array can range from -128 to 127. The 160 and 134 you have stored in there now won't work unless you change the type to be TBYTE instead. TBYTE works with values from 0 to 255.
PrashantJ wrote:
But I could as well get a float/double, date-time, etc.
You would not be able to store 12.34 into a type TCHAR or TBYTE .
Out of curosity, since the database column is numeric, why not bind it to a numeric type?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hello,
I only have two quick questions to ask you and they are:
- Can one implement DLLs in VC with MFC support?
- How does one do about retrieving the taskbar window handle (HWND or CWnd )?
Thanks a lot,
David
|
|
|
|
|
How does one do about retrieving the taskbar window handle (HWND or CWnd)?
HWND hTaskBar = FindWindow("Shell_TrayWnd", NULL);
I am not sure about first question, I think you can probably do it!
ARSALAN MALIK
|
|
|
|
|
dNimrod#X wrote:
Can one implement DLLs in VC with MFC support?
Yes. Remember that DLLs existed long before MFC came about.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
That's great!
By the way, will I have to take special care about any particular issue(s) related to developing a DLL with MFC support?
David
|
|
|
|
|
With AppWizard, you can create two types of DLL projects: MFC and Win32. With MFC, you can create a:
regular DLL with MFC statically linked
regular DLL with shared MFC DLL
MFC extension DLL.
Search MSDN for examples of each.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|