Click here to Skip to main content
15,936,975 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: GetClipBoardOwner with acrobat reader Pin
David Crow1-May-12 3:49
David Crow1-May-12 3:49 
QuestionMeauring CPU time of C code in milliseconds Pin
Ron120230-Apr-12 18:18
Ron120230-Apr-12 18:18 
AnswerRe: Meauring CPU time of C code in milliseconds Pin
Peter_in_278030-Apr-12 18:32
professionalPeter_in_278030-Apr-12 18:32 
GeneralRe: Meauring CPU time of C code in milliseconds Pin
Ron120230-Apr-12 18:42
Ron120230-Apr-12 18:42 
AnswerRe: Meauring CPU time of C code in milliseconds Pin
Peter_in_278030-Apr-12 18:51
professionalPeter_in_278030-Apr-12 18:51 
Questionc++ win32 CreateThread, Wait, final testing Pin
jkirkerx30-Apr-12 16:54
professionaljkirkerx30-Apr-12 16:54 
QuestionRe: c++ win32 CreateThread, Wait, final testing Pin
Code-o-mat1-May-12 0:29
Code-o-mat1-May-12 0:29 
AnswerRe: c++ win32 CreateThread, Wait, final testing Pin
jkirkerx1-May-12 6:57
professionaljkirkerx1-May-12 6:57 
I wrote a post last week about my program working fine when running in debug F5, but the compiled version has many errors. So I've been running the compiled debug version, and using the just in time feature to locate errors. I fixed most of the errors, but the thread eludes me.

I'm using ODBC to connect to the sql server.

The dialog box runs 1 thread to validate when you press OK, and then the next thread to create the project, in which it copies files to the folder, sets permissions, creates a database and tables, users, permissions, write to the registry, and then opens the project.

The strange behavior on the SQL, is that the first sql function runs correctly, and then the 2nd one won't connect.

This is the sql function

BOOL bResult = FALSE;
	
SQLHENV henv;
SQLHDBC hdbc;
SQLHSTMT hstmt;
SQLRETURN retcode;

SQLWCHAR OutConnStr[1024];
SQLSMALLINT OutConnStrLen;

HWND desktopHandle = GetDesktopWindow();   // desktop's window handle

SQLWCHAR	szDatabaseExist[80];
SQLLEN		cbDatabaseExist = 0;
	
// Allocate environment handle
retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);

// Set the ODBC version environment attribute
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
	retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER*)SQL_OV_ODBC3, 0); 

	// Allocate connection handle
	if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
		retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); 

		// Set login timeout to 5 seconds
		if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
				SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER)5, 0);

			// Process data
			WCHAR pzSQLDriver[128];
			swprintf_s(pzSQLDriver, 128,
				L"Driver={SQL Server Native Client 10.0}; Server=%s; Database=master; Trusted_Connection=Yes;",
				pzServerName
			);				

			// Intialize Connection
			retcode = SQLDriverConnect( hdbc, desktopHandle, (SQLWCHAR*)pzSQLDriver,
				wcslen(pzSQLDriver), OutConnStr, 1024, &OutConnStrLen, SQL_DRIVER_NOPROMPT );

			// Allocate statement handle
			if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {               
				retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); 

				// Process data
				WCHAR pzSQLCommand[512];
				swprintf_s(pzSQLCommand, 512,
					L"SELECT CASE WHEN db_id('%s') IS NOT NULL THEN 'TRUE' ELSE 'FALSE' END",
						pzDatabaseName
				);
				pzSQLCommand[wcslen(pzSQLCommand) + 1] = L'\0';
		
				retcode = SQLExecDirect( hstmt, (SQLWCHAR*)pzSQLCommand, SQL_NTS );				
					
				if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {						
						
					SQLBindCol( hstmt, 1, SQL_C_WCHAR, szDatabaseExist, sizeof(szDatabaseExist), &cbDatabaseExist );

					WCHAR *szResult = new WCHAR[cbDatabaseExist];

					while ((retcode = SQLFetch( hstmt )) != SQL_NO_DATA) {
						 swprintf_s(szResult, cbDatabaseExist, L"%s\n", szDatabaseExist );
						 szResult[wcslen(szResult)+1] = L'\0';
						}

					SQLFreeHandle(SQL_HANDLE_STMT, hstmt);						

					if( wcsncmp( szResult, L"TRUE", wcslen(szResult) ) > 0) {
						bResult = TRUE;
					}
					else {
						bResult = FALSE;
					}
						
				}
				SQLDisconnect(hdbc);
			}
                        SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
         }
    }
	
    SQLFreeHandle(SQL_HANDLE_ENV, henv);
}
   	
return bResult;


And then this a a preview of the contents that the thread runs for validation. If something doesn't jive, then the exitcode is generated, and returned to the thread creator, in which the thread creator generates a messagebox, and alters the dialog box.

    BOOL    bValidate = TRUE;
    BOOL    bResult = FALSE;
    DWORD   dwExitCode  = 0;
    DWORD   dwWebsitePath_Check = 0;
    DWORD   dwProjectName = 0;
    DWORD   dwFolderPath = 0;
    DWORD   dwDomainName = 0;
    DWORD   dwLicenseKey = 0;

    DWORD   dwServerName = 0;
    DWORD   dwDatabaseName = 0;
    DWORD   dwAuthMethod = 0;
    DWORD   dwAccountName = 0;
    DWORD   dwPassword = 0;

    WCHAR   *szValidKey = NULL;
    WCHAR   *szWebsitePath_Check = NULL;

    WCHAR   pzProjectType[ 64 ];
    WCHAR   pzProjectName[ MAX_PATH ];
    WCHAR   pzProjectPath[ MAX_PATH ];
    WCHAR   pzFolderPath[ MAX_PATH ];
    WCHAR   pzDomainName[ 255 ];
    WCHAR   pzLicenseKey[ 255 ];

    WCHAR   pzServerName[80];
    WCHAR   pzDatabaseName[80];
    WCHAR   pzAuthMethod[80];
    WCHAR   pzAccountName[80];
    WCHAR   pzPassword[80];

    PMAIN_RUNPROCESS pzValidate;
    pzValidate = (PMAIN_RUNPROCESS)lpParam;
    HWND cWnd               = pzValidate->m_cWnd;
    HWND hWndDlg            = pzValidate->m_hWndDlg;
    HWND lblStatusMessage   = pzValidate->m_StatusMessage;
    HWND pbProgressBar      = pzValidate->m_ProgressBar;

    PROJECT_TYPE projectType;

    // Load the Registry Class
    CA_Registry caReg;

    /////////////////////////////////////////////////////////////////////////////////////////////
// Project Type Validation

    DWORD   dwProjectType = 0;
    dwProjectType = ListView_GetNextItem( lv_ProjectCreate_ProjectType, -1, LVNI_FOCUSED );
    if ( dwProjectType == -1 ) {
        // No Selection has been made - Handle the Error in the Thread Creator
        return 1;
    }
    else {
        // A Selection has been made
        ListView_GetItemText( lv_ProjectCreate_ProjectType, dwProjectType, 0, pzProjectType, 60 );
        if ( wcsncmp( pzProjectType, L"North American Standard Edition 2012", wcslen( L"North American Standard Edition 2012" ) ) == 0 ) {
            projectType = NASE2012_STANDARD;
        }
    }

// End of Project Type Validation    /////////////////////////////////////////////////////////////////////////////////////////////
// Does the Database Exist
	BOOL bDatabaseExist = FALSE;

	CA_SQLServer_ODBC caODBC;
	bDatabaseExist = caODBC._does_SQLServer_Database_Exist_hWnd( pzServerName, pzDatabaseName );

	if ( bDatabaseExist ) {
		return 13;	
	}

	// End of Database Exist	
	/////////////////////////////////////////////////////////////////////////////////////////////
	// if SQL Authentication, validate the credentials
	BOOL bSQLValidate = FALSE;
		
	if ( !bSQL ) {
		// Validate using Windows Authentication
		bSQLValidate = caODBC._validate_SQLServer_Credentials_WinAuth( pzServerName );
		
		if ( !bSQLValidate ) {
			bValidate = FALSE;
			return 11;
		}

	}
	else {
		// Validate using SQL Authentication
		bSQLValidate = caODBC._validate_SQLServer_Credentials_SQLAuth( pzServerName, pzAccountName, pzPassword );
		
		if ( !bSQLValidate ) {
			bValidate = FALSE;
			return 12;
		}

	}
	
// End of Check Project Name
/////////////////////////////////////////////////////////////////////////////////////////////

     return dwExitCode;

AnswerRe: c++ win32 CreateThread, Wait, final testing Pin
Albert Holguin1-May-12 3:46
professionalAlbert Holguin1-May-12 3:46 
GeneralRe: c++ win32 CreateThread, Wait, final testing Pin
jkirkerx1-May-12 6:59
professionaljkirkerx1-May-12 6:59 
AnswerRe: c++ win32 CreateThread, Wait, final testing Pin
Albert Holguin2-May-12 5:35
professionalAlbert Holguin2-May-12 5:35 
AnswerI've traced it down to this Pin
jkirkerx1-May-12 13:55
professionaljkirkerx1-May-12 13:55 
GeneralSolved Now Pin
jkirkerx1-May-12 17:35
professionaljkirkerx1-May-12 17:35 
AnswerRe: Solved Now Pin
Albert Holguin1-May-12 18:22
professionalAlbert Holguin1-May-12 18:22 
GeneralRe: Solved Now Pin
jkirkerx1-May-12 18:33
professionaljkirkerx1-May-12 18:33 
GeneralRe: Solved Now Pin
Albert Holguin2-May-12 5:36
professionalAlbert Holguin2-May-12 5:36 
Question[Win32 C++] VirtualFreeEx() error after WriteProcessMemory() success. But not always. Pin
_Kel_30-Apr-12 12:24
_Kel_30-Apr-12 12:24 
AnswerRe: [Win32 C++] VirtualFreeEx() error after WriteProcessMemory() success. But not always. Pin
Richard Andrew x6430-Apr-12 12:54
professionalRichard Andrew x6430-Apr-12 12:54 
GeneralRe: [Win32 C++] VirtualFreeEx() error after WriteProcessMemory() success. But not always. Pin
_Kel_30-Apr-12 13:18
_Kel_30-Apr-12 13:18 
GeneralRe: [Win32 C++] VirtualFreeEx() error after WriteProcessMemory() success. But not always. Pin
Richard Andrew x6430-Apr-12 13:22
professionalRichard Andrew x6430-Apr-12 13:22 
GeneralRe: [Win32 C++] VirtualFreeEx() error after WriteProcessMemory() success. But not always. Pin
_Kel_30-Apr-12 14:30
_Kel_30-Apr-12 14:30 
GeneralRe: [Win32 C++] VirtualFreeEx() error after WriteProcessMemory() success. But not always. Pin
Richard Andrew x6430-Apr-12 14:43
professionalRichard Andrew x6430-Apr-12 14:43 
QuestionOnInitDialog? Pin
Le Quang Long30-Apr-12 4:38
Le Quang Long30-Apr-12 4:38 
AnswerRe: OnInitDialog? Pin
Maximilien30-Apr-12 5:03
Maximilien30-Apr-12 5:03 
GeneralRe: OnInitDialog? Pin
Le Quang Long30-Apr-12 6:20
Le Quang Long30-Apr-12 6:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.