|
I was just wondering what the 'right' way to save data from a listbox is because so far i've always just written functions that get the text from each item and write it to a file with a seperator like '\n' or something. Isn't there like a universal way to save the data??
Kuniva
|
|
|
|
|
No, You have not a universal way to save the data, You can save de data in files or in the registry...
If you use the CStdioFile class, you can save the data in very few steps...
Best Regards...
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
I was just wondering....
In visual basic you have two modes of filewriting: random access and binary or something. With the random thing you can specify a string to write and an index so it will automatically give the string an index in the file. I'm not sure how this works but i would like to know if there's a similar thing in MFC?
Kuniva
|
|
|
|
|
I'm sorry you don't have something like random access, but you have binary access or Text Access and different modes like, Write, Read, etc...
Look in CFile::CFile();
Best Regards!!!
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
oh, ok then, Thanks for your help!
Kuniva
|
|
|
|
|
oops, i took a look in the MSDN and there appears to be something as random file access afterall i think, allthough i dont fully understand it, here's what it said:
CFile::Seek
This method repositions the pointer in a previously opened file. The Seek method permits random access to the contents of a file by moving the pointer a specified amount, absolutely or relatively. No data is actually read during the seek. If the requested position is larger than the size of the file, the file length will be extended to that position, and no exception will be thrown.
Kuniva
|
|
|
|
|
The Seek make that you can move into the file, the bytes that you enters in the first parameter...
If you want to go to the beguin of the file you must to put 0 or CFile::begin in the second parameter.
You can read from that position.
For example if you have that you need to read 4 bytes from the 30th byte, you need to do
<br />
...<br />
pFile.Seek(30, CFile::begin);<br />
pFile.Read(pbuf, 4);<br />
...<br />
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
In Python there is a method called CPickle which will dump data structures into a binary file. that way many executables could share a data structure. It was accomplished using C. Does anyone know how this could be achieved for MFC's template data structures.
-JD
|
|
|
|
|
If it's just data, then no problem If they're classes, with virtual functions, then it's a big problem. Part of your data includes the virtual function table, which will not be the same between processes (or even between invocations of the same program).
Simply:
fwrite(&data, sizeof(data), 1, file);
--
Where are we going? And why am I in this handbasket?
|
|
|
|
|
> If they're classes, with virtual functions [...]
Or even structures with virtual functions...
> If it's just data, then no problem
You do, of course, need to be smart enough to consider alignment and packing issues (and sometimes endian-ness!) when dealing with reading and writing data structures in such a way.
Peace!
-=- James.
|
|
|
|
|
can anyone tell me what the include file is for WM_KICKIDLE??? When i try to compile it tells me that WM_KICKIDLE is an undeclared identifier.
Kuniva
|
|
|
|
|
|
thanks, damn why didn't i think of that...
Kuniva
|
|
|
|
|
Could you please explain me what WM_KICKIDLE is for?
Never heard about it...
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Kick idle is an internal MFC message used to support idle time processing.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
WM_KICKIDLE is a Hook. It force an idle to kick
RunModalLoop sends this MFC-private message repeatedly when there are no messages in your dialog's queue—just the way CWinThread::Run calls OnIdle.
Look in the MSDN and you will see several samples using WM_KICKIDLE...
Best Regards....
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
I've had to do that so often.
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
WM_KICKIDLE defined in AFXPRIV.H header file
Philip Patrick
"Two beer or not two beer?" <shakesbeer>
Web-site: www.saintopatrick.com
|
|
|
|
|
Does anyone know of a way (I would guess it would use macro's) to execute a string which represents a line of code I want to execute.
example:
CString strCode = _T("int nVariable = 3;");
-And now execute it. I know it could be done with interpreted languages like python, but I don't know about C++.
-JD
|
|
|
|
|
What do you mean "execute it"? Show it in a dialog box?
Show the string in a dialog box (MFC):
AfxMessageBox(strCode);
or Win32
::MessageBox(hWnd,strCode,"Title", MB_OK);
------------------------------
©0d3 ©®4©k3® - That's me!
------------------------------
|
|
|
|
|
I don't see how it could be done in a compiled language like C++.
However, if you can move your dynamic code to a different language (eg: Tcl), you could load an interpreter from within your C/C++ code and execute the code within the interpeter (eg: by using TclEval()).
/ravi
"There is always one more bug..."
ravib@ravib.com
http://www.ravib.com
|
|
|
|
|
You need to implement WSH host scripting. Then you should be able to use VBScript/Javascript to execute code, fire events etc...
See
http://www.codeguru.com/atl/ATL_ScriptHost.shtml
|
|
|
|
|
It can be done but it is a HUGE amount of work and, in most cases, not worth the effort. I implemented an on-the-fly machine code generator for the script engine in my company's product and it was not an easy task at all. This is similar to what JIT compilers for Java do. I actually know very little about assembly code. I just stared at a whole bunch of .cod files emitted by VC++ and sorted out how it works. Curiously, I found that VC++ only uses three data registers to do everything. Another curiosity is that the this pointer for C++ methods is not passed on the stack. It is loaded into ECX prior to the call.
Anyway, What it amounts to is you build a block of bytes of data that are machine code and set a pointer to a function to the address of the block and (*execute_it).
I think an interpreted language is probably the easiest way to go about this and there are many of them.
|
|
|
|
|
> Another curiosity is that the this pointer for C++ methods
> is not passed on the stack. It is loaded into ECX prior to
> the call.
Just an FYI: IIRC, that is the "thiscall" calling convention.
Peace!
-=- James.
|
|
|
|
|
Yes, I know it is the thiscall convention. What is amusing is that the VC++ docs describe this correctly in one place and incorrectly in another. Here is the wrong description :
This is the default calling convention used by C++ member functions that do not use variable arguments. The callee cleans the stack, so the compiler makes vararg functions __cdecl, and pushes the this pointer on the stack last.
I have seen many people refer to this being pushed on the stack and that is not what VC does. There may be some compilers that do though. I don't know for sure.
|
|
|
|