|
I am having a Drop down list box which contains values as A,B,W,X,Y,Z. Only for the first time, the Dropdown list having the name corresponding to the key pressed gets displayed. But for the next key strokes, the corresponding name is not displayed.How to display the value corresponding to the key strokes?
Thanks,
|
|
|
|
|
|
|
I removed the "Sort" property for the drop down box.
modified on Thursday, June 11, 2009 6:04 AM
|
|
|
|
|
How 2 display a message box when the user clicks in the client area in MFC just for SDI application a very basic question.
Plz tell me where to write a code when we create a Appliacyion by the name of MyApp
|
|
|
|
|
What about a MFC tutorial [^]?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
deadlyabbas wrote: How 2 display a message box when the user clicks in the client area in MFC just for SDI application...
Are you wanting to know: 1) how to display a message box, or 2) how to detect a mouse click in the client area of an SDI view?
deadlyabbas wrote: Plz tell me where to write a code when we create a Appliacyion by the name of MyApp
What in the world does this mean?
"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 Want to know how to inherit the explorer's new environment block to a process
|
|
|
|
|
All processes automatically inherit the environment block of its parent process. If the process is created with the CreateProcess Function[^] then you can pass a pointer to a new environment block in the lpEnvironment argument.
Some additional MSDN information:
Changing Environment Variables[^]
Best Wishes,
-David Delaune
|
|
|
|
|
I have sample which will set the environment variable and broadcast the message tat setting has been changed. Except the current process which set the environment variable all the other windows are getting the new change. How to get the new changed environment for the current process.
|
|
|
|
|
Calling the SetEnvironmentVariable() with the new value will change the current process' environment variable.
|
|
|
|
|
Yaa it's working fine but here i have a doubt the variable is set at system level or user level ?
If it sets at system level the setting of environment will fail when i run my application in power user or guest user
|
|
|
|
|
|
What do you think about menu of that program? each program has a option on its menu(Save) you can find it ID of save option and then send your query to it.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
|
No its not.
If you click on the current program(for example IE) you can see File->Save,it has a id for example IF_FILE_SAVE for Save or ID_FILE_CLOSE for Exit you need to get a handle to this menu of this program(or for other programs (you can use of FindWindow or Enumwindow for get a hwnd to that program and then you can use of that handle on the ::GetMenu()) then you can use of GetSubMenu for a handle to the pop up menu and then you can send your request.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
What about keybd_event(VK_CONTROL | 0x53) ?
"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 successed in redirecting console to my program.All commands are executed well except some special characters.
My system is Windows XP Professional Chinese Edition.
Example in cmd.exe:
C:\Documents and Settings\Administrator>|
此时不应有 |。
C:\Documents and Settings\Administrator>
But in my program,it goes:
C:\Documents and Settings\Administrator>|
C:\Documents and Settings\Administrator>
In the debugging,I find that ReadFile() which reads feedback from the console only get '|',but no more characters,which should be a string as "此时不应有 |。"
What's wrong with it?
|
|
|
|
|
|
I think it's not about Chinese characters.My program can work well as follow:
C:\Documents and Settings\Administrator>xxxx
'xxxx' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
C:\Documents and Settings\Administrator>
|
|
|
|
|
I have a windows client application that connects to a Linux daemon, both written in C++. One of the functions simply sends files from a particular directory on the Linux server back to the windows client app. The client app then unpacks the buffer and writes the files. This all works perfectly as long as none of the files on the server are larger than around 1mb. If files larger than this are packed the daemon crashes in the call to send the data. I've done a binary dump into a file prior to attempting to send the data (ie. prior to a crash) and all the files are packed in there perfectly
The code to pack the files on the Linux server is (with all error checking removed for clarity):
bool ClassName::PackSoftwareUpdateBuffer(char* baseDirectory, unsigned char* pBuffer)
{
int return_code;
char buf[1024];
dirent entry;
dirent *result;
struct stat st;
DIR* dir;
Directory *pDir = NULL;
Directory *pCurr = NULL;
Directory *pd = NULL;
Directory *pCurrDir = NULL;
int fd = 0;
size_t bytesread;
do
{
if(pCurrDir)
{
sprintf(buf, "%s/%s", baseDirectory, pCurrDir->DirectoryName);
dir = opendir(buf);
*pBuffer++ = '$';
strcpy((char*)pBuffer, pCurrDir->DirectoryName);
pBuffer += 199;
}
else
{
dir = opendir(baseDirectory);
}
for(return_code = readdir_r(dir, &entry, &result); result != NULL && return_code == 0; return_code = readdir_r(dir, &entry, &result))
{
if(pCurrDir)
sprintf(buf, "%s/%s/%s", baseDirectory, pCurrDir->DirectoryName, entry.d_name);
else
sprintf(buf, "%s/%s", baseDirectory, entry.d_name);
stat(buf, &st))
if(S_ISDIR(st.st_mode))
{
if(pCurrDir)
{
sprintf(buf, "%s/%s", pCurrDir->DirectoryName, entry.d_name);
pd = new Directory(buf);
}
else
pd = new Directory(entry.d_name);
if(pCurr)
pCurr = pCurr->pNext = pd;
else
pDir = pCurr = pd;
}
else
{
strcpy((char*)pBuffer, entry.d_name);
SET_BUFFER_UINT32(pBuffer, 50, st.st_size);
fd = open(buf, O_RDONLY);
pBuffer += 54;
read(fd, (void*)pBuffer, st.st_size);
close(fd);
pBuffer += st.st_size;
}
}
closedir(dir);
if(pCurrDir)
pCurrDir = pCurrDir->pNext;
else
pCurrDir = pDir;
if(!pCurrDir)
break;
}while(true);
DeleteDirectoryStructs(pDir);
return true;
}
Where a Directory is a struct declared/defined as:
struct Directory
{
char DirectoryName[1024];
Directory *pNext;
Directory(char* dirName)
:pNext(NULL)
{
strcpy(DirectoryName, dirName);
}
};
The SET_BUFFER_UINT32 macro simply packs a numeric value into the buffer in network byte order. The pBuffer value passed into the function is a pointer to dynamically allocated memory. This is allocated in 1 mb chunks and always well and truly exceeds the amount of file data packed into the buffer (I have checked and re-checked this as it seemed the obvious reason for the issue). The crash occurs in the following function in the first call to send:
int ClassName::Write(unsigned char *buffer, unsigned int size)
{
int num = 0;
char *bufP = (char *)buffer;
unsigned int total = 0;
do
{
if((num = send(m_socket, (bufP + total), (size - total), 0)) <= 0)
{
return num;
}
total += (unsigned int)num;
}
while (total < size);
return total;
}
The buffer is the same buffer passed into the function to pack the data. If I comment out the call to read in the PackSoftwareUpdateBuffer function no crash occurs. Likewise if I set it so that only files less then one mb are read no crash occurs. In both cases the pBuffer pointer had the file size added to it, the same amount of data was sent if all the files were read, and the files were all successfully recreated on the client (albeit, filled with zeroes for the large files).
Bizarrely if I move the line: pBuffer += st.st_size; to above the call to read no crash occurs?!? This suggests to me there is something elementary I am completely missing. Any pointers much appreciated.
modified on Thursday, June 11, 2009 12:18 AM
|
|
|
|
|
- Where is the pBuffer allocated?
- How is the SET_BUFFER_UINT32 macro implemented?
With those obscurity.
How much memory is allocated for pBuffer? Its pointer value is increasing eternally within the loops. Never decreasing!
|
|
|
|
|
The pBuffer is allocated in a buffer wrapper class. Memory is allocated in 1mb chunks. I call another function to calculate the amount of buffer space required prior to calling PackSoftwareUpdateBuffer. The code for this function is similar to PackSoftwareUpdateBuffer except it never actually opens a file. Just uses the stat call to add up the total number of bytes required. I've checked to make sure it does this accurately using tracing. The buffer class allocates memory as follows (error checking removed):
bool CBuffer::InternalAlloc(unsigned int nBytes)
{
unsigned int nBytesToAllocate = (m_nBytesAllocated ? m_nBytesAllocated : 1048576);
while(nBytesToAllocate < nBytes)
nBytesToAllocate *= 2;
if(m_pMemory)
free(m_pMemory);
m_pMemory = (unsigned char *)malloc(nBytesToAllocate);
m_nBytesAllocated = nBytesToAllocate;
return true;
}
The SET_BUFFER_UINT32 macro is #define'd as follows:
#define SET_BUFFER_UINT32(buf, offset, value) \
buf[offset] = (value >> 24) & 0xff; \
buf[offset + 1] = (value >> 16) & 0xff; \
buf[offset + 2] = (value >> 8) & 0xff; \
buf[offset + 3] = value & 0xff;
Any ideas appreciated.
|
|
|
|
|
Well. The macro is using to store 32-bits size value in proper order, it's clear. But, I can't say that I understood the memory allocation exactly. Lets consider a fictive situation. m_nBytesAllocated is 10485760 bytes (10 MB) before the call to InternalAlloc member. if the requested nBytes is 10485761 bytes, 20 MB of space will be allocated. Sure?
Considering that you are sure, there isn't any buffer overflow problem. And I think that your linux daemon runs on a different CPU architecture, is it possible that there would be a page boundary problem in reading from a device?
The buffer will be passed to read function is starting with offset 54. Try to handle that value aligned in a page boundary consulting your CPU manuals. Or give it a try with a higher fabricated value for a page (e.g. 64K).
|
|
|
|
|
Your are correct about the memory allocation routine being, well, a little over generous. I need to tweak the allocation routine. The Linux daemon runs on x86 (for testing - x64 for production). You may have a point with the page alignment, I'll look into that.
|
|
|
|