|
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?
|
|
|
|
|
I'd like to run the function defined as 'void CEnumProcessTestDlg::Run();'
for every 100 milliseconds. I try to use timeSetEvent,setTimer but I couldn't manageto run these functions. I know that I must use these functions, but I couldn't.I think My declerations are wrongly. How can I run my function for every 100 ms.?
|
|
|
|
|
Use a CALLBACK function. When you set up a CALLBACK function, you are setting up an Event function which gets called whenever the specified event happens, in your case 100ms has passed.
<br />
void SetTestTimer() { _TimerID = timeSetEvent(_TimerRate, 0, &Run, (DWORD)this, TIME_PERIODIC); };<br />
then define your Callback in the header (and as appropriate in the .cpp) as :
<br />
static void CALLBACK Run(UINT wTimerID, UINT msg, UINT dwUser, DWORD dw1, DWORD dw2);<br />
The CALLBACK must be static and have those parameters to run from SetTimer because they act as a function signature, otherwise the function will never get called . Have a nice day.
Alan.
"Once I was but the Learner, now I am the Master" [Darth Vader]
|
|
|
|
|
Hi all, I'm almost there with my array template class, I just have one horrid problem before success . OK, I'm reserving a raw memory chunk using malloc/realloc. If T is an object I am then using the placement new operator (default) to construct the objects inside this reserved block, otherwise I am doing a block initialise on the data. Here's the problem, when I have an array of chars, everything is fine (the placement new path is not necessary), however if I have an array of
<br />
class MyClass<br />
{<br />
public:<br />
MyClass(void);<br />
~MyClass(void);<br />
<br />
array<char> string1;<br />
array<char> string2;<br />
};<br />
<br />
HRESULT Allocate(unsigned int alloc)<br />
{<br />
unsigned int size = sizeof(T);<br />
if(size > 4)<br />
{<br />
m_pItem = malloc(alloc*size);<br />
<br />
new(m_pItem) T[alloc];<br />
}else...<br />
}<br />
Malloc reserves enough space for say 10 of these objects and returns a pointer to the data which is stored. The placement new operator then gets passed this pointer, but fatally constructs the object 4 bits on from m_pItem. Its strange because my debug window says new[] returned 0x00322c50 yet if I use T* p = new(m_pItem) T[alloc]; instead, p = 0x00322c54 but the debug window still claims 0x00322c50 was returned??? Also m_pItem shows complete garbage in the debug window (so it ain't there), but looking at the mem address 0x00322c54, I can see the object has been nicely constructed there. What the hell is going on?
|
|
|
|
|
OK, just managed to find out that when you use new(m_pItem) T[alloc] - the array form of placement new, it may, depending on the object, add some extra overhead to the allocation. Urrrggghhh. Apparently its safer to just loop through the number of objects and use the non-array placement of new - new(m_pItem) T;, which doesn't add any overhead, and everything is hunky dory. What a crock of sh*t. Now all I need to do is figure out how to destroy objects without making a fuss or memory leak .
Alan.
|
|
|
|
|
Hi !
I'm developping using the Visual C++ environnement, but I'm not using the MFC nor the Win32 API directly. Thus, I'm thinking about using another editor for my C++ sources.
Any suggestions, or is the Microsoft's editor the best ?
Thanks !
Jerome
|
|
|
|
|