CodeGuru Forums - Visual C++ Programming https://forums.codeguru.com/ Ask questions about Windows programming with Visual C++ and help others by answering their questions. en Wed, 21 Feb 2024 14:35:26 GMT vBulletin 60 https://forums.codeguru.com/images/misc/rss.png CodeGuru Forums - Visual C++ Programming https://forums.codeguru.com/ Is this valid for printf (in MSVC) https://forums.codeguru.com/showthread.php?566248-Is-this-valid-for-printf-(in-MSVC)&goto=newpost Sun, 18 Feb 2024 09:23:46 GMT I'm trying to run a program that runs fine when built with gcc - and it builds okay with MSVC but crashes at run time.

I've traced the crash to a call to vsnprintf() which is getting passed a string like this:- "(Value: %s%s %+05.1lf dB) "

I've never seen %+05.1lf in a string before - is it a valid argument for MSVC? ]]>
Visual C++ Programming John E https://forums.codeguru.com/showthread.php?566248-Is-this-valid-for-printf-(in-MSVC)
ShellExecute tries to launch .exe everytime even though it is already runniong. https://forums.codeguru.com/showthread.php?566235-ShellExecute-tries-to-launch-exe-everytime-even-though-it-is-already-runniong&goto=newpost Thu, 01 Feb 2024 06:47:23 GMT m_saveDCPProbePDF ) parameters = "savePDF"; else parameters = "dontSavePDF"; parameters += "*"; parameters += m_je->m_compilationPath; parameters += "*"; parameters += m_je->m_dcpName; ShellExecute( NULL, NULL, "DCPProbe.exe", parameters, progDir, SW_SHOWNORMAL ); --------- The problem I have is that even though program 2 is all ready running, ShellExecute tries to launch it again, which of course it can't because of the mutex. Is there a way to do this so that it uses the program already running rather than trying to launch a new one eveytime? Thanks so much, Steve Q. :-)]]> Hey All,

I have written two programs. Both of them have a mutex so that only one instance of each can ever be run at a time.

Program one uses ShellExecute to send information to program two. Here's a code snippet:

Code:

if ( m_je->m_saveDCPProbePDF ) parameters = "savePDF";
else parameters = "dontSavePDF";

parameters += "*";

parameters += m_je->m_compilationPath;

parameters += "*";

parameters += m_je->m_dcpName;

ShellExecute( NULL, NULL, "DCPProbe.exe", parameters, progDir, SW_SHOWNORMAL );

The problem I have is that even though program 2 is all ready running, ShellExecute tries to launch it again, which of course it can't because of the mutex.

Is there a way to do this so that it uses the program already running rather than trying to launch a new one eveytime?

Thanks so much,

Steve Q. :-) ]]>
Visual C++ Programming steveq https://forums.codeguru.com/showthread.php?566235-ShellExecute-tries-to-launch-exe-everytime-even-though-it-is-already-runniong
Help with RichEdit control https://forums.codeguru.com/showthread.php?566234-Help-with-RichEdit-control&goto=newpost Thu, 01 Feb 2024 03:22:27 GMT I want to clear RichEdit control. But, I set the attribute of RichEdit control CFE_PROTECTED. So I couldn't clear RichEdit control. I think that I should set the attribute of RichEdit control again( release PROTECTED attribute).

How can I release PROTECTED attribute? ]]>
Visual C++ Programming FijianBauble https://forums.codeguru.com/showthread.php?566234-Help-with-RichEdit-control
::cryptDecrypt Fails with Unicode https://forums.codeguru.com/showthread.php?566232-cryptDecrypt-Fails-with-Unicode&goto=newpost Sat, 27 Jan 2024 13:53:42 GMT (arSource.GetCount())); m_file.Flush(); // Acquire direct access to the memory file buffer. BYTE* pData = m_file.Detach(); // We need a DWORD to tell decrpyt how much data we're encrypting. DWORD dwDataLength = static_cast(arSource.GetCount()); DWORD dwOldDataLength = dwDataLength; // Now decrypt the data. if(!::CryptDecrypt(m_hKey, NULL, TRUE, 0, pData, &dwDataLength)) { // Free the memory we release from the memory file. delete [] pData; return false; } --------- ::CryptDecrypt(m_hKey, NULL, TRUE, 0, pData, &dwDataLength) fails with Bad Data on a unicode build, but not on a non unicode build. Could someone please give me some direction as to how to fix this? Many thanks, Steve Q.]]> Hey Gurus,
I'm frustrated by an issue I have when trying to decrypt some data.
I have two projects, both decrypting the exactly the same data. One project uses unicode and the other doesn't. The project not using unicode, decrypts the data without a problem. With the project that does use unicode ::cryptDecrypt fails with "bad data". I understand the difference between unicode and non unicode builds. When I look at the data being sent to ::cryptDecrypt it is identical on both builds! This really has me stumped. Here is some of my code from the unicode version. I'm using the class CCryptography in my software.

Code:

int result = true;

        CByteArray arData;

        int count;

        BYTE *data;

        CString passwordDecoded;

        // This is for the T2A macro.
        USES_CONVERSION;

        // Decode the Base64 encoding of the password.
        count = Base64DecodeGetRequiredLength( password.GetLength() );

        data = ( BYTE * ) malloc( count );

        Base64Decode( T2A(password), password.GetLength(), data, &count );

        for ( int i = 0; i < count; i++ ) arData.Add( data[ i ] );

        arData.Add( 0 );

        passwordDecoded = arData.GetData();

        free( data );

        arData.RemoveAll();

        if ( m_crypto.DeriveKey( passwordDecoded ) )
        {
                // Decode the Base64 encoding of the registration key.
                count = Base64DecodeGetRequiredLength( registrationKey.GetLength() );

                data = ( BYTE * ) malloc( count );

                Base64Decode( T2A( registrationKey), registrationKey.GetLength(), data, &count );

                int i;

                for ( i = 0; i < count; i++ )
                {
                        arData.Add( data[ i ] );
                }

                free( data );

                //        Try and deserialize the data.
                if ( m_crypto.Decrypt( arData, m_arStrings ) == true ) // This returns false!!

m_crypto.Decrypt function:
Code:

bool CCrypto::Decrypt(const CByteArray& arData, CObject& serializable)
{
        //        Return failure if we don't have a context or key.
        if(m_hCryptProv == NULL || m_hKey == NULL)
                return false;

        //        Return failure if the object is not serializable.
        if(serializable.IsSerializable() == FALSE)
                return false;

        //        Decrypt the contents of the array to the memory file.
        if(InternalDecrypt(arData) == false)
                return false;

        //        Create a reading archive from the memory file.
        CArchive ar(&m_file, CArchive::load);

        //        Read the data from the memory file.
        serializable.Serialize(ar);
       
        //        Close the archive.
        ar.Close();

        //        And we're done.
        return true;
}

The InternalDecrypt function:
Code:

bool CCrypto::InternalDecrypt(const CByteArray& arSource)
{
        //        Trash the file.
        m_file.SetLength(0);

        //        Write the contents of the byte array to the memory file.
        m_file.Write(arSource.GetData(), static_cast<UINT>(arSource.GetCount()));
        m_file.Flush();

        //        Acquire direct access to the memory file buffer.
        BYTE* pData = m_file.Detach();

        //        We need a DWORD to tell decrpyt how much data we're encrypting.
        DWORD dwDataLength = static_cast<DWORD>(arSource.GetCount());
        DWORD dwOldDataLength = dwDataLength;

        //        Now decrypt the data.
        if(!::CryptDecrypt(m_hKey, NULL, TRUE, 0, pData, &dwDataLength))
        {
                //        Free the memory we release from the memory file.
                delete [] pData;

                return false;
        }

::CryptDecrypt(m_hKey, NULL, TRUE, 0, pData, &dwDataLength) fails with Bad Data on a unicode build, but not on a non unicode build.

Could someone please give me some direction as to how to fix this?

Many thanks,

Steve Q. ]]>
Visual C++ Programming steveq https://forums.codeguru.com/showthread.php?566232-cryptDecrypt-Fails-with-Unicode
const expr debug in visual studio https://forums.codeguru.com/showthread.php?566229-const-expr-debug-in-visual-studio&goto=newpost Wed, 24 Jan 2024 18:55:42 GMT Hello experts I found the workaround for this. VS still doesnot show the const expr local variables via debugger. Thanks pdk Hello experts

I found the workaround for this.

VS still doesnot show the const expr local variables via debugger.

Thanks
pdk ]]>
Visual C++ Programming pdk5 https://forums.codeguru.com/showthread.php?566229-const-expr-debug-in-visual-studio