|
A very simple and realistically non-worthwhile implementation is simple. Your malloc calls new with an byte array. Then your free, which you would also implement would use delete to delete the array.
If you want a learning experience however then you should do the following in the specified order.
1. Learn what stack and list are and how to implement them.
2. Specifically learn how to implement them using sequential memory and not just pointers.
3. Learn how malloc is generally implemented. You will need substantial understanding of 1/2 to understand this.
4. Implement your own heap management. (Which you will understand after doing 1/2/3.)
|
|
|
|
|
I never use VC++ to develop an app that use to connect and update database before.
My app is design to allow user to update the database by supply MS Excel file.
When the app open, user need to choose either connect to MS Access 2010 (.mdb) or MSSQL 2014 express.
By using MFC Application Wizard, I need to choose which client type to use at Database support section (ODBC or OLEDB).
After reference to the doc on the web. Seems that OLEDB suitable for Access and ODBC suitable for MSSQL.
This make me has a difficulty to choose between them during start.
Or I should create a project that has no database support at start, then add DLL that support database to this solution later.
But the wizard that use to create MFC DLL and ATL Project has no section for choose database support.
Any advice and suggestion that direct me how to start is appreciated.
|
|
|
|
|
There are no limitations to support different types of databases in one application. The application wizard only prepares the project to support a specific database interface. Support for other interfaces can be added later manually.
My suggestion:
Create two new empty projects with support for different database interfaces. Then choose one as your project and add the necessary definitions from the created source files of the other project by comparing the files.
|
|
|
|
|
Thanks for reply.
Since wizard can relief my work. I just think is it possible to select both ODBC and OLEDB by using wizard.
If it is not possible, I have to implement the code myself.
That's hell a lot of work
|
|
|
|
|
The selection uses radio buttons. So only one can be selected.
You must write the code to access the database anyway. The wizard will not do that. It just prepares your project. Merging two empty projects into one is not much work.
|
|
|
|
|
Note that reading even a trivial excel file in an application can be a difficult task.
Once you have read the data the user interface and writing to a database is easier because there are more sources that one can learn from.
|
|
|
|
|
I added one extra "copy path" option in windows 7 context menu using regedit ...
when I right click on any file and select "copy path" option the path of that file should get copied to txt file
plz help me out ....I m working on one project where I need this...
|
|
|
|
|
What is the C/C++/MFC question here?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
|
|
|
|
|
|
When read big excel file, it takes many time to read cell one by one.
|
|
|
|
|
|
I'm Using Library for Office
// Loop through the data and report the contents.
for (int rowCounter = 1; rowCounter <= iRows; rowCounter++) {
for (int colCounter = 1; colCounter <= iCols; colCounter++) {
index[0]=rowCounter;
index[1]=colCounter;
COleVariant vData;
saRet.GetElement(index,vData);
CString szdata(vData);
valueString += szdata;
valueString += "\t";
}
valueString += "\r\n";
}
In this example, it's using loop to read cells, the reading speed is not good.
|
|
|
|
|
Which library?
lichengbyd wrote: In this example, it's using loop to read cells, the reading speed is not good. It is using the loops to extract the values from the safe array. But the data are already in memory of your application. You missed the call that retrieves the data from Excel:
COleSafeArray saRet(oRange.get_Value(covOptional));
|
|
|
|
|
Indeed, thanks for you infomation!
|
|
|
|
|
Hi all!,
I've been working on a code to develop a tracking game with a haptic device as controller. I use library Chai3D and OpenGL.
I need to save some information of the game during the program execution. And write into a txt file.
I'm attaching part of my code where mentioning vector objects need to be saved:
void updateHaptics(void)
{
while(simulationRunning)
{
cVector3d newPosition1,newPosition2;
hapticDevices[0]->getPosition(newPosition1);
hapticDevices[1]->getPosition(newPosition2);
cMatrix3d newRotation1, newRotation2;
hapticDevices[0]->getRotation(newRotation1);
hapticDevices[1]->getRotation(newRotation2);
cursors[0]->setPos(newPosition1);
cursors[1]->setPos(newPosition2);
cursors[0]->setRot(newRotation1);
cursors[1]->setRot(newRotation2);
cVector3d linearVelocity1, linearVelocity2;
hapticDevices[0]->getLinearVelocity(linearVelocity1);
hapticDevices[1]->getLinearVelocity(linearVelocity2);
velocityVectors[0]->m_pointA = newPosition1;
velocityVectors[0]->m_pointB = cAdd(newPosition1, linearVelocity1);
velocityVectors[1]->m_pointA = newPosition2;
velocityVectors[1]->m_pointB = cAdd(newPosition2, linearVelocity2);
double Kp = 60.0; double Kb = 3.0;
cVector3d newForce (0,0,0);
cVector3d coupledForce1 = cMul(Kp, (newPosition1-newPosition2))-(cMul(Kb, (linearVelocity2)));
newForce.add(coupledForce1);
hapticDevices[1]->setForce(newForce);
cVector3d newForce1 (0,0,0);
cVector3d coupledForce2 = cMul(Kp, (newPosition2-newPosition1))-(cMul(Kb, (linearVelocity1)));
newForce1.add(coupledForce2);
hapticDevices[0]->setForce(newForce1);
}
simulationFinished = true;
}
On the above code I need to save these objects into a file
cVector3d newForce
cVector3d NewForce1
Please help me how to make a provision to save these file effectively into a txt file.
Basically I dont have much idea on saving , writing into files.
Thanks in advance!
|
|
|
|
|
There is an edit link below your post which should be used rather than posting a new question.
There is also a delete link. Please use that to delete your first question.
To write the elements to a text file, you may open the file using fopen() and then print the elements using fprintf() :
FILE *f = fopen(fileName, "wb");
fprintf(f, "%lf %lf %lf\r\n", newForce.x, newForce.y, newForce.z);
fprintf(f, "%lf %lf %lf\r\n", newForce1.x, newForce1.y, newForce1.z);
fclose(f);
Depending on the required accuray it may be necessary to specify the number of significant digits to be printed (see the printf() format specifications).
[EDIT]
The above is for Windows text files. For Unix text files remove the '\r' from the fprintf() format strings.
|
|
|
|
|
Hey Thank you Jochen!.
Im just wondering how can i make use of a buffer where intitially I can dumb my data..and once the execution is completed writing into a file..do you have a suggestion?.
|
|
|
|
|
You can do it similar using sprintf() to print to a buffer and then write the buffer to file:
char buffer[128];
char *p = buffer;
int n = sprintf(p, "%lf %lf %lf\r\n", newForce.x, newForce.y, newForce.z);
s += n;
sprintf(p, "%lf %lf %lf\r\n", newForce1.x, newForce1.y, newForce1.z);
FILE *f = fopen(fileName, "wb");
fwrite(buffer, 1, strlen(buffer), f);
fclose(f);
But as you can see this is much more code and it is insecure without checking for buffer overflows (which adds more code).
If you don't need the data to be in text format (e.g. only loaded by your application), it might be better to write the data to a binary file. That solves also the problem of inaccuracies when converting floating point values to text and back again later.
Example:
FILE *f = fopen(fileName, "wb");
fwrite(&newForce.x, sizeof(newForce.x), 1, f);
fclose(f);
Reading is then done in a similar way:
FILE *f = fopen(fileName, "rb");
fread(&newForce.x, sizeof(newForce.x), 1, f);
fclose(f);
|
|
|
|
|
Many thanks Jochen!! .
I'm planning to use just one file containing information about two forces, something like this:
timestamp newforce(X Y Z) newForce1(X Y Z))
where the values of x,y,z will be in column.
fprintf(pFile, "%lf %lf %lf\r\n %lf %lf %lf\r\n", newForce.x, newForce.y, newForce.z, newForce1.x, newForce1.y, newForce1.z);
do you think it's a right assignment?, I mean how can I write data effectively into the file with proper indentation?
|
|
|
|
|
You can use the printf format specifiers (see http://www.cplusplus.com/reference/cstdio/printf/[^]).
Using the width specifier, all numbers will have the same width padded with blanks. For proper alignment of the decimal point you should also use the precision specifier and the flag specifier (use a space or minus). The final values to be used depend on the range of your values and the required precision. Assuming a range up to (but excluding) 100 and a precision of 2 fractional digits:
Precision = 2
Width = 1 (sign) + 2 (digits) + 1 (decimal point) + 2 (digits) = 6
Then use the format "% 6.2f" for each value:
fprintf(pFile, "% 6.2f % 6.2f % 6.2f\r\n% 6.2f % 6.2f % 6.2f\r\n",
newForce.x, newForce.y, newForce.z, newForce1.x, newForce1.y, newForce1.z);
For the time stamp you can use the strftime()[^] function.
modified 18-Mar-15 13:08pm.
|
|
|
|
|
I tried as u suggested , but now the data I'm getting is kind of overflowing, I mean it's always generating a data txt file of 1kb!!
|
|
|
|
|
You may give an example of your data. Inspecting the text file may also give a hint what is going wrong.
[EDIT]
I have replaced the usage of "%lf" by "%f" in my post. But this should make no difference with MS compilers.
modified 18-Mar-15 13:09pm.
|
|
|
|
|
Hi Jochen,
I'm getting data like this
18832315686612578000000000000000000000000000000000000000000000000000.00 18832315686612578000000000000000000000000000000000000000000000000000.00 18832315686612578000000000000000000000000000000000000000000000000000.00
18832315686612578000000000000000000000000000000000000000000000000000.00 18832315686612578000000000000000000000000000000000000000000000000000.00 18832315686612578000000000000000000000000000000000000000000000000000.00
It's 2 raws of numbers..3,5 lines are continuation of 1st line..ans so 4,6 ..
It's basically limited to 1kb irrespective of the duration of experiment
|
|
|
|
|
That are quite large numbers. Are they the correct values? If your numbers are in that range, you should use the "%E" format.
|
|
|
|
|
Hi Jochen,
Now it's working perfectly!. I did a a mistake in closing the file. Thank you so much for your prompt and precise feedback!.
|
|
|
|