|
Hi!
I have a question regarding the use of different types of integers in Visual C++ 6.0. For example, I want to use in my application an integer variable named nIntValue.
If I declare it like this:
__int16 nIntValue;
does the system allocate it on only 16 bits or it still uses 32 bits as if I declared it:
__int32 nIntValue;
I have created this small test program:
int main( void )
{
__int32 n32BitsValue = 0x64;
__int16 n16BitsValue = 0x64;
return 0;
}
After that, I disassembled it using dumpbin /disasm test.exe.
Then I realized that it allocates 32 bits on the system stack for each variable. So it didn't matter for the OS that I wanted n16BitsValue to be 16 bits long. The only difference I noticed was this:
mov dword ptr [ebp - 4], 64h
mov word ptr [ebp - 8], 64h
So it allocated 32 bits on that stack for n16BitsValue, but modified only 16 of them. If this happens, what need is for these different integer types anyway? What can be done to force the operating system to allocate only 16 bits for an __int16 variable?
Any help would be greatly appreciated.
Thanks in advance!
|
|
|
|
|
Eikthrynir wrote: If I declare it like this:
__int16 nIntValue;
does the system allocate it on only 16 bits or it still uses 32 bits as if I declared it:
__int32 nIntValue;
<br />
printf("n16BitsValue: %d\n", sizeof(n16BitsValue));<br />
<br />
printf("n32BitsValue: %d\n", sizeof(n32BitsValue));<br />
<br />
n16BitsValue: 2
n32BitsValue: 4
so yeah, 16-bit and 32-bit
Also, VC sees __int16 as short , and __int32 as int .
|
|
|
|
|
Eikthrynir wrote: Then I realized that it allocates 32 bits on the system stack for each variable.
Eikthrynir wrote: mov dword ptr [ebp - 4], 64h
mov word ptr [ebp - 8], 64h
dword is 32 bits, but word is 16 bits AFAIK, so no, not the 2 variables make 32 bits.
|
|
|
|
|
The compiler 'allocates' 32 bits on the stack for an __int16 , but the code it generates only references the lower 16 bits. The reason for this is efficiency due to memory alignment. Modern Intel processors access memory most efficiently on 32-bit boundaries. I don't know about AMD or the other manufacturers, but I would suspect they are similar.
Why is this a concern?
Software Zen: delete this;
|
|
|
|
|
Thank you for your time! I really appreciate it!
The reason I wanted to know how much memory the compiler "allocates" on the stack is the performance concerning space.
Thanks again!
|
|
|
|
|
|
Hi,
My problem is that I sometimes receive dozens of WM_MOUSEWHEEL events for a single rotation step of the mouse wheel. Other events like WM_KEYDOWN don't have this problem, I received them only once for a pressed key.
Normally I'm using this event in a CDialog inherited class and everything's works ok but the context here is slightly different. This time I had to create my window with "CreateWindowEx" so there's no CDialog inheritance and therefore I need to have my own message loop and message processing function. Can you have a look at them below and tell me if you see an explanation for my problem ?
Thanks.
Message loop :
<br />
MSG msg; <br />
while (1)<br />
{<br />
PeekMessage(&msg, hWND, NULL, NULL, PM_REMOVE);<br />
TranslateMessage(&msg);<br />
DispatchMessage(&msg); <br />
if (msg.message == WM_QUIT)<br />
{<br />
break;<br />
}<br />
Sleep(100);<br />
}<br />
Message processing function :
<br />
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)<br />
{<br />
switch(message)<br />
{<br />
case WM_CREATE:<br />
return 0;<br />
break;<br />
<br />
case WM_CLOSE:
PostQuitMessage(0);<br />
return 0;<br />
break;<br />
<br />
case WM_DESTROY:<br />
PostQuitMessage(0);<br />
return 0;<br />
break;<br />
<br />
case WM_KEYDOWN:<br />
ProcessKeyStroke(MapVirtualKey(((UINT)lParam & 0x00ff0000) >> 16,1));<br />
break;<br />
<br />
case WM_MOUSEWHEEL:<br />
{<br />
short zDelta = GET_WHEEL_DELTA_WPARAM(wParam);<br />
ProcessMouseWheel(zDelta);<br />
}<br />
break;<br />
<br />
default:<br />
return (DefWindowProc(hwnd, message, wParam, lParam));<br />
break;<br />
}<br />
<br />
return 0;<br />
}<br />
<br />
|
|
|
|
|
Any one help me..........
1)Im using Visual studio 6.0.......it contain a WININET.h file ..this file contain ::FtpCommand function..........Visual studio WinInet.h does not contain this functio....so i have to download from Microsoft site i dont know wat to download..any one know about this............give me more info
|
|
|
|
|
You asked the same question yesterday - please don't keep reposting!
Anyway, what you need is the platform SDK - the latest one is here:
clicky[^]
Don't be confused that it's called the "Windows Server 2003 R2 Platform SDK" - MS just name the latest platform SDK after the newest version of windows supported - That'll give you the latest stuff if you're developing for 2000, XP, or any of the recent versions of Server.
|
|
|
|
|
HI benjy.........i got SDK files from the link u gave but how will my Visual studio come to know about the SDK i tried to replace the vc98 wininet.h file with a SDK wininet.h file but i got some error how can go through this...reply if u know this....im fedup of this
|
|
|
|
|
benjymous wrote: Anyway, what you need is the platform SDK - the latest one is here...
The SDK for v6 is not available online. It must be ordered on CD.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
Hi Friends,
In my project I want to compare two images to find out the differences in both of the images, can any one please suggest me some algorithm or free code which I can use for this purpose.
Thanks in advance,
Dinu
|
|
|
|
|
|
Do you want to compare on depth of images?
|
|
|
|
|
Hi all, i will thank in advance for your help.
I want to color the text of radio button, using OnCtlColor but the color doesn't change. anyone know how i can color the text? this is a part of my Dialog box
HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if( (pWnd->GetDlgCtrlID() == IDC_RADIO1) ||
(pWnd->GetDlgCtrlID() == IDC_RADIO2) )
{
pDC->SetTextColor(((CEstoApp*)AfxGetApp())->GetSfondoTesti());
pDC->SetBkMode(TRANSPARENT);
}
return hbr;
}
Thanks to all
|
|
|
|
|
Try returning brush of color you want.
HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if( (pWnd->GetDlgCtrlID() == IDC_RADIO1) ||
(pWnd->GetDlgCtrlID() == IDC_RADIO2) )
{
hbr = CreateSolidBrush(...);
}
return hbr;
}
|
|
|
|
|
This code is working
HBRUSH CAnswer::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(pWnd->GetDlgCtrlID() == IDC_RADIO1)
pDC->SetTextColor(RGB(53,97,220));
return hbr;
}
|
|
|
|
|
thank for your answer, in fact the code is working, maybe in my case is not working because i use a resource that implement XP STYLE and maybe this is why the code in my program is not working.
thank a lot
|
|
|
|
|
Maybe I had a problem like this but with ComboBox
|
|
|
|
|
I try to write a simple playsound program.
It works while it's compiling.
There is no errors return.
The playsound function return 1 value.
But it doesn't play the WAV files.
Can somebody help me why it doesn't play the music?
My code is following.
#include "stdafx.h"
#include <windows.h>
#include <mmsystem.h>
#include <iostream>
#include <winuser.h>
#pragma comment(lib, "winmm.lib")
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i;
i=MessageBeep(0);
cout << i ;
i=PlaySound((LPCWSTR)"c:\\dn.wav",NULL, SND_FILENAME);
cout << i ;
cin >> i;
cout << i << endl;
return 0;
}
I try two methods
1. i=PlaySound((LPCWSTR)"dn.wav",NULL, SND_FILENAME);
2. i=PlaySound((LPCWSTR)"c:\\dn.wav",NULL, SND_FILENAME);
But it still doesn't play the music.
Thanks a lot.
minihotto
|
|
|
|
|
I tested your code it worked maybe your problem is your file if you try to play files on windows\\media what happen it works or doesnt work?
|
|
|
|
|
it works.
-- modified at 12:15 Monday 9th October, 2006
|
|
|
|
|
So maybe your problem is of your file
|
|
|
|
|
I dont understand.@@
you mean the path of the file?
|
|
|
|