DisableProcessWindowsGhosting() is supported with XP SP1 and later. If your app must support older Windows versions, you must check the version. You can use late binding by getting the function address with GetProcAddress()[^]:
typedef void (WINAPI* LPFN_DisableProcessWindowsGhosting)();
HINSTANCE hInst = ::GetModuleHandle(_T("User32"));
LPFN_DisableProcessWindowsGhosting lpfnFunc =
TRACE("DisableProcessWindowsGhosting() is not supported\n");
This will also solve your problem regarding the old SDK header files.
I am looking for a simple, basic, preferable a C way of parsing multipart/form-data POST request from a client browser. So far I have a really simple web server, which reads web browser requests in a loop and prints them to to command prompt window:
len = recv(..., input_buf, ...);
while (!strstr(input_buf, "\r\n\r\n") && len > 0);
// Try to parse header and datachar * pch = nullptr, *context = nullptr;
pch = strtok_s(input_buf, "\r\n", &context);
while (pch != nullptr)
pch = strtok_s (nullptr, "\r\n", &context);
When this web server starts, it just shows the following web form to the web browser:
So far so good, ok, I connect to my server with firefox, select some test text file, which is a really small one - just a couple of bytes and hit an html form submit button. Server reads request and I have the following output in command prompt window:
But the question is, how do I get file data? I was reading tons of online docs, when it says something about boundary strings - I have no idea what are boundary strings. I am just trying to figure out how to grab raw bytes file data. I cannot use any 3rd party libraries. And what concerns me, is that Content-Length is zero - seems like file was not transferred at all
Can anyone help me with this?
Thanks in advance
I have a application have hte trayIcon with a Close menu, and it needs keep identical with task bar right click menu.
But if a Modal window shows, the application cannot be closed if uses [close] menu on the task bar, so I need to check if a modal window is showing, when user click the close menu on the tray icon.
I would suggest setting an application wide flag whenever a modal dialog is displayed.
The flag could be set in the WM_INITDIALOG handler.
When the modal dialog is closed, the flag can be reset.
These actions could be repeated for all modal dialogs in the application.
The same flag can then be checked from the tray.
«_Superman_» I love work. It gives me something to do between weekends.
Normally from the taskbar close menus you should send only WM_CLOSE to the main window and you should handle the program exit and "exit possible" flag from the WM_CLOSE handler of your main window. I would extend Superman's solution by using a counter instead of a bool, everytime a modal dialog opens increase the counter and everytime a modal dialog closes decrease the counter. If you have a lot of modal dialogs then you could automatize this by inheriting your dialog classes from a common class and you could implement this feature only once for all dialogs in the base class. So it is OK to close the main window only if your dialog counter is zero. Optionally you can grey out the close buttons/menuitems when the counter is nozero.
EDIT: Here is an alternative solution that MAY WORK, I haven't tried it: Usually when at least one modal dialog is active all other windows/dialogs in the background are disabled (with EnableWindow()[^]). So if the main window is disabled we can suspect that it is disabled because of a modal window (unless you are disabling it manually that I doubt). In this case you could use the IsWindowEnabled()[^] function on the main window to detect whether it is enabled or disabled. So all you have to do is cancelling the main window close (from your WM_CLOSE handler) if the main window is disabled (plus all you should do from your context menu close command is sending a WM_CLOSE to the main window so your WM_CLOSE handler will handle the main window close command regardless of the source of the command). CWnd also has an IsWindowEnabled()[^] method besides the winapi IsWindowEnabled().
I created a MFC dialog using CDHtmlDialog and added a HTML page with many controls and one of them is a IMAGE tag. I got a default image loaded from the hard drive displayed in the HTML page. Up to this part, everything works fine.
Now what i want to do is, dynamically change the image based on the user click on one of the HTML buttons. I don't want this image source to be hard coded in the HTML nor the image source send from the MFC app.
What i want is for the MFC app to send the image data to the HTML in some (binary) format and then the page to display the image.
I am not even sure whether this is possible. So basically what i want is for the HTML page to display a image from the memory.
Can anyone guide me on how to do this? What approach needs to be taken?
What you're supposed to do is respond to the button click by generating new HTML on the fly, and telling the HtmlDialog to load it. I don't recall the exact function names, but you'll find it all in the documentation.
The difficult we do right away...
...the impossible takes slightly longer.
So the 1st question is,
1. How to read a Image file as memory buffer (unsigned char *) in MFC? i.e, making sure it doesn't loose any NULL terminators or any binary contents.
And 2nd question is,
And 3rd question is,
The reason why i want to do it this way is because the HTML should never be able to display the Image file from a file path or URL. That is a requirement for the project i am doing.
HTML page should only use a memory buffer containing the Image file info. Hope this information helps.
Thanks in advance. I appreciate the 2 earlier responses i got.
I am going to assume you will follow what Richard said and reload the HTML in the dialog. I am also going to assume that you are able to modify the HTML from within your code.
In this case, you should be able to achieve what you want by embedding the image as Base64 encoded data, but note that this process increases the size of your data. This is also know as The Data URI Scheme: http://en.wikipedia.org/wiki/Data_URI_scheme[^]
Here is the description:
Consider lists of numbers from real-life data
sources, for example, a list containing the number of students enrolled in different
course sections, the number of comments posted for different Facebook status
updates, the number of books in different library holdings, the number of votes per
precinct, etc. It might seem like the leading digit of each number in the list should
be 1–9 with an equally likely probability. However, Benford’s Law states that the
leading digit is 1 about 30% of the time and drops with larger digits. The leading
digit is 9 only about 5% of the time. Write a program that tests Benford’s Law. Collect a list of at least one hundred numbers from some real-life data source and enter them into a text file.
Your program should loop through the list of numbers and count how many times 1 is the
first digit, 2 is the first digit, etc. For each digit, output the percentage it appears
as the first digit. If you read a number into the string variable named strNum then you can access
the first digit as a char by using strNum .
And Here is how I got so far:
Programming Language C++ (I just take this class this F2013)
I suppose that you didn't expect the result you've got.
Your program doesn't check the frequency of the first digit of the number but all the digits in the stream.
You have to split your data set into numbers first and then take only the first digit of that number.
Now there are several ways to split a number but the easiest is probably to use the getline function of a stream. The get line default uses the endline to seperate the lines but you can provide your own delimiter.
This reduces the complexity of your program, which is good in industrial code but isn't when someone still needs to learn coding algorithms.
I think your aim should be to write your own string split function/algorithm.
Learn from the mistakes of others, you may not live long enough to make them all yourself.
Create a "number box" that has 10 compartments, one for each digit 0-9.
For each number in your list
Check the first digit.
If it is a 0, increment the "0" compartment in the above-mentioned box.
If it is a 1, increment the "1" compartment in the above-mentioned box.
If it is a 2, increment the "2" compartment in the above-mentioned box.
// output statistics here
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
I'm using opensource library (exprtk http://partow.net/programming/exprtk/[^]) on qt 5.1.0 64 bit with visual studio 2012. But I'm taking c1128 error. Full output of error: C1128: number of sections exceeded object file format limit : compile with /bigobj
DeviceIoControl() is a Windows kernel function that passes the request to the device specific driver. So there should be no differences on one machine when calling this from a VS 2003 or VS 2008 generated application or even any other programming language.
Using VTable to get the address. And I can save backbuffer. But when change game's size, the game will crash. It seems change size wouldn't go to ResizeTarget(). So I want to ask:
1. When the game change size for d3d10_1.dll, what does he do, and what should I do?
2. There is other question, when the game exit, what should i do. i want to stop my project when the game is exit.
Thanks for any advices. I'm a newer in directx. There are so many publishs for directx, i.e d3d9, d3dx9_43, d3d10, d3d10_1, d3d11, d3d11_1 and so on.
I find when resize game's window it will call IDXGISwapChain()->ResizeBuffers(). I can hook ResizeBuffers(). And it also crash(the game is stablish, cant move any more.).I dont konw what should i do? please help!
I am wondering what might be the advantage of CStringArray over CArray<CString, LPCTSTR>. The background is that I am planning to implement a CStringArray-like template class which is either explicitly ANSI or explicitly Unicode, and would like to implement it as CArray<CStringA, LPCSTR> and CArray<CStringW, LPCWSTR>, respectively.
I have never mastered the usage of MFC container classes but I have an advice: support only unicode unless you are forced to support ansi. WinNT uses unicode/UTF16 inside, the codepaging/ansi api is just heritage from older windows versions. Supporting both is just a waste of time and unecessary complication if you don't have to support Win9x.
EDIT: Regarding the difference between CStringArray and CArray<CString...> I have a tip: The old versions of MFC didn't contain any templated containers, those mfc versions had only some non-template containers for a few types and CStringArray was one of them (among the others like CByteArray). I guess CStringArray exists just because of backward compatibility. CString didn't have reference counting in some older versions of MFC so in theory it is possible for a specialized CStringArray to reallocate the array memory without copying strings if CStringArray knows the internal implementation of CString, but a templated CArray has to work with copying/deleting. With reference counting a general CArray can do a relatively good job and with today's move ctors it can be even better if MFC supports it.
There are situations when I must support ANSI, for example when it comes to dealing with ANSI text files or serial protocols. I want to have the CStringArray functionality available for the must-be-ANSI situations while generally compiling for Unicode. Btw, I find MFC containers quite useful (unless, of course, you are using STL). The documentation is quite good, and you can debug-step through the source code.
Do you receive single bytes/ascii or really ansi on the serial port? Many people confuse ansi with ascii or latin1. Similarly, many windows coders confuse utf16 with unicode (they are two different things) and wchar_t with a unicode character. Can you clearly separate these concepts because if not I can write you a very little mini tutorial about these here. I want to convince you that compiling your program only for unicode is probably enough. Btw, what is on the other end of the serial port and what kind of codepage do you use in the "ansi" text for communication, is the text bare ascii (characters below chr(128))?
Containers: No matter what containers you use, its easy to debug either implementation. One of the project I'm currently working on contains own container implementations (array, hashmap, ...) and even these containers are debuggable if you can adjust the autoexp.dat file of your visual studio accordingly to teach the debugger how to get out items from the container. When I choose containers I consider 2 aspects: portability to different platforms and whether I need hardcore performance optimization later in the project or not. If we consider portability then stl is a much better choice than mfc containers, thats why I never really used mfc containers. Writing your own containers isn't practical in 99% of the projects.
Well in fact I should use proper terminology. When I said "ANSI" I meant 8-bit character stuff. When I said "Unicode" I meant 16-bit characters. Speaking of Unicode code points, mostly in the range 0000 through 007f. In other words, ASCII characters in different representations. But this discussion is getting beside the point. My question was, what is the advantage of CStringArray over CArray<CString, LPCTSTR>? Rephrase: Why is there a CStringArray class when CArray<CString, LPCTSTR> has the same functionality? Or does it not?
Last Visit: 31-Dec-99 18:00 Last Update: 17-Oct-17 2:27