int IniWriteInteger (const char *section, const char *indent, int value, char *inifilename) { char str[20]; memset (str, 0, 20); sprintf (str, "%d", value); IniWriteString (section, indent, str, inifilename); return 0; }
BOOL setSubWindowPlacement( CWnd *pwnd, int vnum) { BOOL handled = FALSE; char name[16]; char rgch[80]; WINDOWPLACEMENT wp = {0}; wp.length = sizeof(wp); if (0 != pwnd->GetWindowPlacement(&wp)) { RECT r = {0}; RECT *prc = &wp.rcNormalPosition; POINT *pptMin= &wp.ptMinPosition; POINT *pptMax= &wp.ptMaxPosition; int state = 0; handled = TRUE; if (wp.showCmd == SW_SHOWMAXIMIZED) { state = P95_WP_MAXIMIZED; } else if (wp.showCmd == SW_SHOWMINIMIZED) { state = P95_WP_MINIMIZED; } wsprintf(rgch, "%d %ld %ld %ld %ld %ld %ld %ld %ld", state, prc->top, prc->right, prc->bottom, prc->left, pptMin->x, pptMin->y, pptMax->x, pptMax->y ); wsprintf(name, "W%d", vnum); IniWriteString(INI_FILE, name, rgch); } return handled; }
int main(int argc, char *argv[]) { const char szSection[] = "student"; const char szKeyName[] = "name"; const char szKeyAge[] = "age"; char szValue[TEST_BUF_SIZE]={0}; int age; if (0 != IniWriteString(TEST_INI_FILE, szSection, szKeyName, "Tony")) { printf("IniWriteString failed. [%s, %s, %s]\n", szSection, szKeyName, "Tony"); } else { printf("IniWriteString success. [%s, %s, %s]\n", szSection, szKeyName, "Tony"); } if (0 != IniWriteString(TEST_INI_FILE, szSection, szKeyAge, "20")) { printf("IniWriteString failed. [%s, %s, %s]\n", szSection, szKeyAge, "20"); } else { printf("IniWriteString Success. [%s, %s, %s]\n", szSection, szKeyAge, "20"); } if (0 != IniReadString(TEST_INI_FILE, szSection, szKeyName, szValue, TEST_BUF_SIZE, "")) { printf("IniReadString failed. [%s, %s]\n", szSection, szKeyName); } else { printf("IniReadString success. [%s, %s, %s]\n", szSection, szKeyName, szValue); } age = IniReadInt(TEST_INI_FILE, szSection, szKeyAge, 0); printf("IniReadInt here. [%s, %s, %d]\n", szSection, szKeyAge, age); /* 用例 */ if (0 != IniReadString(TEST_INI_FILE, "Main", "test case", szValue, TEST_BUF_SIZE, NULL)) { printf("IniReadString failed. [%s, %s]\n", "Main", "test case"); } else { printf("IniReadString success. [%s, %s, %s]\n", "Main", "test case", szValue); } /* 用例 */ if (0 != IniReadString(TEST_INI_FILE, "Main", "test case1", szValue, TEST_BUF_SIZE, NULL)) { printf("IniReadString failed. [%s, %s]\n", "Main", "test case1"); } else { printf("IniReadString success. [%s, %s, %s]\n", "Main", "test case1", szValue); } /* 用例 */ if (0 != IniWriteString(TEST_INI_FILE, "Main", "test case1", "TEST CASE1")) { printf("IniWriteString failed. [%s, %s]\n", "Main", "test case1"); } else { printf("IniWriteString success. [%s, %s]\n", "Main", "test case1"); } if (0 != IniReadString(TEST_INI_FILE, "Main", "test case1", szValue, TEST_BUF_SIZE, NULL)) { printf("IniReadString failed. [%s, %s]\n", "Main", "test case1"); } else { printf("IniReadString success. [%s, %s, %s]\n", "Main", "test case1", szValue); } return 0; }
void test_primenet (void) { int m_primenet, m_dialup; unsigned long m_proxy_port, m_debug; char m_userid[21], m_compid[21], m_proxy_host[121]; char m_proxy_user[51], m_proxy_pwd[51], orig_proxy_pwd[51]; unsigned short proxy_port; int update_computer_info, primenet_debug; char m_username[81], m_userpwd[14]; update_computer_info = FALSE; primenet_debug = IniSectionGetInt (INI_FILE, "PrimeNet", "Debug", 0); m_primenet = USE_PRIMENET; if (strcmp (USERID, "ANONYMOUS") == 0) m_userid[0] = 0; else strcpy (m_userid, USERID); strcpy (m_compid, COMPID); m_dialup = DIAL_UP; getProxyInfo (m_proxy_host, &proxy_port, m_proxy_user, m_proxy_pwd); m_proxy_port = proxy_port; strcpy (orig_proxy_pwd, m_proxy_pwd); m_debug = primenet_debug; askYN ("Use PrimeNet to get work and report results", &m_primenet); if (!m_primenet) goto done; outputLongLine ("\nYou must first create your user ID at mersenne.org or leave user ID blank to run anonymously. See the readme.txt file for details.\n"); askStr ("Optional user ID", m_userid, 20); askStr ("Optional computer name", m_compid, 20); askYN ("Computer uses a dial-up connection to the Internet", &m_dialup); askStr ("Optional proxy host name", m_proxy_host, 120); if (!m_proxy_host[0]) goto done; askNum ("Proxy port number", &m_proxy_port, 1, 65535); askStr ("Optional proxy user name", m_proxy_user, 50); askStr ("Optional proxy password", m_proxy_pwd, 50); askNum ("Output debug info to prime.log (0=none, 1=some, 2=lots)", &m_debug, 0, 2); done: if (askOkCancel ()) { DIAL_UP = m_dialup; IniWriteInt (INI_FILE, "DialUp", DIAL_UP); if (m_proxy_host[0] && m_proxy_port != 8080) sprintf (m_proxy_host + strlen (m_proxy_host), ":%lu", m_proxy_port); IniSectionWriteString (INI_FILE, "PrimeNet", "ProxyHost", m_proxy_host); if (m_proxy_host[0]) { IniSectionWriteString (INI_FILE, "PrimeNet", "ProxyUser", m_proxy_user); if (strcmp (m_proxy_pwd, orig_proxy_pwd)) { IniSectionWriteString (INI_FILE, "PrimeNet", "ProxyPass", m_proxy_pwd); IniSectionWriteInt (INI_FILE, "PrimeNet", "ProxyMask", 0); } } if (m_debug != primenet_debug) { IniSectionWriteInt (INI_FILE, "PrimeNet", "Debug", m_debug); } if (m_userid[0] == 0) strcpy (m_userid, "ANONYMOUS"); if (strcmp (USERID, m_userid) != 0) { strcpy (USERID, m_userid); sanitizeString (USERID); IniWriteString (INI_FILE, "V5UserID", USERID); update_computer_info = TRUE; } if (strcmp (COMPID, m_compid) != 0) { strcpy (COMPID, m_compid); sanitizeString (COMPID); IniWriteString (LOCALINI_FILE, "ComputerID", COMPID); update_computer_info = TRUE; } if (!USE_PRIMENET && m_primenet) { USE_PRIMENET = 1; create_window (COMM_THREAD_NUM); base_title (COMM_THREAD_NUM, "Communication thread"); if (!STARTUP_IN_PROGRESS) set_comm_timers (); spoolMessage (PRIMENET_UPDATE_COMPUTER_INFO, NULL); spoolExistingResultsFile (); } else if (USE_PRIMENET && !m_primenet) { USE_PRIMENET = 0; if (!STARTUP_IN_PROGRESS) set_comm_timers (); } else if (update_computer_info) spoolMessage (PRIMENET_UPDATE_COMPUTER_INFO, NULL); IniWriteInt (INI_FILE, "UsePrimenet", USE_PRIMENET); spoolMessage (PRIMENET_PROGRAM_OPTIONS, NULL); } else STARTUP_IN_PROGRESS = 0; }