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
  • Need help with cryptography

    cryptography question visual-studio com docker
    2
    0 Votes
    2 Posts
    0 Views
    L
    Hi, SMD111 wrote: Q: What is the effect of repetitive calls to this function? For example, I decide to change the key length, and generate a call with a different dwFlags value. What happens to the old key pair? Does it get overwritten? Or does each new call generate a new key pair? Each call generates a new key pair. Each key remains valid until you call the CryptDestroyKey function or until you reboot. If you wanted to save the key... you could export it or save it into the certificate store. SMD111 wrote: MSDN: “The CryptGetUserKey function retrieves a handle of one of a user's two public/private key pairs.” Q: which one? There is no default for zero-value. You would probably get a ERROR_INVALID_PARAMETER error if you pass zero. You would need to specify either AT_KEYEXCHANGE or AT_SIGNATURE. Currently defined as integers 1 and 2. SMD111 wrote: Q: So how does one retrieve the public key, and how does one get the private key? See the previous response. You would need to pass AT_KEYEXCHANGE or AT_SIGNATURE. Note that AT_SIGNATURE keys can be used to sign and AT_KEYEXCHANGE keys can be use both to sign and decrypt. SMD111 wrote: Q: How can the public/private key pair be destroyed? The question is either unclear or nonsensical. When you call CryptDestroyKey the handle to an internal object is securely deleted. It is up to you to securely delete your own application memory and destroy any exported keys and/or remove keys from the certificate store or on disk. One last thing... while working internally on an operating system service I discovered multiple failures... including a race condition within the old Crypt32 Cryptography Functions. Our team moved to the 'Cryptography Next Generation' and all issues were resolved. Best Wishes, -David Delaune
  • [C]Problem in creating a random string

    help data-structures lounge
    12
    0 Votes
    12 Posts
    0 Views
    D
    Krishnakumartg wrote: MyArray[i + 1] = '\0'; Why add 1? When the loop ends, i is already 1 past the desired length. "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
  • Most efficient way to create a string range in C?

    question tutorial
    4
    0 Votes
    4 Posts
    0 Views
    J
    Efficient in terms of speed or lines of code? If the latter, create a string buffer and then manipulate it until it is greater than the end.
  • how to create thread on windows?

    c++ visual-studio question csharp com
    15
    0 Votes
    15 Posts
    16 Views
    J
    Note: prefer _beginthreadex over _beginthread. If using C++11, you could use the std::thread class.
  • _tcscpy_s and unused buffer part

    debugging
    14
    0 Votes
    14 Posts
    1 Views
    J
    _tcscpy_s and it's variants only guarantee that the string will be copied IF it fits. I suspect that the compiler "figured out" that it could safely optimize the copy using 32 or 64 bit chunks. This would result in satisfying the condition that the string be null terminated, but would also end up copying random data stored after the original string.
  • WaitForSingleObject best practices

    12
    0 Votes
    12 Posts
    2 Views
    J
    Be aware that the change folder notification occurs at any change, which means the full write may not have happened. One solution is to write the file to another location and then atomically move it to the monitored directory.
  • Error in returning array of int as reference

    data-structures help question
    10
    0 Votes
    10 Posts
    0 Views
    J
    Some issues: static int Einschlagsnummer; Is never default initialized. Some code paths return nothing so whatever is in [e]ax gets returned, which may be 1. If Trefferchance is <= 80 and m_Schutzwall > 5, it will return 1 for each iteration up to five. However, you stated that m_Schutzwall is 1 which means it's never decremented to zero since the test is for m_Schutzwall > 1, not m_Schutzwall >= 1. This suggests that the return value is likely what happens to be in [e]ax. now nitpicking: int Zufallstreffer; Zufallstreffer=rand()%99+1; int Trefferchance; Trefferchance=rand()%99+1; Why not initialize the variables in the declaration of them? Why m_Schutzwall=m_Schutzwall-1; instead of --m_Schutzwall;
  • Assigning pointers from one class to another and

    question hardware help tutorial
    8
    0 Votes
    8 Posts
    2 Views
    L
    Yes but that is easy to deal with fire the interrupt to a static function then kick it to the object. That solution is trivial. PSOMECLASS* TheClassObject = NULL; static void InterruptComesInHere (void){ if (TheClassObject) { // Make sure class/object has been set otherwise interrupt just returns TheClassObject->CallSomeMethod(); // Send interrupt into class/object if set } } All you have to do once you have your object initialized ready to receive is set the pointer to the created object using the & symbol. I would disable interrupts while you do the pointer set :-) All it really does is makes the interrupt a couple of cycles slower. The harder part by far is dealing with the interupts in windows which is nowhere near as easy as DOS. I assume this is a windows app and I wonder have you got the interrupt working because that isn't easy on windows 7,8 & 10 Windows uses hardware interrupts internally and does not let applications mess with them. You need to create a write a kernel-mode driver for that which is not trivial. To be honest in Windows at your level it would be easier to simply create a thread and poll the hardware for data and get rid of the interrupt all together. If you are trying to do this sort of thing commercially you are better off porting the IO onto a USB because they have raw block transfer mechanisms and the USB interface can be bought off the shelf. If you look up EasyCap for example which sells for about $10-$15 will drag normal S video into windows via the USB using exactly that trick. In vino veritas
  • 0 Votes
    4 Posts
    0 Views
    L
    See the code ...
  • 0 Votes
    2 Posts
    0 Views
    L
    I think you need to talk to the manufacturer, we have no idea what a V4 printer is.
  • Toolbar Resizing

    question help
    10
    0 Votes
    10 Posts
    3 Views
    T
    The link is out of date. I found the page with Google by enter "TN031 Control Bars".
  • 0 Votes
    3 Posts
    0 Views
    L
    You first need to be absolutely sure the thing is worth the effort to protect because any protection scheme software or hardware has a cost and it isn't cheap. Even just putting a software decrypt key that gets stored in the registry or a hidden file means you have a way to produce the keys in some sort of program. That means time and effort to develop the key release program and then physically handle requests by people for a key. It's all cost. The physical hardware key solution suggested is not cheap either and not much more difficult to break than a software key. I can de-hasp a program in about 30min because it's dead easy to intercept the communication with the hasp plug with a special driver. Many of the pirates you refer too will be able to do the same. Often you are better off just leaving a nag screen in for products that are low dollar and try and guilt the users into purchase. There are two alternative marketing tricks 1.) Make the thing so big with graphics and the like that you need multiple DVD roms to distribute and makes torrenting the thing awkward. It becomes such a pain people just go and buy the disk it isn't worth the effort to pirate. 2.) Keep putting out frequent updates even if small, it keeps the pirates disinterested in it. So are you sure the product is worth the effort? In vino veritas
  • class is missing "type" - why ?

    help hardware visual-studio question
    3
    0 Votes
    3 Posts
    0 Views
    G
    The reason for the different error messages when you have parentheses or not are down to what you are declaring (I've removed the "class" from in front of hcd and usbd to leave the relevant parts): class IDE_USBD; class IDE_HCD; class IDE_ILI9341 { public: IDE_HCD hcd; IDE_USBD usbd(); ... Here hcd doesn't have parentheses, so it is a member variable. The compiler needs to know the size of the IDE_HDC class to store the variable in the IDE_ILI9341 class, which is why you get the "incomplete type" error. The usbd declaration does have parentheses, so it is a member function returning an instance of the IDE_USBD class. The compiler doesn't need to know the size of the IDE_USBD class in this case because it doesn't affect the amount of space taken up in the class by usbd. You will run into problems later when you try to use usbd as a variable though (because it isn't one).
  • 0 Votes
    16 Posts
    0 Views
    L
    Yes we are putting composition over inheritance, so our classes are trying to achieve multiple and flexible behaviour (reusing as much code as possible) rather than inheritance from a base or parent class. I would also add there is one final thing you will be able to do if you go that path which you can't possibly do with your current scheme, which is to thread the classes or at least the one that had the old ISR code to help its response and speed. In vino veritas
  • 0 Votes
    5 Posts
    3 Views
    V
    Member 9411471 wrote: It will not compile using msvc++ 2015 And what compiler error does it produce?
  • Object Creation of an class?

    c++ question
    7
    0 Votes
    7 Posts
    0 Views
    M
    Thanks In vino veritas.
  • More basic C++ questions - may I ask?

    c++ com graphics help question
    9
    0 Votes
    9 Posts
    0 Views
    D
    Ratul Thakur wrote: i'm not able to figure out where are X and Y defined They aren't. The OP's code is incomplete and thus will not compile. "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++ syntax

    c++ json tutorial question
    4
    0 Votes
    4 Posts
    0 Views
    D
    Ratul Thakur wrote: ...what does FGAPIENTRY stand for... Look in your project's header files. It resolves to this. "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
  • 0 Votes
    5 Posts
    0 Views
    CPalliniC
    Yes. You may find (on the web) folks arguing that warning is not legitimate. In a clean implementation you don't qualify with extern the variable in the source file wherein you define it.
  • 0 Votes
    13 Posts
    0 Views
    L
    Correct The problem as you will find is hierarchy order as you will find. Sometimes the order will not be the way you want in different functions and you will need to control it and that gets down to some very nitty details. The question we will still always pose back to you is do you really need the hierarchy at all. I can't stress enough to read one article from wikipedia it can save you alot of heartache https://en.wikipedia.org/wiki/Composition_over_inheritance[^] In vino veritas