|
Without further info I do not realy understand your problem, but, the general procedure is:
Step 1. You should know the fully qualified name of the file you want to read i.e.: CString MyFile="C:\MyDirectory\MyData\DataFile.ext". If you type that as a string in your code(bad Idea, but not your immediate problem) you should type all backslashes double. i.e.:CString MyFile="C:\\MyDirectory\\MyData\\DataFile.ext".
Step 2;
You Open the file, and get a File Handle:
FILE* F =fopen(MyFile,"rb"); The "rb" means that you want to open the file for binary reading, (as opposed to Text Reading, which should be opened for reading with just "r")
Step 3: You find out how big the file is. You move the File Pointer to the End of the File, and ask where it is.
size_t CurPos=ftell(F);// Record the File Pointer
fseek(F,0,SEEK_END)
size_t FileSize=ftell(F);
fseek(F,CurPos,SEEK_SET);// Returns the FilePointer to where it was
Step 4:
Allocate a buffer to hold the File Contents
char* Buf=(char*)malloc(FileSize);
Step 5:
Ensure that there was enough free memory left to Allocate the Buffer
if(Buf==NULL) return ERR_OUT_OF_MEM;
Step 6:
Read the File into the Buffer
fread(Buf,FileSize,sizeof(char),F);
step 7:
Close the File. This is most important, Noone Else can work with the file while you have it open, Even yourself cannot open it a second time.
Step 8:
The contents of your file is now in Buf. Do with it as you like.
Step 9:
When You're done with it, you should 'free' Buf. Unlike say VB, C++ has NO garbage collection service. It is up to you to get rid of memory you no longer need.
Bram van Kampen
|
|
|
|
|
do you have any source code to read data from harddisk and print it on the screen? thanks a lot.
i am reading one book, it is still blur, thanks
Li Zhiyuan
5/10/2006
|
|
|
|
|
Did you use of CFile class?
|
|
|
|
|
i dun use CFile class
Li Zhiyuan
5/10/2006
|
|
|
|
|
hi guys,
i need help on visual c++ coding. does anyone know the coding for x and y coordinates detection. As i needed to detect the mouse pointer. Your reply serve a great help. thx
|
|
|
|
|
Is GetCursorPos()[^] what you're looking for?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
yes it is..
i tried using
POINT pos;
GetCursorPos(&pos);
int x=pos.x;
int y=pos.y;
but when i compile it appear is error.
Compiling...
SetCursorPos.c
C:\Program Files\WiT8.1\customcp\cplib2\src\SetCursorPos.c(10) : error C2143: syntax error : missing ';' before 'type'
C:\Program Files\WiT8.1\customcp\cplib2\src\SetCursorPos.c(11) : error C2143: syntax error : missing ';' before 'type'
Error executing cl.exe.
SetCursorPos.obj - 2 error(s), 0 warning(s)
|
|
|
|
|
Looks like you're missing windows.h.
You may want to use the project wizard to build a Win32 project for you.
Then you'll have a good starting point with the basic required header files
included.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
thx mark..
but i had a new error.
coding:
#include "wcplib2.h"
#include <windows.h>
#include <iostream>
using namespace std;
CorOpRtn myCo_SetCursorPos(CorObj *In, CorObj *Out)
{
POINT pos;
GetCursorPos(&pos);
int x=pos.x;
int y=pos.y;
return COR_OP_OK;
}
Error:
Compiling...
SetCursorPos.c
c:\program files\microsoft visual studio\vc98\include\eh.h(32) : fatal error C1189: #error : "eh.h is only for C++!"
Error executing cl.exe.
SetCursorPos.obj - 1 error(s), 0 warning(s)
Student86
|
|
|
|
|
The error message says it - you'll need to be compiling for C++
to use eh.h
Renaming the source file with a .cpp extension is probably enough.
If not, the /TP compiler option will do it. You can set this for
a project in the project properties/C/C++/Advanced section.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I am creating a class for a dialog that can be used either in modal or modeless form, and I would like to use them both at the same time in a dialog-based app.
The complication is that the modal form and the modeless form use different resources (modal form has an 'OK' and 'Cancel' button, modeless does not) wondering if it's possible to use them in the same application since VS2005 puts the following line in CDialog-derived classes:
[code]
// Dialog Data
enum { IDD = IDD_DX9MATERIAL_DIALOG };
[/code]
which seems to tie the class to the dialog, no? Is it not possible to the use the same class for two dialogs? Or should I just create another version of the class for the two types of docs?
Thanks - @LRG
|
|
|
|
|
@largeinsd wrote: which seems to tie the class to the dialog, no?
Yes. It's only source code....feel free to alter it for your own use
The IDD is used only one place by default - it is passed to the CDialog
constructor. With a little modification you can pass whatever resource ID
you want to the base class.
Another alternative in this case, is to use one resource and show or hide the two
buttons depending on if the dialog is used modal or modeless.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Another alternative in this case, is to use one resource and show or hide the two
buttons depending on if the dialog is used modal or modeless.
Kaboom! That's why you're the MVP... and I'm just glad we're on the same team.
Thanks Mark, I will implement that.
|
|
|
|
|
@largeinsd wrote: I'm just glad we're on the same team.
What team?
Maxwell Chen
|
|
|
|
|
Team MFC/C++!
Of course
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Team MFC/C++!
I thought that you and largeinsd were co-woring on some specific project.
Maxwell Chen
|
|
|
|
|
Heh - nah....I took it more as an expression -
same thing as "I'm glad we aren't enemies" or "glad we're
not working against each other"
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
thanks
|
|
|
|
|
Just kidding
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
But why you dont want to use of wmi?
|
|
|
|
|
Hi,
There is a site with a page containing an HTML form for accessing private areas. This form requests an username and password to login.
I need to programmatically send username and password to the destination page of the form using POST method (to download an automatically generated file contained into the site reserved area).
This is not very hard to do I think, but my question is:
whenever login succeeded (the destination page of the form has accepted and verified username/password sent and probably that page redirects to another page, which should be the reserved area, on successfull login), is there a way to request a page from the reserved area ? The 'user' is still logged in for the server between a WinInet request and the next one ? (who manages the session and cookies to mantain the user logged?)
Thanks
|
|
|
|
|
I'm having a problem with date controls. Basically, I want the 2nd control(finalize date) to default to the date value in the first control(business date). And, the 2nd control should allow the date to be changed to a date that is within one day of the 1st control.
OnDatetimechangeDtcBusiness(NMHDR* pNMHDR, LRESULT* pResult) <br />
{<br />
COleDateTime dtMinRange;<br />
COleDateTime dtMaxRange;<br />
<br />
CString csBusDate;<br />
GetDlgItem(IDC_DTC_BUSINESS)->GetWindowText(csBusDate);<br />
<br />
COleDateTime dtBusDate;<br />
dtBusDate.ParseDateTime(csBusDate);<br />
<br />
dtMinRange.SetDate(dtBusDate.GetYear(), dtBusDate.GetMonth(), dtBusDate.GetDay() - 1);<br />
dtMaxRange.SetDate(dtBusDate.GetYear(), dtBusDate.GetMonth(), dtBusDate.GetDay() + 1);<br />
<br />
((CDateTimeCtrl*)GetDlgItem(IDC_DTC_FINALIZE_DATE))->SetRange(&dtMinRange, &dtMaxRange);<br />
m_dtFinalizeOnDate = dtBusDate;<br />
<br />
*pResult = 0;<br />
}
The 2nd date is not defaulting to the 1st date. The 2nd date is defaulting to one day after the 1st date.
Any and all comments are greatly appreciated. If you see something that could be done a better way, please let me know.
Thank you.
|
|
|
|
|
So what's the problem? Why are you using GetDlgItem() rather than an actual control variable?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Sorry about that, I edited my message post. The problem is that the 2nd control date is defaulting to one day after the 1st control date(business date).
|
|
|
|
|
littleGreenDude wrote: The problem is that the 2nd control date is defaulting to one day after the 1st control date(business date).
Isn't that what you told it to do?
dtMaxRange.SetDate(dtBusDate.GetYear(), dtBusDate.GetMonth(), dtBusDate.GetDay() + 1);
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|