|
Same problem i faced yesterday and fixed it.
In my case i was creating a DISPLAY DC and one Compatible DC and one Bitmap memory through CreateDIBSection API call.
hdc = CreateDC("DISPLAY",NULL,NULL,NULL);
Bitmap = CreateDIBSection(hdc, pBMI, DIB_RGB_COLORS, (void**)&m_pVideoBits, 0, 0);
HDC hSrcDC = CreateCompatibleDC(hdc);
SelectObject(hSrcDC, m_hViewfinderBitmap);
while Deleting the Bitmap and DC you should follow the following way
DeleteDC(hSrcDC);
DeleteObject(Bitmap);
DeleteDC(hdc);
If your code also have some this kind of thing then please take care that, you should not clean a bitmap untill it is attached to the DC
Hope i could help you some way.
Regards
Anil Kumar
|
|
|
|
|
Can any body tell me why structure alignment is necessary in C/C++ and what it may cause?
Anil Kumar
|
|
|
|
|
Hi
Applications should generally align structure members at addresses that are "natural" for the data type and the processor involved. For example, a 4-byte data member should have an address that is a multiple of four.
This principle is especially important when you write code for porting to multiple processors. A misaligned 4-byte data member, which is on an address that is not a multiple of four, causes a performance penalty with an 80386 processor and a hardware exception with a MIPS® RISC processor. In the latter case, although the system handles the exception, the performance penalty is significantly greater.
/\|-||\/|/\|)
|
|
|
|
|
Or maybe this can help too:
All modern CPUs expect that fundamental types like ints, longs and floats will be stored in memory at addresses that are multiples of their length.
CPUs are optimized for accessing memory aligned in this way.
Some CPUs:
allow unaligned access but at a performance penalty;
trap unaligned accesses to the operating system where they can either be ignored, simulated or reported as errors;
use unaligned addresses as a means of doing special operations during the load or store.
When a C compiler processes a structure declaration, it can:
add extra bytes between the fields to ensure that all fields requiring alignment are properly aligned;
ensure that instances of the structure as a whole are properly aligned. Malloc always returns memory pointers that are aligned for the strictest, fundamental machine type.
The specifications for C/C++ state that the existence and nature of these padding bytes are implementation defined. This means that each CPU/OS/Compiler combination is free to use whatever alignment and padding rules are best for their purposes. Programmers however are not supposed to assume that specific padding and alignment rules will be followed. There are no controls defined within the language for indicating special handling of alignment and padding although many compilers like gcc have non-standard extensions to permit this.
Summary
Structure Alignment
Structure alignment may be defined as the choice of rules which determine when and where padding is inserted together with the optimizations which the compiler is able to effect in generated code.
/\|-||\/|/\|)
|
|
|
|
|
But as per my understanding the structure members are stored in the contigous memory locations for example
struct temp
{
char a,
int b,
float c,
};
if i declare temp *structPtr = 0x00000000 (Address of element a)
then what should be the address of element b if it is 0x00000002 then one byte is waisted.
According to you b should have address of multiple of 4.
So i can say that there is a trade of CPU performance vs Memory usage
Am i right please guide me.
Regards
Anil Kumar
|
|
|
|
|
Yes, memory usage versus performance.
In Visual Studio you can use the #pragma pack() to control memory alignment on a structure-by-structure basis.
|
|
|
|
|
Generally the default structure alignment (which you should use unless there is a compelling reason not to) is 8 bytes. This aligns all basic data types (up to doubles) to even multiples of their size.
Example (using 8 byte alignment):
struct test
{
char a;
int b;
WORD c;
char d;
double e;
};
The offset addresses are:
a = 0
b = 4
c = 8
d = 10
e = 16
Total size of the structure: 24 bytes
Notice there is some wasted space in there. You can add some variables to this and not increase the size of the structure at all. The following structure is still 24 bytes in size, but is now fully packed.
struct test2
{
char a;
char a2;
WORD a3;
int b;
WORD c;
char d;
char d2;
int d3;
double e;
};
|
|
|
|
|
Respected All
Regards!
I have a CString object which has a value like
----------------------------------------
CString str=ss.find(0,4) //from this statment the str will be assign to
//file name ;
and now this "str" is a File name which i have to use in fileopen like
pFile=open("C:\\str.dat","r");
but it cant open str.dat as in the above satatment.now i think that i have to assign it to another string type variable and then can use it in opening a file.
but how i do it,,plz help me.
waiting for + response.
david
david
|
|
|
|
|
i'm not sure i understand well, but what about this ?
pFile=open("C:\\" + str + ".dat","r");
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
convert to char*
CString ss;//=xyz, david
char* str = ss.GetBuffer(cs.GetLength());
then construct ur file name.. with strcat(str,"//..dat"), so u wont get confused
then
pFile=fopen(str,"r");
am i right?
V
|
|
|
|
|
Hello,
I want to close all open Windows in my Application (not the MainWindow).
Unfortunately this Code fragment does not what I'm expecting
Here is my Code:
//Test Only for 4 Windows
CWnd * pWnd = NULL;
pWnd = GetActiveWindow();
for(int i = 1; i < 4; i++)
{
pWnd = GetActiveWindow(); //I tried GetNextWindow too
if (pWnd != theApp.GetMainWnd())
{
pWnd->PostMessage(WM_KEYDOWN,VK_ESCAPE);
}
pWnd = NULL;
}
Thanks fpr your Help.
And greetings from Germany
|
|
|
|
|
I have it!!
The Solution:
CWnd * pWnd = NULL;
pWnd = GetActiveWindow();
while(pWnd != theApp.GetMainWnd())
{
((CDialog*)pWnd)->EndDialog(IDCANCEL);
pWnd = GetActiveWindow();
}
|
|
|
|
|
You could also try to post the WM_CLOSE message to the windows.
If you notice strange side effects, you could consider doing the WM_CLOSE instead of calling EndDialog directly.
|
|
|
|
|
Sends the WM_CLOSE Message IDCANCEL?
I would really like to use WM_CLOSE but I 'm not sure
if the Windows is closed with IDCANCEL. My solution has a
disadvantage it closes only Modal Dialogs
Daniel
|
|
|
|
|
WM_CLOSE asks the model dialog window to close.
You are correct, the WM_CLOSE does not ensure that they end with the IDCANCEL return value.
The WM_CLOSE will close modeless dialogs as well.
|
|
|
|
|
Hello,
I am working in VC++ 6.0 and Windows Xp Professional.
I created an ActiveX control using MFC ActiveX ControlWizard and have drawn a circle
on the control window using CDC (CView) Class. Now I want to print this circle on the
currently installed printer. I already added a method named "PrintCircle" to
the control. I would like to call this method to do the printing.
Now, my question is, how can I invoke the Printing functions
Meantime I done the job with a SDI Application
I try to do this way...
CMyCtrl
CMyCtrl:: PrintCircle()
{
m_pView->MyPrint();
}
CMyView
CMyView::MyPrint()
{
OnFilePrint();
}
This will goes up to OnpreparePrint () and show the print Dialog too
Then shows an Runtime Error 2147417848(80010108)
Hoping to get a reply soon.
Thanks in advance.
|
|
|
|
|
My company develops Object Orienterd software applications (mainly in VC++).
We have always measured our software quality and complexity using standard
metrics (Line Of Code, MCCabe and so on..). Now we are trying to apply Object
Oriented metrics but we have seen that there are many different approaches,
many different type of metrics an few standardized ways to apply Object
Oriented metrics.
Does someone know something about it ? Which Object Oriented metric can be
used to start ? Are there some articles that can be taken as a guide ?
Thanks a lot!
|
|
|
|
|
Hey All,
Does anyone know how to find what arguments were passed to a process?
I can see that the ProcessViewer from sysinternals can do it, but I can not see how.
ideas?
Jules
|
|
|
|
|
|
Can anybody send me sample of source code about TCP programming.........very URGENT........
|
|
|
|
|
|
|
I had read through the website u given, they got alot of example of source code. I dont't understand that to start a TCP programming, which I should start first... Can give me some guide? I really rush on doing this project and only left 6 weeks for me to do....And I also very weak in programming....PLEASE....
|
|
|
|
|
Hi all, I am trying to write a program that runs in background to monitor and kill some running process. I coded it in Visual C++ 6.0 in a Win32 Console Application project. The code works, just that the console window appears when I run it. Can anyone tell me how can I make it a background process without the console window showing up? Thanks and appreciate.
|
|
|
|
|
There are a bunch of functions for dealing with consoles. Search for "Console Functions" in MSDN
Something like this might work ::ShowWindow(::GetColsoleWindow(), SW_HIDE);
|
|
|
|