|
Is there a way to set a size for message queue? Also is there any performance consideration to be made while selecting PeekMessage or GetMessage.
-- modified at 5:13 Sunday 8th July, 2007
|
|
|
|
|
tom groezer wrote: Is there a way to set a size for message loop?
loops have a size?
tom groezer wrote: is there any performance consideration to be made while selecting PeekMessage or GetMessage.
In a loop, yes. GetMessage() will wait for posted messages. PeekMessage() will not.
Looping calling PeekMessage() when no messages are available in the queue will use CPU time
needlessly.
Mark
This episode brought to you by the letter N
|
|
|
|
|
I think you can set a quota.
I am pretty sure the upper limit is 10,000 messages.
We have abandoned 'window message queues' in a few areas because of the limit.
Given the nature of your other queries, you might want to consider using TCP/IP or named pipes for your interprocess communications.
|
|
|
|
|
How could I achieve versioning of archive files.
|
|
|
|
|
The simplest way would be to insert a version number when storing (before writing anything else)
and when loading, extract the version number and use it to appropriately load the archive.
Mark
This episode brought to you by the letter N
|
|
|
|
|
I need to write a console application to write a state log. It will be executed as a task periodically and record the condition of things to a log file.
When I execute the application it causes the screen to flicker in the best of circumstances and a phantom console window to appear and disappear in the worst of circumstances even though I don’t write anything to the console. Everything is appended to a log file.
Is there any way of suppressing the flicker or phantom console window from appearing?
|
|
|
|
|
For similar problems I always recommend switching from a Console app to a Windows app and then not actually opening any Windows. Most of my test apps run that way.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I was thinking about running a windows application instead of a console application but need to pass command line parameters. Is there a way to get the equivalent of the argv array when executing a windows app?
|
|
|
|
|
Check out the remarks section here: GetCommandLine()[^]
This episode brought to you by the letter Q
|
|
|
|
|
Mark Salsbery wrote: GetCommandLine()
Excellent! That along with Mathew's suggestion to use a windows application is just what I need to get rid of the flicker.
|
|
|
|
|
Can we overload a function by return type?
|
|
|
|
|
|
The simple answer is no. Two functions which differ only by return type are not allowed.
You can make a function return a template defined type but unless that type is also used for one of the parameters you're going to find it hard to get the compiler to recognise which type you intend to replace your template argument with in any given case. some experimentation required I think.
You could consider passing in the return value by reference and then you'd have no problem doing ordinary overloading.
int Myfunc(void)
{
}
float Myfunc(void)
{
}
void Myfunc(int& iRef)
{
}
void Myfunc(float& fRef)
{
}
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
No. Because when you call the function the compiler won't be able to know which overload you're calling.
|
|
|
|
|
In general no. The only exception (I believe) is casting operators.
Steve
|
|
|
|
|
english word for base-2 number is binary, for base-8 and base-16 are octal and hexadecimal respectively.
but:
which english word is for base-4 number?
i can not find it in google, maybe you know it.
thx.
|
|
|
|
|
|
The more interesting question is:
If "bit" is the abbreviation for "binary digit", what would be the abbreviation for "ternary digit"?
|
|
|
|
|
trits
This episode brought to you by the letter N
|
|
|
|
|
Then we will have to call "bits" "brits".
|
|
|
|
|
in Chinese they're simply called "base-2 number", "base-3 number", "base-4 number", etc. So maybe Chinese isn't as difficult as it seems~
|
|
|
|
|
I cant get SACL of an existing file on my system with this code.
GetNamedSecurityInfo returns 0 (ERROR_SUCCESS) , which means
there is no error in execution of it but pSACL still becomes 0x00000000
and IsValidAcl(pSACL) returns FALSE .
#include <windows.h>
#include <aclapi.h>
unsigned long enable_privilege(const char *priv)
{
HANDLE token = INVALID_HANDLE_VALUE;
u status = OpenProcessToken(
GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES,
&token
);
if( !status )
{
return GetLastError();
}
unsigned char buf[sizeof(TOKEN_PRIVILEGES) + sizeof(LUID_AND_ATTRIBUTES)];
TOKEN_PRIVILEGES *privs = (TOKEN_PRIVILEGES*)buf;
status = LookupPrivilegeValue(
NULL,
priv,
&privs->Privileges->Luid
);
if( !status )
{
u err = GetLastError();
CloseHandle(token);
return err;
}
privs->PrivilegeCount = 1;
privs->Privileges->Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(
token,
FALSE, // do not disable all
privs,
0, // zero buffer for prev state
NULL, // prev state don't care
NULL // no sink for returned prev state size
);
status = GetLastError();
CloseHandle(token);
return status;
}
int _tmain(int argc, _TCHAR* argv[])
{
PACL pSACL = NULL;
PSECURITY_DESCRIPTOR pSD = NULL;
unsigned long returnValue ;
enable_privilege(SE_SECURITY_NAME );
returnValue = GetNamedSecurityInfo(
"D:\\aa.txt", // object name
SE_FILE_OBJECT, // object type
SACL_SECURITY_INFORMATION, // information type
NULL, // owner SID
NULL, // primary group SID
NULL, // DACL
&pSACL, // SACL
&pSD); // SD
if(!IsValidAcl(pSACL))
printf("FAILED , ERROR CODE : %d\n\n",returnValue);
LocalFree(pSD);
return 0 ;
}
|
|
|
|
|
Hi, I'm new to Visual C++ 2005, and I'm trying to create a simple "hello world" kernel. Can I use Visual C++ 2005? I've tried "Win32 Console Application", the PE result still call Windows dependent library. Are there some arguments I must pass to "CL.EXE" so I can get clean "PE EXE"?
Can "LINK.EXE" create another binary interface except PE/COFF? And why we cannot relocate the PE base location to a value below 64K? I still new to PE too.
Btw, I heard about "ML.EXE". Is that full version of MASM packaged together with Visual C++?
|
|
|
|
|
If by 'kernel' you mean something that runs without another operating system present, you can't do it in Visual C++ 2005 unless you already have a bootloader that gets the system into 32-bit (or 64-bit) protected mode. The PC traditionally starts up in 16-bit Real Mode - you'll need a 16-bit real mode compiler to write code for this mode. Microsoft's last 16-bit compiler was Visual C++ 1.52c, which is available to MSDN subscribers. I believe Extensible Firmware Interface switches to 64-bit protected mode within the early ROM boot code - 32-bit EFI exists but Microsoft aren't supporting it for Windows Vista (64-bit EFI on x64 is due to be supported in Windows Vista SP1 and Windows Server 2008).
To stop the compiler and linker producing an executable that links to any Win32 DLLs, you need to tell it not to link the Microsoft C Runtime. You do this with the /nodefaultlib switch. You will also need to change the entry point function; by default this is (for an ANSI console application) mainCRTStartup . You need to supply your own with the /entry switch. If you were producing a Windows binary the entry point function would need to match the WinMain function.
LINK only supports generating 32-bit (or 64-bit) PE/COFF outputs. It can accept Borland's Object Model Format files but not create them. Windows only runs PE files - even the Windows kernel, NTOSKRNL.EXE, is a PE file, as are device drivers (they're linked /DRIVER /SUBSYSTEM:NATIVE).
The PE base address cannot be below 64KB as the first 64KB of the address space is reserved in Windows. This is so that functions that take a resource identifier can differentiate between a numeric identifier (a value below 65536 cast to an LPTSTR) and a string identifier.
ML is the macro assembler - it stopped being a separate product a while ago. Again, it's designed to produce PE/COFF files. I'm not sure which Visual Studio editions it ships with - it might not be in Express Edition.
|
|
|
|
|
Mike Dimmick wrote: you can't do it in Visual C++ 2005 unless you already have a bootloader that gets the system into 32-bit (or 64-bit) protected mode.
I just realized why some CALL in code section use 4 bytes displacement instead of 2 bytes. Thanks, I'll create a code to switch to protected mode first before calling the PE. Because the PE is memory-mapped, I think I can just load the PE into memory and jump into it entry-point from image-base.
Thanks.
|
|
|
|