|
They use ReadFile behind the scenes.
|
|
|
|
|
U can use fstream class object and use its functions like read
Muhammad Shoaib Khan
http://geocities.com/lansolution
|
|
|
|
|
are there, to read from files.
fread, fstream - they all use ReadFile (or ReadFileEx) internally.
I want to know what Win32 API functions are there, to read from files.
|
|
|
|
|
ReadFile is the most low level API call you cant get for reading directly from a handle, but there is also a more sophisticated way to read a file.
You could create a memory mapping of the file and then use any developer tricks you can dream up.
An example: If the file is a bitmap file, then you can cast the void * you get from the mapping to a struct BITMAPFILEHEADER *, and then read from the members of that structure.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
Thank you for the elaborate resposne
Unfortunately, I found out that this also is not the way DirectShow reads WMV and ASF files (I found it out using API hooking).
Any chance that it uses some sort of direct disk access? Or maybe reads the file in a different process and streams the data through COM to my process?
Any other ideas?
Thanks!
|
|
|
|
|
The whole point of DirectX is to be an abstraction layer that hides the awfull truth which is: If a DirectX driver for the given hardware exists, in your case this is the soundboard driver, then the features of that driver is used. If such a driver does not exist, then DirectX will emulate the DirectX functions, using the usual Win32 API calls.
So, what you are looking for is not an API call, but a way to access the hardware directly which is not at all like reading a file (unless of course you are used to read files in assembler ).
But why not use DirectX then?, if there is a difference in performance compared to the ASM solution, then it is a very small one.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
Thanks again for taking the time to reply everytime
Would you like to continue the discussion in email?
At any case - what I actually want to do is override the DirectX function calls so that my code will intercept every reading from the disk and modify the data that is being read...
|
|
|
|
|
Hi
C functions like fgets() and fscanf() can do the trick for you.
Besides that, you can also use the MFC class CFile and it's derived classes to do some file I/O.
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
After calling PageSetupDlg() about three or four times I get an "Out of Memory" error.
My App is MDI with Multiple Document views.
I am storing the PAGESETUPDLG structure in the view class so that each time a new view is created, each view will have it's own page setup values.
The problem seems to be that if the PAGESETUPDLG devmode and devnames are not set to NULL either before or after calling PageSetupDlg(), then the memory error occurs.
I tried creating a dmOrientation variable so that I could store the paper orientation for each view but it won't compile. (See how below. It's commented out.)
I tried creating a DEVMODE and DEVNAMES structure but this didn't help. (See how below. It's commented out.)
My questions are:
How can I store the PageSetupDlg() values for each view?
Am I doing something wrong? (See partial code below)
//- Begin part of h file -//
// MyView.h : header file
//
/////////////////
// CMyView view
class CMyView : public CView
{
protected:
CMyView(); // protected constructor used by dynamic creation
DECLARE_DYNCREATE(CMyView)
// Attributes
public:
PAGESETUPDLG psd; // common dialog box structure
// short myOrientation;
// DEVMODE myDevMode;
// DEVNAMES myDevName;
LOGFONT mylf; // logical font structure
//- End part of the h file -//
//- Begin part of the cpp file -//
// CMyView.cpp : implementation file
//
#include "stdafx.h"
#include "MyApp.h"
#include "MyAppDoc.h"
#include "MyView.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////
// CMyView
IMPLEMENT_DYNCREATE(CMyView, CView)
CMyView::CMyView()
{
//Page Setup
// myDevMode = (HANDLE)NULL; //don't forget to free or store hDevMode
// myOrientation = DMORIENT_PORTRAIT; //Selects the orientation of the paper.
// This member can be either DMORIENT_PORTRAIT (1)
// or DMORIENT_LANDSCAPE (2)
// psd = {0}; //doesn't compile
psd.lStructSize = sizeof(PAGESETUPDLG);
psd.hDevMode = (HANDLE)NULL; //don't forget to free or store hDevMode
psd.hDevNames = (HANDLE)NULL; //don't forget to free or store hDevNames
// psd.hInstance = (HANDLE)hInst;
psd.lCustData = (LPARAM)NULL;
psd.hPageSetupTemplate = (HGLOBAL)NULL;
psd.Flags = PSD_INTHOUSANDTHSOFINCHES | PSD_MARGINS;
psd.rtMargin.top = 1000;
psd.rtMargin.left = 1000;
psd.rtMargin.right = 1000;
psd.rtMargin.bottom = 1000;
// Initialize LOGFONT
mylf.lfHeight = 12; // LONG lfHeight;
mylf.lfWidth = 0; // LONG lfWidth;
mylf.lfEscapement = 0; // LONG lfEscapement;
mylf.lfOrientation = 0; // LONG lfOrientation;
mylf.lfWeight = 0; // LONG lfWeight;
mylf.lfItalic = 0; // BYTE lfItalic;
mylf.lfUnderline = 0; // BYTE lfUnderline;
mylf.lfStrikeOut = 0; // BYTE lfStrikeOut;
// BYTE lfCharSet;
// BYTE lfOutPrecision;
// BYTE lfClipPrecision;
// BYTE lfQuality;
mylf.lfPitchAndFamily = 0;
// BYTE lfPitchAndFamily;
lstrcpy(mylf.lfFaceName,"Arial");
// CHAR lfFaceName[LF_FACESIZE];
}
/////////////////
// CMyView Printing
void CMyView::OnFilePageSetup()
{
psd.hwndOwner = GetSafeHwnd( );
// psd.hDevMode = (HANDLE)myDevMode; //don't forget to free or store hDevMode
// psd.hDevMode = (HANDLE)NULL; // don't forget to free or store hDevMode
// psd.hDevNames = (HANDLE)NULL; // don't forget to free or store hDevNames
// psd.hDevMode.dmFields = DM_ORIENTATION;
// psd.hDevMode.dmOrientation = myOrientation; //doesn't compile
psd.hInstance = (HANDLE)hInst;
psd.lCustData = (LPARAM)NULL;
psd.hPageSetupTemplate = (HGLOBAL)NULL;
if(PageSetupDlg(&psd) == TRUE) {
// myOrientation = psd.hDevMode.dmOrientation;
// myDevMode = (HANDLE)psd.hDevMode;
psd.hDevMode = (HANDLE)NULL;
psd.hDevNames = (HANDLE)NULL;
}
}
//- end of part of cpp file -//
|
|
|
|
|
Oops.
Forgot that there was another function in CMyView::OnFilePageSetup().
After the user chooses OK the following function is called.
AfxGetApp()->SelectPrinter(psd,hDevNames, psd.hDevMode,TRUE);
When this function is commented out, there is no memory error. However, the landscape/portrait is not implemented when Print Preview is called.
|
|
|
|
|
I want to pass the CString name to a class. I have this:
void CForm3Page1::OnName()
{
CFormatname Dlg("ralph");
if (Dlg.DoModal() == IDOK)
{
}
}
and my class looks like this:
private:
CString thename;
public:
CFormatname(CWnd* pParent = NULL, CString); // standard constructor
CFormatname::CFormatname(CString name, CWnd* pParent /*=NULL*/)
: CDialog(name, CFormatname::IDD, pParent)
{
//{{AFX_DATA_INIT(CFormatname)
//}}AFX_DATA_INIT
thename = name;
}
But it doesn't work. I keep getting the errors:
C:\Formatname.h(25) : error C2548: 'CFormatname::CFormatname' : missing default parameter for parameter 2
C:\Formatname.h(15) : see declaration of 'CFormatname'
and other errors. I have looked in this book for quite some trying to
mimic this example. How do I pass a CString to a class?
Please any response any one can give me will be greatly appreciated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
DanYELL wrote:
CFormatname(CWnd* pParent = NULL, CString); // standard constructor
CString is a data type, it has to be followed with a variable that represents it:
CFormatname(CWnd* pParent = NULL, CString myStr);
- Nick Parker My Blog
|
|
|
|
|
Even with that change, I still get this error:
C:\Formatname.h(25) : error C2548: 'CFormatname::CFormatname' : missing default parameter for parameter 2
and it's this line
CFormatname(CWnd* pParent = NULL, CString mystr); // standard constructor
???
|
|
|
|
|
Try
CFormatname(CWnd* pParent = NULL, CString myStr = NULL);
Thank You
Bo Hunter
|
|
|
|
|
Bo Hunter wrote:
CFormatname(CWnd* pParent = NULL, CString myStr = NULL);
Since myStr is not a pointer and NULL is a void pointer 0, the default argument isn't correct, but should be CFormatname(CWnd* pParent = NULL, CString myStr = "");.
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
|
On my machine once you start default parameters from there
on out has to have defaults as well. Is this correct?
Thank You
Bo Hunter
|
|
|
|
|
Still stumped. I call the class like so:
CFormatname Dlg("ralph");
The constructor is:
CFormatname(CWnd* pParent = NULL, CString mystr = NULL); // constructor
and
CFormatname::CFormatname(CWnd* pParent /*=NULL*/, CString mystr)
: CDialog(CFormatname::IDD, pParent, mystr)
{
//{{AFX_DATA_INIT(CFormatname)
//}}AFX_DATA_INIT
thename = mystr;
}
and the errors are:
C:\Formatname.h(25) : error C2440: 'default argument' : cannot convert from 'const int' to 'class CString'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Formatname.h(25) : error C2548: 'CFormatname::CFormatname' : missing default parameter for parameter 2
C:\Formatname.cpp(20) : error C2661: 'CDialog::CDialog' : no overloaded function takes 3 parameters
What perplexes me is the information that is added to the class by
Visual C++. It automatically adds 'CWnd* pParent /*=NULL*/'
and 'CFormatname::IDD' and I try to ignore those parameters and
mimic what I see in books, but it doesn't work.
Please, please, please any response anyone can give me will be
greatly appreciated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
The constructor you supplied is expecting the first parameter to be a CWnd*, and you are passing a string. Either change the constructor
CFormatname(CString mystr, CWnd* pParent = NULL) or pass in a NULL pointer
CFormatname Dlg(NULL, "ralph");
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Seems so obvious now (and it works). I appreciate the reply. I kept
wanting to ignore the 'CWnd* pParent = NULL' part.
One last question. For this part of the constructor:
CFormatname::CFormatname(CWnd* pParent /*=NULL*/, CString mystr)
: CDialog(CFormatname::IDD, pParent)
{
//{{AFX_DATA_INIT(CFormatname)
//}}AFX_DATA_INIT
name = mystr;
}
what exactly is CFormatname::IDD? What am I passing to CDialog?
pParent is just NULL and I know what :: means, but CFormatname::IDD
doesn't make sense.
|
|
|
|
|
The IDD is the ID of the dialog. It is defined as a const in the class's H file.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Try This:
CFormatname(CString name,CWnd* pParent = NULL); // standard constructor
Shenthil
|
|
|
|
|
I have been using the introductory edition of MS VC++ 6.0 that came with Ivor Hortons book. What is the current latest version?
Ger
|
|
|
|
|
VC++ .NET 2003
modified 12-Sep-18 21:01pm.
|
|
|
|
|