|
Hello David,
That's a great idea indeed ! Using a union is absolutely brilliant !
I have a further suggestion :
union
{
BYTE b[sizeof(int)];
int n;
} u;
Instead of hardcoding the size of the array, I thought we could set this to the byte size of an integer. This code will ensure platform independence.
Thanks, David.
Best Regards,
Bio.
|
|
|
|
|
Hello Ting,
The size of the byte array must be exactly 4 bytes in intel platforms (4 bytes being 32 bits).
The reason why I use an "unsigned char" array is because a byte in programming terms is essentially an unsigned 8-bit character. So use "unsigned char" instead of "char".
If your byte array is smaller than 4 bytes, reset it to 4 bytes and pad the missing bytes with zero. E.g. :
instead of :
// Byte array to represent 0x00112233.
unsigned char ucByteArray[3] = { 0x33, 0x22, 0x11 };
make this :
// Byte array to represent 0x00112233.
unsigned char ucByteArray[4] = { 0x33, 0x22, 0x11, 0x00 };
Remember the byte ordering of Intel platforms : a two byte short integer with value 0x1122 is represented in memory bytes as :
0x22 <-- first byte.
0x11 <-- second byte.
Your byte array must not be larger than 4 bytes. This would be an error.
Best Regards,
Bio.
|
|
|
|
|
Hello Ting,
Additional info (which I think you already know but I just want to clarify) : The byte ordering information that I just mentioned pertains only to Intel machines. Please find out the byte ordering information of the target machine you are working on.
Also, I mentioned that your byte array must not be larger than 4 bytes. This is assuming that you are working on the Intel platform. You could be working on a machine with a 64 bit processor which will make the byte size of an integer 8 bytes. In this case, your byte array should be no larger than 8 bytes.
Just to clarify,
Bio.
|
|
|
|
|
i use it at windows platform (include winxp, 98, me, and pocket pc 2003). Do they are "Intel platform"? Thanks
|
|
|
|
|
Hello Ting,
The Intel platform is what we commonly refer to as the PC (personal computer). The Macintosh is not the Intel platform (the Mac uses the Motorolla chip, last time I remember).
WinXP, 98, ME all run on the PC and so they do run on the Intel platform.
The Pocket PC 2003 is the OS behind PDAs which do not use the Intel chip. Even if they do, they may not be 32-bit based.
One simple but effective way to check out the byte size of an integer in whatever target platform you are working on is to use the "sizeof" operator. E.g. :
memcpy (ucArray, (void*)((unsigned char*)&iInt), sizeof(iInt));
notice my use of sizeof(iInt) instead of hardcoding this to 4.
Regards,
Bio.
|
|
|
|
|
Hi,
How can we change the font and text color of an edit control(CEdit class)
using CFontDialog ?
Thanx in advance
Rgds
Sunil
|
|
|
|
|
CFontDialog dlg;
if (dlg.DoModal() == IDOK)
{
LOGFONT lf;
memcpy(&lf, dlg.m_cf.lpLogFont, sizeof(LOGFONT));
//CFont m_font as class member
VERIFY(m_font.CreateFontIndirect(&lf));
GetDlgItem(IDC_EDIT_MYTEST)->SetFont(&m_font);
}
There is no spoon.
mail
|
|
|
|
|
--------------------------------------------------------------------------------
Hello,
I am working with MDI application. When I maximize my main window, my child windows should also be maximized.I want my childd window to be maximized whenever Mainframe window is maximized.Can anyone please help me to do this?
Thanks
Madhavi
|
|
|
|
|
Handle WM_SIZE for Main Window.
If you have faith in the cause and
the means and in God, the hot
Sun will be cool for you.
|
|
|
|
|
Hello,
I'm trying to upload a file from a Pocket PC 2003 device to different servers, one is running Windows XP Professional and the other is running Linux.
When I upload the file to the Windows server, the file is created, but as soon as I close the handle, the file is deleted. When uploading to the Linux machine the file is uploaded, but If I call any other FTP function it fails.
Any ideas what's wrong?
Thanks
This is my evc 4.0 code:
Before I InternetOpen + InternetConnect.
HANDLE hFile;
HINTERNET hFtpOpenFile;
HINTERNET handle;
DWORD dwWritten = 0;
DWORD dwRead;
DWORD dwBytesWritten;
DWORD nBytesToReadWrite = 1024;
DWORD nBytesWritten = 0;
hFile = CreateFile(lpzFile2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL);
long lFileSize = GetFileSize (hFile, NULL);
long nSumBytes = 0;
char *inBuffer = new char [lFileSize];
DWORD nBytesLeft = lFileSize;
if(bBinary)
{
hFtpOpenFile = FtpOpenFile(hConnect, lpzFile1, GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY, 0);
}
else
{
hFtpOpenFile = FtpOpenFile(hConnect, lpzFile1, GENERIC_WRITE, INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_RELOAD | INTERNET_FLAG_RESYNCHRONIZE | FTP_TRANSFER_TYPE_ASCII, 0);
}
if(!hFtpOpenFile)
{
InternetCloseHandle(hFtpOpenFile);
CloseHandle (hFile);
return false;
}
do
{
if(ReadFile(hFile,inBuffer,nBytesToReadWrite,&dwRead,NULL))
{
nSumBytes = nSumBytes + dwRead;
InternetWriteFile(hFtpOpenFile,inBuffer,(nBytesToReadWrite >= nBytesLeft ? nBytesLeft : nBytesToReadWrite),&dwBytesWritten);
nBytesLeft = lFileSize - nSumBytes;
}
else
{
CloseHandle(hFile);
InternetCloseHandle(hFtpOpenFile);
return false;
}
}while(nSumBytes != lFileSize);
InternetCloseHandle(hFtpOpenFile);
CloseHandle(hFile);
return true;
|
|
|
|
|
Hello !
I have two questions about DirectX:
1) I try to use the transparency property of a DirectDraw Surface (using the SetColorKey method). This works fine when the color keys are pure black or pure white, but it doesn't work for any other color. In this case, the background is drawn also on the screen (instead of being transparent).
2) I need to set pixels color directly. I tried using the DC of the DirectDraw Surface (GetDC method) and then use SetPixelColor with this DC. This works but this is horribly slooooooooooooooow (in fact, I need to use that for a lot of pixels...). Any idea of a better solution ??
Thanks
|
|
|
|
|
problem is memory full. can't free.
in this sample source below.
so, how can i free memory in struct.
////////////////////////////////////////////////
// begin source
typedef struct
{
char* sztext;
int nindex;
}T_TEST_T;
typedef struct
{
T_TEST_T *pptest;
char* sztext;
int nindex;
}T_TEST;
void testRun( )
{
T_TEST *ptest
ptest = new T_TEST;
ptest->pptest = new T_TEST_T;
for(int n=0;n<100000;n++)
{
ptest->sztext = new char[1024];
strcpy(ptest->sztext, "test one deep step !!!");
ptest->nindex = 777;
ptest->pptest->sztext = new char[1024];
strcpy(ptest->pptest->sztext, "test two deep step ");
ptest->pptest->nindex = 888;
}
// + must used ptest in struct +
if( ptest->sztext != NULL )
delete []ptest->sztext ;
if( ptest->pptest->sztext != NULL)
delete []ptest->pptest->sztext;
if( ptest->pptest )
delete ptest->pptest;
if( ptest )
delete ptest;
// can't free memory..
// end source
////////////////////////////////////////////////////////////////////////
thank's see this ~ waiting your reply.
|
|
|
|
|
|
In your structures, and a method for cleaning the memory and call it before detructing you structure. In general, it's better to add cleaning methods INSIDE your objects than to clean them externally...
|
|
|
|
|
ofcouese i know fact that inside delete.
but my situation is must be storing in struct.
so, want to free struct at outside.
|
|
|
|
|
Your problem can be summarized like:
char *p;
p = new char[16];
p = new char[32];
delete [] p; Do you see the problem? Memory was allocated twice but only deleted once.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
// worng source
char *p;
p = new char[16];
p = new char[32];
delete p; // <- delete []p;
/////////////////////////
and my situation is must be storing in struct.
so, want to free struct at outside.
|
|
|
|
|
You must've missed my point. In your code snippet, you are assigning a new value to ptest->sztext and ptest->pptest->sztext 100,000 times. With only two delete s outside of the for loop, you are going to have 199,998 memory leaks of 1024 bytes each, or roughly 195.3MB! Make sense?
Anonymous wrote:
and my situation is must be storing in struct.
It matters not what you are allocating the memory for (e.g., struct, object, int, array). It's a simple matter of having one delete for each new .
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I want to use tab control in MDI.
My Tab contain Image,Button,Edit..etc.(as use dialog).
Tab control is ok in dialog.
But MDI is not ok.
|
|
|
|
|
I want to use mdi with check control.
My code is following..
if (m_chk==1){MessageBox("Check","Test",MB_OK);}
else{MessageBox("Not Check","Test",MB_OK);}
I check control on or off.
Every time appears MessageBox is "Not Check".
|
|
|
|
|
Hi,
you must have to call UpdateData(TRUE) before calling this code.
This may help you
Sujan
|
|
|
|
|
Hi
I have one in-place Directshow transform filter, and I am currently scratching my head looking for ways for the filter to detect that the user is currently seeking through the file (in lieu of the filter playing continous frames). If the user is currently seeking, I want to reset some variables in my filter. Is there a way to do this?
Thanks!
|
|
|
|
|
I want a little of you advice in a making of a computer program.
Actually i recently made a very simple software. It basically captures the "stock market" transactions. After capturing tractions, the decision of buying or selling is made according to some pre defined formulas. For example
1) If total shares purchased are greater than 50 and and stockmarket opening time is 9:30 AM then sell 23 shares.
2) If stock market opening time is greater than 9:30 then do not buy any share till 11:30 and after 11:30 use formula ABC to get share difference and if difference is negative than buy that share.
There are 11 such conditions defined by our client. We've hardcoded all these condiotions in our source code.
Now the problem is that, these conditions are hardcoded and client daily wants to change conditions or define new conditions. Whenever client wants to enter new condition, it call us, then we add such condition or formula in the source code and then send updated copy.
Now we want to make this generic i.e we want to add new feature so that our client can himself add new condition or change existing at runtime. This is where i require your advice. suppose if you were at my place that what had you done ? Does the solution lies in writing parser/compiler.
Imtiaz
|
|
|
|
|
Hi
With my experience I would model all the possiblity and a create a customizable software. The action to be taken could be defined by the client itself.
Represent all the condition by the some variables. And give interface for the client to present their condition using those variables.
Hope it helps you some way
Regards
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
|