Menu

help concerning edit conrol

2002-08-31
2012-09-26
  • Nobody/Anonymous

    Hi! I am working on an installation program and I am having a problem.  I want to have to registation codes for the installer so that you can't spread the software illegally.  I am having trouble because the program always registers the input as false.  Here's the source code:
    #include <windows.h>
    #include <stdlib.h>

    #include "resource.h"
    BOOL CALLBACK StepThreeProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        static BITMAPFILEHEADER *pbmfh;
        static BITMAPINFO *pbmi;
        static BYTE *pBits;
        static int cxDib, cyDib;
        static HDC hdcmem;

        switch(Message)
        {
            case WM_INITDIALOG:
            break;
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                     case ID_CANCEL:
                     if(IDYES==MessageBox(NULL, "Are you sure you want to cancel the installation?" , "RapidApps Installer", 0 + MB_YESNO + MB_ICONQUESTION))
                     {
                         EndDialog(hwnd, 0);
                     }
                     else
                     {
                     }
                     break;
                     case ID_NEXT:

                     char* bufOne;
                     bufOne = (char*)GlobalAlloc(GPTR,25);
                     GetDlgItemText(hwnd, IDC_REGONE, bufOne, 25);

                     char* bufTwo;
                     bufTwo = (char*)GlobalAlloc(GPTR, 25);
                     GetDlgItemText(hwnd, IDC_REGTWO, bufTwo, 25);

                     if (bufOne == "SD654DF5SD4F6SD545F4G8S4H" && bufTwo  == "G54F684G24F6S4G5F4G68S45F")
                     {
                         MessageBox (NULL, "You registration keys appear to be valid." , "RapidApps Installer", 0 + MB_ICONASTERISK);
                     }
                     if (bufOne != "SD654DF5SD4F6SD545F4G8S4H" || bufTwo  != "G54F684G24F6S4G5F4G68S45F")
                     {
                        MessageBox (NULL, "You registration numbers are not valid.  If you legally purchased this software, please contact RapidApps Inc." , "RapidApps Installer", 0 + MB_ICONEXCLAMATION);
                     }
                     break;
                     case ID_BACK:
                     EndDialog(hwnd, 0);
                     break;
                }
            break;
            case WM_PAINT:
            DWORD dwFileSize, dwHighSize, dwBytesRead;
            HANDLE hFile;
            hFile = CreateFile ("C:\\bitmap.bmp", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);

            dwFileSize = GetFileSize (hFile, &dwHighSize);
            pbmfh = (BITMAPFILEHEADER *)malloc(dwFileSize);
            ReadFile (hFile, pbmfh, dwFileSize, &dwBytesRead, NULL);

            pbmi = (BITMAPINFO *) (pbmfh + 1);
            pBits = (BYTE *) pbmfh + pbmfh->bfOffBits;
            cxDib = pbmi->bmiHeader.biWidth;
            cyDib = abs(pbmi->bmiHeader.biHeight);
            HDC hdc;
            hdc = GetDC (hwnd);
            hdcmem = CreateCompatibleDC (hdc);

            SetDIBitsToDevice (hdc, 0, 0, cxDib, cyDib, 0, 0, 0, cyDib, pBits, pbmi, DIB_RGB_COLORS);

            ReleaseDC (hwnd, hdc);
            free (pbmfh);
            return 0;
            case WM_CLOSE:
                     if(IDYES==MessageBox(NULL, "Are you sure you want to cancel the installation?" , "RapidApps Installer", 0 + MB_YESNO + MB_ICONQUESTION))
                     {
                         EndDialog(hwnd, 0);
                     }
                     else
                     {
                     }
            break;
            default:
                return FALSE;
        }
        return TRUE;
    }

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        return DialogBox(hInstance, MAKEINTRESOURCE(IDD_STEPTHREE), NULL, StepThreeProc);
    }

    This program is a dialog box with controls defined by a .rc file.  If there is anything you can see wrong with this code, please help.

     
    • Nobody/Anonymous

      Try this:

      char* bufOne;
      bufOne = (char*)GlobalAlloc(GPTR,26);
      /* Your 25 characters, plus string terminator (which is '\0' ) */
      GetDlgItemText(hwnd, IDC_REGONE, bufOne, 26);
      /* Read the documentation for GetDlgItemText. Last parameter is the maximal number of character INCLUDING the string terminator, which is put automatically.  */

      The same for bufTwo

      Dan

       
    • Nobody/Anonymous

      Don't forget to ZeroMemory (or memset) any buffer or struct before using it. Strange things can happen failing to do so...

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.