|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
What is the difference between two images looking the same, if one uses compression and the other one doesn’t. For example we have images made of 12 pixels with all pixels having the same color, except the first three which are different then the rest. If we consider a color depth of 24 bit the bitmap version will have 12*24 bit, 288 bit total. In the compressed image the first 3 pixels will weight 24 bit and the other ones another 24 bit, 48 total. The start and end pixels marking a color sequence need to be considered too, that’s index 0, index 2, index 3 and index 11. Is that correct?
|
|
|
|
|
Probably not - it depends on the compression method.
There are two different types of image compression: lossless and lossy.
PNG for example is lossless - when it is decompressed to a bitmap for display, the bitmap is identical to the original input bitmap data.
JPG is lossy - when it is decompressed the resulting image is lower quality than the original.
You can prove this with any image editor: load a bitmap, save it as a JPG. Open the JPG, save it as a new JPG. Repeat a few times, and watch how the image size drops, the compare the original with the final result. It doesn't take many iterations before the result as very clear to see.
Do the same with a PNG file and the result will be identical to the original.
There is also the problem that any form of compression adds overhead to the resulting file to manage the compression - and small files or those containing a high degree of randomisation can end up bigger than the uncompressed original as a result!
If you really want to know about image compression, Google / Wiki is the place to start: but be warned that the math gets pretty hairy!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Com Automation latest library for working with ms excel in mfc vosual studio vc++, can anyone suggest from where i get this.
|
|
|
|
|
|
- In VS menu Project -> Add New Item ... ->
- In "Add New Item" dialog select MFC in the treeview left, and then choose the "MFC Class From Typelib" and press the Add button
- In the "Add Class From Typelib" dialog choose the source of interface (registry or file), type libraries and then all the needed interfaces.
- then press OK
|
|
|
|
|
Is there any way in Windows to throttle a process' CPU usage?
If so, what's the technique?
EDITED:
I'm asking if one can programmatically throttle a process' CPU usage. Meaning managing the CPU time that a process is allowed to consume.
The difficult we do right away...
...the impossible takes slightly longer.
modified 19-May-23 22:07pm.
|
|
|
|
|
Not that I've ever seen.
Thinking about it, you might be able to kind of simulate it by limiting the cores the process can run on by setting processor affinity for it.
|
|
|
|
|
|
|
A tiny virtual machine.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
|
This looks awesome. Thanks, David.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
 I know this is the C/C++ forum, but here's an example of how to do this in C#. It was an interesting little research project.
The result can be seen in Task Manager quite easily. The CPU is limited to an AVERAGE of 20% in this example. It'll go as low as 8% and as high as 25% on my 13900K.
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace CsJobObjectSandbox
{
internal class Program
{
[StructLayout(LayoutKind.Explicit, Size = 8)]
public struct JobObject_CPU_Rate_Control_Information
{
[FieldOffset(0)]
public uint ControlFlags;
[FieldOffset(4)]
public uint CpuRate;
[FieldOffset(4)]
public uint Weight;
[FieldOffset(4)]
public ushort MinRate;
[FieldOffset(6)]
public ushort MaxRate;
}
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public IntPtr lpSecurityDescriptor;
public int bInheritHandle;
}
public enum JobObject_Info_Class
{
BasicLimitInformation = 2,
BasicUiRestrictions = 4,
SecurityLimitInformation = 5,
EndOfJobItmeInformation = 6,
AssociateCompletionPortInformation = 7,
ExtendedLimitInformation = 9,
GroupInformation = 11,
NoticiationLimitInformation = 12,
GroupInformationEx = 14,
CpuRateControlInformation = 15,
NetRateControlinformation = 32,
NotificationLimitInformation = 33,
LimitViolationInformation2 = 34
}
private const uint JOBOBJECT_CPU_RATE_CONTROL_ENABLE = 0x1;
private const uint JOBOBJECT_CPU_RATE_CONTROL_WEIGHT_BASED = 0x2;
private const uint JOBOBJECT_CPU_RATE_CONTROL_HARD_CAP = 0x4;
private const uint JOBOBJECT_CPU_RATE_CONTROL_NOTIFY = 0x8;
private const uint JOBOBJECT_CPU_RATE_CONTROL_MIN_MAX_RATE = 0x10;
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern IntPtr CreateJobObject([In] ref SECURITY_ATTRIBUTES lpJobAttributes, string lpName);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern bool SetInformationJobObject([In] IntPtr hJob, [In] JobObject_Info_Class jobObjectInfoClass, IntPtr lpJobObjectInfo, int cbJobObjectInfoLength);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern IntPtr AssignProcessToJobObject([In] IntPtr hJob, [In] IntPtr hprocess);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern bool CloseHandle([In] IntPtr hObject);
static void Main(string[] args)
{
SECURITY_ATTRIBUTES attributes = new();
attributes.nLength = Marshal.SizeOf(attributes);
attributes.lpSecurityDescriptor = IntPtr.Zero;
attributes.bInheritHandle = 0;
IntPtr jobHandle = CreateJobObject(ref attributes, "SandboxJobObject");
JobObject_CPU_Rate_Control_Information cpuLimitInfo = new()
{
ControlFlags = JOBOBJECT_CPU_RATE_CONTROL_ENABLE | JOBOBJECT_CPU_RATE_CONTROL_HARD_CAP,
CpuRate = 2000
};
int size = Marshal.SizeOf(typeof(JobObject_CPU_Rate_Control_Information));
IntPtr infoPointer = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(cpuLimitInfo, infoPointer, false);
bool result = SetInformationJobObject(jobHandle, JobObject_Info_Class.CpuRateControlInformation, infoPointer, size);
if (result)
{
Marshal.FreeHGlobal(infoPointer);
IntPtr processHandle = Process.GetCurrentProcess().Handle;
_ = AssignProcessToJobObject(jobHandle, processHandle);
Task task = TestMethodAsync();
task.Wait();
}
CloseHandle(jobHandle);
}
static Task TestMethodAsync()
{
return Task.Factory.StartNew(() =>
{
long y = 0;
Parallel.For((long)0, (long)10000000000, (x) =>
{
y = x++ * 2;
});
});
}
}
}
|
|
|
|
|
Just out of curiosity, if you set a hard cap of 20%, what causes it to exceed that?
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I don't know for sure, but I suspect thread scheduling on different cores running at different speeds.
On a 13900, you have 8 performance cores, which support HT, and 16 efficiency cores, which don't support HT. So I have 24 cores that can run at vastly different speeds, supporting 32 threads.
|
|
|
|
|
Nice. Learn something new every day.
|
|
|
|
|
I am revoking my license to this
modified 20-May-23 16:42pm.
|
|
|
|
|
This is what we refer to as a "code dump". Usually pointless except in the mind of the poster.
Taking credit for someone else's code it appears. "Signing" with some trivial changes.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Three more kicks and he will be removed.
|
|
|
|
|
Message Closed
modified 19-May-23 21:10pm.
|
|
|
|
|
But failing to address the first comment "Usually pointless except in the mind of the poster."
|
|
|
|
|
Below is my code but note working same header footer is set to all page, please suggest best solution for this.
oWorkSheets2007 = oWorkBook2007.GetWorksheets();
oWorkSheet2007 = oWorkSheets2007.GetItem(COleVariant((short)sheetNum));
XLS2007::Window owindObj = oApp2007.GetActiveWindow();
XLS2007::Pages oPages = owindObj.GetPanes();
oPageSetup = oWorkSheet2007.GetPageSetup();
oPages = oPageSetup.GetPages();
long a = oPages.GetCount();
int l=0;
for( l=l+1;l<=a;l++)
{
oPage= oPages.GetItem(COleVariant((short)l));
oPageSetup = oWorkSheet2007.GetPageSetup();
oPageSetup.SetPrintErrors(1);
oPageSetup.SetAlignMarginsHeaderFooter(HFI.bAlignWithMargins);
oPageSetup.SetScaleWithDocHeaderFooter(HFI.bScaleWithDoc);
oPageSetup.SetCenterHeader(LPCTSTR(HFI.FirstCentreHeader));
oPageSetup.SetCenterFooter(LPCTSTR(HFI.FirstCentreFooter));
oPageSetup.SetLeftHeader(LPCTSTR(HFI.FirstLeftHeader));
oPageSetup.SetLeftFooter(LPCTSTR(HFI.FirstLeftFooter));
oPageSetup.SetRightHeader(LPCTSTR (HFI.FirstRightHeader));
oPageSetup.SetRightFooter(LPCTSTR(HFI.FirstRightFooter));
oPageSetup.SetCenterHeader(LPCTSTR(HFI.OddCentreHeader));
oPageSetup.SetCenterFooter(LPCTSTR(HFI.OddCentreFooter));
oPageSetup.SetLeftHeader(LPCTSTR(HFI.OddLeftHeader));
oPageSetup.SetLeftFooter(LPCTSTR(HFI.OddLeftFooter));
oPageSetup.SetRightHeader(LPCTSTR(HFI.OddRightHeader));
oPageSetup.SetRightFooter(LPCTSTR(HFI.OddRightFooter));
|
|
|
|
|
The (incomplete) for() loop looks a bit odd in that it is using the same values for the header and footer and the set methods are called twice. If you are wanting the header/footer on the even pages to be different than the header/footer on the odd pages then you are going to have to check whether l is odd or even and use a different value accordingly.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|