Skip to content

C / C++ / MFC

C, Visual C++ and MFC discussions

This category can be followed from the open social web via the handle c-c-mfc@forum.codeproject.com

111.5k Topics 465.7k Posts
  • how to correct an segmentation fault ?

    question com graphics data-structures json
    4
    0 Votes
    4 Posts
    0 Views
    T
    thank you !
  • Tiniest portable executable

    game-dev algorithms tutorial announcement
    2
    0 Votes
    2 Posts
    0 Views
    L
    There was a competition some time back to make the smallest PE header for windows. If you ran across golden I was surprised you didn't find the link Tiny PE[^] The answer was 97 bytes but it won't work on Windows 2000, 133 bytes to get it to work on Windows 2000. I don't believe any of those work on Windows 7,8 or 10. This one works on windows 10 x64bit I tried it ... that is 268 bytes DPE64small/DPE64small.asm at master · DrakoPensulo/DPE64small · GitHub[^] Having looked at it I think the statement the smallest PE is 252 bytes on Win32, or 268 bytes on Win64 is correct. Personally I would go with the 268 bytes because it works on every windows version that exists currently. Here is the layout of the created 268 byte executable https://github.com/LdB-ECM/Docs_and_Images/blob/master/Images/Small_PE.jpg?raw=true This is how windows sees the details on the file https://github.com/LdB-ECM/Docs_and_Images/blob/master/Images/SmallPE_report.jpg?raw=true I did have fun messing around with it thanks to your question. For reference a linux executable PE you can squeeze to 45 bytes. In vino veritas
  • Device manager in windows.

    question c++ json
    2
    0 Votes
    2 Posts
    0 Views
    D
    This may be a good starting point. "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
  • C++ ofstream System.AccessViolation

    help csharp c++ ios dotnet
    6
    0 Votes
    6 Posts
    1 Views
    U
    Hello, How you fixed the access violation error on Visual Studio 2010. I am trying to write data to csv file but it is giving me access violation error. As you mentioned, the debugger points to : virtual void __CLR_OR_THIS_CALL _Lock() { // lock file instead of stream buffer if (_Myfile) _CSTD _lock_file(_Myfile); }
  • How cin.get() works in loop ?

    question
    5
    0 Votes
    5 Posts
    1 Views
    J
    cin.get() does not read individual keystrokes -- the input is buffered by the terminal until you hit Enter, then all of the input is sent to the program at once. To read individual keystrokes, you'll have to rely on a third-party tool like GNU's ncurses library.
  • try /catch Exception missing type

    help question visual-studio code-review learning
    5
    0 Votes
    5 Posts
    0 Views
    L
    This is a complex thing so lets go thru it. On a Normal O/S, RTOS very few low level functions ever have exception catches they usually simply report it back. The why is simple, the problem it faces is how the exception should report the error, it isn't clear who it should be reported to the APP or the O/S. As an example, early versions of Windows when low level functions raised an exception put up the blue screen of death and silly things on the API could create it. Blue Screen of Death - Wikipedia[^] It actually became a problem because people got sick of rebooting there computer and on the modern versions of windows it is reserved for unrecoverable errors. Almost all the core windows API almost never raises an exception it simply passes the error back to be handled by the caller because part of being able to handle the error is to know what the caller program is which only the caller knows. So basically there is no problem something like an APP raising exception it can rely on the O/S being able to do something sensible with the exception. However if the caller is something like a driver or the O/S itself there is always the problem the thing you are reporting to has already crashed. So in your case file I/O may well be used by a driver so no-one would set it up to raise an exception. Now there are even newer changes in programming to Virtual O/S which started with VMware. There you have a hypervisor program and the O/S or OS's run above the hypervisor Hypervisor - Wikipedia[^] In that enviroment many low level functsions will raise an exception and the Hypervisor will catch them because it is immune to errors in the VM. So in that situation a file IO may well be setup to raise an exception. See the common theme if you are going to raise an exception the thing that catches the exception must be able to continue running despite the error. So the question of if a low level function should raise an exception depends on there being a stable level below it to catch the raised error. What this answer brings in is the concept of protection rings the wiki entry is very Intel centric Protection ring - Wikipedia[
  • volatile misbehaves

    hardware question code-review
    17
    0 Votes
    17 Posts
    4 Views
    S
    Vaclav_ wrote: Here is something which MAY explain the issue. https://gcc.gnu.org/onlinedocs/gcc/Volatiles.html I don't think that's the issue here, but it does represent something I wish the Standard would address. Although there may be some platforms and application fields for which gcc's behavior would be reasonable in a quality compiler, there are many purposes for which it is not. On many platforms, it is possible for an access to a volatile location to trigger operations that usefully affect other storage (e.g. starting an "in-place" background I/O operation). For an implementation to be suitable for systems-programming on such a platform, it must provide a way of ensuring that such operations are sequenced relative to other operations on non-qualified storage. An implementation can support systems programmings on such platforms without requiring the use of special directives by treating volatile accesses as triggering a call to an unknown function, and I would suggest that quality implementations for such platforms should provide an option to treat them in such fashion. Unfortunately, even though the Standard has to date expressly avoided quality-of-implementation issues, the authors of gcc seem to think either that the Standard fully describes everything necessary to make something a quality implementation, or that users should not expect gcc to behave like a quality implementation when any of its optimizations are enabled. While there might some cases where it might be unnecessarily expensive to treat volatile accesses as sequenced relative to non-qualified accesses to objects that would be accessible by outside code, in most cases the cost would be negligible, and would be less than the cost of adding "volatile" qualifiers and accesses everywhere else that would otherwise be necessary to ensure correct semantics. When the Standard was written, it may have been reasonable to expect compiler writers to exercise good judgment about how quality compilers intended for various purposes should be expected to behave in circumstances beyond those mandated by the Standard, and for programmers to be reliant upon compiler writers' sound judgment. Such expectation and reliance are no longer tenable. If the authors of the Standard don't want to mandate that all compilers treat "volatile" more strongly, they should at minimum specify a predefined macro to allow programmers to say something like: #if !(\_\_STDC\_VOLATILE\_SEMANTIC
  • Return a local 2d Array

    data-structures tutorial question
    6
    0 Votes
    6 Posts
    0 Views
    J
    The return type for getArray needs to be int (*getArray())[COL];. An expression of type T [M][N] decays to type T (*)[N], not T **. So your code needs to be int main() { int (*ptr)[N]; int (*getArray())[N]; ... } int (*getArray())[N] { ... return tab; }
  • Graphical representation of Data

    performance
    6
    0 Votes
    6 Posts
    0 Views
    S
    yes.I need to program.
  • 0 Votes
    4 Posts
    0 Views
    CPalliniC
    You are welcome.
  • best programing language for linux

    csharp linux
    1
    0 Votes
    1 Posts
    0 Views
    No one has replied
  • 0 Votes
    4 Posts
    0 Views
    L
    Microsoft has an tutorial on both making the DLL and Including it another C++ program. It's no different for C just make the extensions .C instead of .CPP Walkthrough: Creating and Using a Dynamic Link Library (C++)[^] The only difference between a C and C++ DLL is C++ does name mangling Name mangling - Wikipedia[^] In vino veritas
  • 0 Votes
    10 Posts
    0 Views
    J
    Yes, but; 1) I highly suggest you install them from oldest to newest. 2) Do NOT open a solution by double-clicking in explorer. Rather, open the visual studio you want to use and then open the solution from there. Also be aware that once you move a solution to a newer version, you typically cannot move back. Also note that starting with either 2013 or 2015, you can use an earlier toolset.
  • __sync_synchronize stops processor ?

    question c++ performance
    5
    0 Votes
    5 Posts
    0 Views
    V
    David, I have "discovered" the real problem - nothing to do with synchronization. ( see my recent "volatile misbehaves " post. ) I am sorry for wasting your time on this, my apology.
  • CInternetSession OpenURL

    html help tutorial
    13
    0 Votes
    13 Posts
    0 Views
    L
    _Flaviu wrote: I really don't know hot to overcome this The javascript and/or webassembly needs to execute. Websites are not flat files anymore. You will need to use a complete browser engine to parse the DOM. In other words most websites today are generating dynamic content via javascript. You need to think outside the box here... that javascript you see needs to execute in order to generate the page. One quick way to do this would be using a hidden Internet Explorer window as the backend. Creating a Web Browser-Style MFC Application[^]. You could set the CHtmlView to load the site and dump the top document after javascript has modified the DOM. Some of my tools are using a custom webkit[^] as the backend to do this. You can also use Chromium Embedded[^]. You could probably spend less than a day modifying cefsimple[^] to load the website and dump the top document to file after javascript has executed. Good Luck. Best Wishes, -David Delaune
  • 0 Votes
    7 Posts
    0 Views
    H
    Sounds great, thanks!
  • Why can't variables be declared in a switch statement

    c++ question
    2
    0 Votes
    2 Posts
    0 Views
    L
    You can, you just need to put them, and the code that uses them inside curly braces, thus: switch (number) { case 1: { int i; // local to only this case statement } } Variables not inside such a block are considered to have the scope of the entire switch block. But if they are declared in a single case statement there is a possibility that they would not get initialised safely. To make a variable available to multiple case statements it must be declared before the switch.
  • problem encountered by calling constructors explicitly.

    graphics help
    4
    0 Votes
    4 Posts
    0 Views
    CPalliniC
    Since you know at compile time the array size, why don't you allocate it on the stack? #include #include using namespace std; constexpr size_t SIZE = 3; class Vector { array x{}; public: Vector (const array & a) { for (size_t n=0; n x{1,2,3}; array y{6,3,9}; Vector v1{x}; Vector v2{y}; cout << "v1 " << v1 << endl; cout << "v2 " << v2 << endl; cout << "v1*v2 = " << (v1*v2) << endl; }
  • vs2005 Form window Error C2039

    help winforms graphics debugging question
    4
    0 Votes
    4 Posts
    0 Views
    V
    Then it would be better to post in the Managed C++/CLI Forum.
  • Why do I need typecast hex?

    question
    3
    0 Votes
    3 Posts
    0 Views
    V
    Thanks Richard, you are a pal. Appreciate your comments.