|
halestorm 222 wrote: i can't seem to figure out whats wrong with my code.
How do you know something is wrong?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I have calling Initialize function with these parameters
Initialize(this->GetDC(),200,200);
Unhandled exception occurred at: m_pBitmap->CreateCompatibleBitmap(pInputDC,width,height);
void Initialize(CDC* pInputDC,int width, int height)
{
CDC *m_pDC;
CBitmap* m_pBitmap;
m_pDC->CreateCompatibleDC(pInputDC);
m_pBitmap->CreateCompatibleBitmap(pInputDC, width, height);
m_pDC->SelectObject(m_pBitmap);
m_pDC->Rectangle(0,0,width,height);
}
This is shown in call stack when exception occurred:
mfc80ud.dll!CGdiObject::Attach(void * hObject=0xb90510f0) Line 1157 + 0x3 bytes
mfc80ud.dll!CBitmap::CreateCompatibleBitmap(CDC * pDC=0x004bf954, int nWidth=336, int nHeight=189) Line 251 + 0x25 bytes
AxGraph.ocx!CGraphCtrl::Initialize(CDC * pInputDC=0x004bf954, int width=336, int height=189) Line 27
I could not understand why is this happening. Help to resolve the issue.
|
|
|
|
|
Did you allocated memory for of CBitmap* and CDC* using new?
Величие не Бога может быть недооценена.
|
|
|
|
|
Thanks. I forgot to allocate memory. After allocating memory its working.
Thanks again
K.Masood
|
|
|
|
|
Hi,
Usually I instantiate my CDialog based classes in my view class. Then CMyView class typically creates a modal dialog and then launches a function on OK from which I can easily access the dialog variables.
Unfortunately, the wizard implementation of CPropertySheet has no default constructor. So you are forced to construct it in the view function that is called from a toolbar menu or similar. Then the property page variables have to be duplicated in CMyView class and copied. I have 2 books that show it done this way.
Here is the wizard CPropertySheet constructor code-
CMyDlg::CMyDlg(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
}
CMyDlg::CMyDlg(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
And the constructor in CMyView looks like -
CMyDlg CMyDlg(_T(" "),this);
or
CMyDlg CMyDlg(_T(" "));
if (CMyDlg.DoModal() == IDOK){
(both verified to work)
If I now add the appropriate default constructors to the PropertySheet .h and .cpp files -
CMyDlg();
CMyDlg::CMyDlg():CPropertySheet()
{
}
I then instantiate CMyDlg in the view class instead of constructing it in the menu function.
I don't get any compile errors but the dialog (property page) does not display when DoModal is called even though there is no run time error.
I suppose I should admit defeat and call the constructor as designed.
modified on Friday, October 30, 2009 12:55 AM
|
|
|
|
|
HI all,
I have written some code about changing Modification Time and Access Time in File.
My code tries to change both time every one minute.
But, sometimes, Modification Time is not changed by _utime() with 'NO ERROR' after running few hours. (but, Access time is changed.)
Below is the code used to changed times.
if anyone know why the problem is appeared and how i can solve,
Please, let me know
Thanks.
+++++++++++++++++++++++++++++++++++++++++++++++
BOOL SetModificationTime( time_t t )
{
struct _utimbuf uti;
uti.actime = t;
uti.modtime = t;
if (_utime(szPath, &uti))
{
OutputDebugString("Error : Faid to change time");
return FALSE;
}
}
--------------------------------------------------
|
|
|
|
|
|
Thank you for answer~
But, SetFileInformationByHandle need at least Windows Vista OS.
My Program's minimum supported client is Windows 2000. T.T
is There any other way to solve?
Please Let me know.
Thanks.
|
|
|
|
|
Have you tried SetFileTime() ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I wrote the below code in an attempt to set a 500ms timer. CreateWaitableTimer returns a valid handle and SetWaitableTimer() returns 1 indicating success, however TimerAPCProc() never gets called. Can anybody see what's wrong with this code?
VOID CALLBACK __stdcall TimerAPCProc(LPVOID lpArgToCompletionRoutine, <br />
DWORD dwTimerLowValue, DWORD dwTimerHighValue)<br />
{<br />
<br />
}<br />
<br />
void SetTimer()<br />
{<br />
m_hTimer = CreateWaitableTimer(NULL, false, NULL);<br />
LARGE_INTEGER liInterval;<br />
liInterval.QuadPart = -500000000;<br />
int dSuccess = SetWaitableTimer(m_hTimer, &liInterval, 0, TimerAPCProc, NULL, false);<br />
}
Thanks for any help you can offer.
|
|
|
|
|
|
Thanks for the reply and information. The timer is being created in the main thread so it's definitely not a problem of it exiting too soon. I also tried setting the time to -1 just to try and get it to call the TimerAPCProc but still it wouldn't.
I solved the problem by switching to SetTimer(). For some reason I thought SetTimer() worked in seconds rather than milliseconds and that's the only reason I was using SetWaitableTimer(). I was looking for an alternative time and noticed SetTimer() took a value in milliseconds so it was fine for what I needed.
I still don't understand why SetWaitableTimer() wouldn't work but it doesn't really matter now.
|
|
|
|
|
Hello
Can anyone tell me how to read and write to a binary file?
Any sample code will be of great help.
I want to write multiple structures into a binary file
and then read it one by one.
Thanks in advance
|
|
|
|
|
Just CreateFile with binary access, write it, seek to the front, and read it back record by record. If you want random access, then the records must be the same size. If you want variable length records, just precede each binary record with a DWORD with the record size when you write it, then when you read it back, read the DWORD to get the record size, then read the data block, - this also implies that the file must be sequentially accessed both for writing and reading.
Dave.
|
|
|
|
|
#include <stdio.h>
typedef struct _myStruct
{
int x;
int y;
int z;
} myStruct;
int main()
{
FILE *fp;
char *fileName = "output.dat";
char *mode = "wb";
myStruct theArray[10];
int i;
for (i=0; i<10; i++)
{
theArray[i].x = i;
theArray[i].y = 10-i;
theArray[i].z = i * (10-i);
}
fp = fopen(fileName, mode);
fwrite(theArray, sizeof(struct myStruct), 10, fp);
fclose(fp);
}
|
|
|
|
|
Thanks for the sample code.
I am working on C++ using WIN32 API's in Visual Studio 2003.
In the function here for binart read/write,
i am using the functions, _write and _ read.
Does that make any difference in writing/reading? compared to using fwrite and fread?
|
|
|
|
|
|
dipuks wrote: i am using the functions, _write and _ read.
See here and here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
For opening binary file use CreateFile [^] with OPEN_EXISTING flag.
For reading the file use ReadFile [^]
For writing the file use WriteFile [^]
Величие не Бога может быть недооценена.
|
|
|
|
|
Hi,
I have the following program.
I want to use char array at the end of while loop so that after while loop if i use printf() statement it will be printed.I have already copy the directory in an char array.Actually i am something confusing at this time and cann't solve the problem.
#include<windows.h>
#include<string.h>
#include<stdio.h>
int main()
{
int length1,length2;
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
char DirSpec[MAX_PATH + 1];
DWORD dwError;
char dirpath[MAX_PATH];
printf("Enter the path of directory: ");
gets(dirpath);
printf ("Target directory is %s\n",dirpath);
strncpy (DirSpec, dirpath, strlen(dirpath)+1);
strncat (DirSpec, "\\*", 3);
hFind = FindFirstFile(DirSpec, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
printf ("Invalid file handle. Error is %u\n", GetLastError());
return (-1);
}
else
{
length1=sizeof(FindFileData.cFileName);
char firstdir[length1];
strcpy(firstdir,FindFileData.cFileName);
printf("First file name is %s\n",firstdir);
while (FindNextFile(hFind, &FindFileData) != 0)
{
length2=sizeof(FindFileData.cFileName);
char otherdir[length2];
strcpy(otherdir,FindFileData.cFileName);
printf("Other dir is:%s\n",otherdir);
}
/* ****************************************************
* here i want a char array *
* printf("All dir except first is:%s",array); *
* *
****************************************************/
dwError = GetLastError();
FindClose(hFind);
if (dwError != ERROR_NO_MORE_FILES)
{
printf ("FindNextFile error. Error is %u\n", dwError);
return (-1);
}
}
return (0);
}
I have commented the line where i want the char array.Actually i want this array outside while loop.
|
|
|
|
|
Please post your code withing the code block.
You are more likely to get and answer if you do that.
ravi 12 wrote: char otherdir[length2]
You cannot create an array with a variable (length2) as its size.
You need to have a constant instead.
|
|
|
|
|
Hi «_Superman_»,
thank you very much for your suggestion.You are right that i must create a constant size array.thanks
|
|
|
|
|
Are you wanting a char array of all files found in the while() loop by the FindFirstFile() /FindNextFile() pair? Unless you have an aversion against it, use std::vector or std::list .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi DavidCrow,
Thanks for your suggestion.Yes i want a char array of all files found in the while() loop by the FindFirstFile()/FindNextFile() pair.
|
|
|
|
|
Perhaps «_Superman_» overlooked the difference between c and c++ when it came to dynamically sized array declarations - they work just fine here too.
Um, this is really very easy.
You need to declare somewhere to hold a string.
After each new filename has been retrieved it's tacked onto the end of the existing string
When the loop's over the string is printed.
I can think of at least 3 ways around this mountain, though (surprise, surprise) went for the easiest/quickest/dodgiest (is that even a word?) way.
1. Declare a new var in main and initialize to 4096 times "\0" (since I'm testing in C:\ and I know there to be under 4kb worth of file/folder names there)
char finalString[4096];
2. Add to it each time through the loop
while (FindNextFile(hFind, &FindFileData) != 0)
{
strcat(finalString, FindFileData.cFileName);
strcat(finalString, "\n");
}
3. Print it out
printf("%s\n", finalString);
The other two ways that come to mind are:
1. Dynamically resizing the memory used to hold the final string.
2. Getting a count of the number of dir-entries, then creating an array of char* with that many entries. You then alloctae some memory, point dirEntryArray[curEntryNum] at this memory, and make sure you copy the current filename into said mem.
You can probably see why I went for the 'coding-horrors' way.
EDIT: ah crap! See, that's why David is an MVP, and I'm not. 
|
|
|
|