|
Here's a good hint from writing software. Always do your best to seperate your UI from your back-end.
Your issues of how to display stuff is one thing, but what you actually intend to do here is: post a interpretable message from one client to another. Most chat programs do this by either using a specific packet/message format -- or use some "RPC".
Ignore the RPC for now.
What I think you need to do, is define a message format. This message format is something used by one client to convey one of many possible messages to another client.
The message that you want to send needs to be able to contain:
* identification of what type of message you are sending
* its good to include the size of the whole message
* and the "message" itself.
I should say, that my use of the word "message" should not be confused with a "chat message". This is a broader term for any bit of communication from one client to another.
In instant messaging, these messages are commonly:
* "instant message"
* "i want to log in and here's my password"
* "i am logging off"
* "here's a file"
* "i am away"
stuff like that.
You might consider XML as a nice and easily interpretable way to send messages.
But more often than not, the "message" is sent a data block.
Here's a possible message format -- this is a "message header";
[Message-Type: stored as a DWORD]
[Message-Length: stored as a DWORD]
With this information, you can now interpret the packet/message to determine what the caller wants to tell you. Message-Type of (3) might mean that you are "away". and a (6) might mean "i want to transfer a file".
Depending on the message ID, the data that follows will be in the format appropriate to that message type....
I'll leave you with this -- but I hope these clues help.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
Hi,
can anyone help how to create a Menu dynamically in a MFC application ?
Thanks in advance
ram
|
|
|
|
|
|
The AppWizard-generated class for your main window is named CMainFrame and it's derived from CFrameWnd. CFrameWnd, in turn, is derived from CWnd, and CWnd has a bunch of easy-to-use member functions like SetMenu(). Play around with those.
|
|
|
|
|
Hi,
is there a Win32 API to check if a file is an executable (that can be passed to CreateProcess)?
IIRC there was one, but I can't remember....
"Dor säggsische Dialeggt eechnet sich wie keeen onderor für den Ausdrugg zäärdlischor Gefiehle."
sighist | Agile Programming | doxygen
|
|
|
|
|
I don't know any direct API that can be just called with filename returning true/false if it's a EXE.
This one can be a good starter - doing something different, but in fact very similar
Q90493 - HOWTO: How To Determine Whether an Application is Console or GUI
Or I would look to Image Help Library (obsolete - better use DbgHelp) might be there will be some handy functions.
hope this helps
|
|
|
|
|
|
Which would not work on files such as screen savers.
SHGetFileInfo(_T("C:\\WINNT\\system32\\ssbezier.scr"), 0, &fi, sizeof(fi), SHGFI_EXETYPE);
Would return a value of 0, indicating it is not an executable, when in fact it is.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Try this code snippet:
HANDLE hFile;
IMAGE_DOS_HEADER DosHeader;
DWORD dwBytes,
dwBytesRead;
IMAGE_NT_HEADERS NTHeader;
hFile = CreateFile(szFilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (INVALID_HANDLE_VALUE != hFile)
{
dwBytes = sizeof(IMAGE_DOS_HEADER);
if (ReadFile(hFile, &DosHeader, dwBytes, &dwBytesRead, NULL) != FALSE)
{
SetFilePointer(hFile, DosHeader.e_lfanew, NULL, FILE_BEGIN);
dwBytes = sizeof(IMAGE_NT_HEADERS);
ReadFile(hFile, &NTHeader, dwBytes, &dwBytesRead, NULL);
if ((NTHeader.FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE) == IMAGE_FILE_EXECUTABLE_IMAGE)
MessageBox(_T("File is executable"), _T(""), MB_OK);
}
CloseHandle(hFile);
}
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi all
My application used 2 threads ,2 apartments more exactly. First one is main STA and second is MTA. Into main STA I create COM object , approximately this way:
Void main(){
CoInitializeEx(NULL,COINIT_MULTITHREADED);
CmyObjPtr pObj(CLSID_ CmyObjPtr);
pObj->DoSomethere();
…
}
Sometime arise distinguished trouble my object invoke itself method (ie pObj->DoSomethere();) haven’t time to be created because of it accomplished into other thread.
How I can avoid this??? I try to use a great deal of synchronized methods, for this purpose such as creating critical section in DllGetClassObject function and this code
While(pObj == NULL){
Sleep(10);
}
But program not exit from this loop if pObj don’t be created from enter into loop.
Thanks.
|
|
|
|
|
You need to use a CRITICAL_SECTION or MUTEX to force the thread not to continue until the other thread holding the MUTEX returns it. Basically wrap the initialisation up in the mutex so you know it will complete it before the component is used. MSDN will be able to help you on this, its a bit too involved to explain on the forum.
Alan.
|
|
|
|
|
Hi all,
I'm trying to add a splash screen to a dll inside DllMain (process_attach) and the docs says there are lots to think about. E.g I can not call functions outside kernel32.dll, etc...
Now I need to know where I can find a table of all functions listed in kernel32.dll? Anyone?
The docs also says I can not call any registry functions... by if I want to do this, how can I go on?!
/Tommy
|
|
|
|
|
if you mean name of this function then you can use Depends application from VC tools.
|
|
|
|
|
The reason for the restriction is that you don't know what order the loader will decide to initialise DLLs in, and you shouldn't use any DLL that hasn't been initialised.
The only DLL it's always safe to use at this point is kernel32.dll, because that's where the Win32 bit of process setup lives - it's guaranteed to be initialised first.
A large amount of the GUI code lives in User32.dll and Gdi32.dll, so you shouldn't do what you're proposing to do. If you must do it, delay it until some other function in your DLL is called. Personally I would advise not doing it at all.
For information on how the .NET Framework breaks these rules, and the impact that has, read Chris Brumme's blog entry[^] on the subject.
|
|
|
|
|
Tommy Svensson wrote:
Now I need to know where I can find a table of all functions listed in kernel32.dll? Anyone?
Depends.exe
dumpbin /exports
are two that I know of.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
im writing a drawing app in mfc, i just want to know how to let the user add text, ..im using the the tutorial off msdn called drawcli. if anyone knows alot about this tutorial, all the help is needed, but this is more important right now
thanks Ryan
smile...its your destiny
|
|
|
|
|
One solution is an edit control.
Kuphryn
|
|
|
|
|
im looking for more like the text button on paint...ie the user clicks on the button, then clicks on a place on the drawing area and is able to write text there...then should beable to drag and drop the text if neccesary
smile...its your destiny
|
|
|
|
|
i encouter the following problems:
1) when i declare an int for textfile and wan to assign it to dialog int member variable, the value output is not the same as in the textfile and also has this warning that my member variable eg, int m_temp is nt referenceed.
2)how to output more than 2 words per line from a textfile coz it always output only the 1st word.
thanx!
|
|
|
|
|
coda_x wrote:
1) when i declare an int for textfile and wan to assign it to dialog int member variable, the value output is not the same as in the textfile and also has this warning that my member variable eg, int m_temp is nt referenceed.
I don't quite understand what you're after here. How about a code snippet?
coda_x wrote:
2)how to output more than 2 words per line from a textfile coz it always output only the 1st word.
You didn't mention what type of file object you had so I'm going to show you an example using a CStdioFile object.
CStdioFile file("somefile.txt", CFile::modeCreate | CFile::modeWrite);<br />
file.WriteString("word1 word2 word3 word4\n");
or
file.WriteString("word1 ");<br />
file.WriteString("word2 ");<br />
file.WriteString("word3 ");<br />
file.WriteString("word4\n");
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi,
Is it possible to get the command line of a process thanks to its id or handle ?
Thank in advance.
Robin.
|
|
|
|
|
Here is one solution from MSDN.
http://support.microsoft.com/defaul...&NoWebContent=1
Kuphryn
|
|
|
|
|
Whenever I'm opening a CFileDialog, like:
CString filepath;
CFileDialog file(FALSE);
if(file.DoModal()==IDOK){
filepath = file.GetPathName();
}
else{
AfxMessageBox("File Save cancelled");
return;
}
The OS is loading quite a lot of memory all at once. Even if I press the CANCEL button and close the dialog box, the memory usage doesn't decrease.
Any suggestion how to kill it.
|
|
|
|
|
Make sure you're measuring the right thing.
If you're looking in Task Manager, the 'Mem Usage' column is in fact the working set size. The 'working set' is the amount of physical memory currently assigned to your program, and includes any code or data shared with other processes.
When you create a common dialog, Windows has to swap in the code from the common dialogs DLL, comdlg32.dll . Thus your working set increases.
However, Windows will only trim your working set (swap out physical pages) when the working set exceeds a particular size, or when memory demand is high. You might not see the working set decrease again in the lifetime of your process.
If you suspect a leak, monitor the 'VM Size' column in Task Manager. This shows the actual amount of virtual memory which is committed by your process (again including code size, which might be shared). You might still see an increase if the common dialogs DLL - or MFC - perform any one-time allocations for the process - some DLLs do so.
Changes in this column will only catch memory allocated with VirtualAlloc or a growing heap; it won't catch small leaks in your heap (since the VM size of the heap will only change if the heap needs more memory to manage). For that, see the crtdbg.h header file.
|
|
|
|
|
Read this article and then decide if you still want to pursue this:
http://www.flounder.com/howbig.htm
Yes, there are ways of making your EXE/DLL smaller, or even use a tad less memory, but you have to weigh the investment with the return on that investment. See here:
http://msdn.microsoft.com/msdnmag/issues/01/01/hood/default.aspx
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|