HMODULE GetLanguageResource() { HKEY hKey; LPSTR lanFile=NULL; if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Update\\Locate32",0,KEY_READ,&hKey)==ERROR_SUCCESS) { DWORD lLength; if (RegQueryValueEx(hKey,"Language",0,NULL,NULL,&lLength)==ERROR_SUCCESS) { lanFile=new char[lLength+1]; if (RegQueryValueEx(hKey,"Language",0,NULL,(LPBYTE)lanFile,&lLength)!=ERROR_SUCCESS) { delete[] lanFile; lanFile=NULL; } } RegCloseKey(hKey); } char szPath[MAX_PATH]; int nLen=GetModuleFileName(g_hmodThisDll,szPath,MAX_PATH); for (nLen--;nLen>=0 && szPath[nLen]!='\\';nLen--); nLen++; if (lanFile==NULL) StringCbCopy(szPath+nLen,MAX_PATH-nLen,"lan_en.dll"); else { StringCbCopy(szPath+nLen,MAX_PATH-nLen,lanFile); delete[] lanFile; } return LoadLibrary(szPath); }
SAVESTATE_t* CreateSave(const TCHAR *author, const TCHAR *comment , int model) { SAVESTATE_t* save = (SAVESTATE_t*) malloc(sizeof(SAVESTATE_t)); if (!save) return NULL; save->version_major = CUR_MAJOR; save->version_minor = CUR_MINOR; save->version_build = CUR_BUILD; memset(save->author, 0, sizeof(save->author)); memset(save->comment, 0, sizeof(save->comment)); #ifdef WINVER #ifdef _UNICODE char buffer[64]; size_t numConv; wcstombs_s(&numConv, save->author, author, sizeof(save->author)); wcstombs_s(&numConv, save->comment, comment, sizeof(save->author)); #else StringCbCopy(save->author, sizeof(save->author), author); StringCbCopy(save->comment, sizeof(save->comment), comment); #endif #else strncpy(save->author, author, sizeof(save->author)); strncpy(save->comment, comment, sizeof(save->comment)); #endif save->model = model; save->chunk_count = 0; u_int i; for(i = 0; i < NumElm(save->chunks); i++) { save->chunks[i] = NULL; } return save; }
/******************************Public*Routine******************************\ * ProfileStringIn * \**************************************************************************/ UINT ProfileStringIn( LPTSTR szKey, LPTSTR szDefault, LPTSTR szProfileString, DWORD cb ) { CheckPointer(szKey,0); CheckPointer(szDefault,0); CheckPointer(szProfileString,0); HKEY hKey; DWORD dwType; if((hKey = GetAppKey(FALSE)) == 0) { StringCbCopy(szProfileString, cb, szDefault); return lstrlen(szProfileString); } if((RegQueryValueEx(hKey, szKey, NULL, &dwType, (LPBYTE)szProfileString, &cb) != ERROR_SUCCESS) || dwType != REG_SZ) { StringCbCopy(szProfileString, cb, szDefault); cb = lstrlen(szProfileString); } RegCloseKey(hKey); return cb; }
// // This is a helper routine which extracts a specified NETRESOURCE from hnres. // UINT DropExt_GetNetResource(HGLOBAL hnres, UINT iItem, LPNETRESOURCE pnresOut, UINT cbMax) { LPNRESARRAY panr = GlobalLock(hnres); UINT iRet = 0; // assume error if (hnres) { if (iItem==(UINT)-1) { iRet = panr->cItems; } else if (iItem < panr->cItems) { UINT cbProvider, cbRemoteName; LPCSTR pszProvider = _Offset2Ptr((LPSTR)panr, (UINT_PTR)panr->nr[iItem].lpProvider, &cbProvider); LPCSTR pszRemoteName = _Offset2Ptr((LPSTR)panr, (UINT_PTR)panr->nr[iItem].lpRemoteName, &cbRemoteName); iRet = sizeof(NETRESOURCE) + cbProvider + cbRemoteName; if (iRet <= cbMax) { LPSTR psz = (LPSTR)(pnresOut+1); *pnresOut = panr->nr[iItem]; if (pnresOut->lpProvider) { pnresOut->lpProvider = psz; StringCbCopy(psz, cbProvider, pszProvider); psz += cbProvider; } if (pnresOut->lpRemoteName) { pnresOut->lpRemoteName = psz; StringCbCopy(psz, cbRemoteName, pszRemoteName); } } } GlobalUnlock(hnres); } return iRet; }
CTask::CTask(CONTENT_ID id, LPWSTR name, LPWSTR details, LPWSTR category, LPWSTR dueTime) : CBaseContent() { HRESULT hr = E_FAIL; m_contentID = id; hr = StringCbCopy(m_wszName, sizeof(m_wszName), name); if (FAILED(hr)) { //handle the error } hr = StringCbCopy(m_wszDetails, sizeof(m_wszDetails), details); if (FAILED(hr)) { //handle the error } hr = StringCbCopy(m_wszCategory, sizeof(m_wszCategory), category); if (FAILED(hr)) { //handle the error } hr = StringCbCopy(m_wszTimeDue, sizeof(m_wszTimeDue), dueTime); if (FAILED(hr)) { //handle the error } m_prevId = id-1; m_nextId = id+1; }
void nt_set_env(const Char *name, const Char *val) { char *cname, *cval; int len; cname = name?short2str(name):NULL; if(cname) { len = lstrlen(cname); nameBuf = heap_alloc(len+1); if (!nameBuf) { stderror(ERR_TOOLARGE); } StringCbCopy(nameBuf,len+1,cname); } cval = val?short2str(val):NULL; if(cval) { len = lstrlen(cval); valBuf = heap_alloc(len+1); StringCbCopy(valBuf,len+1,cval); } SetEnvironmentVariable(nameBuf,cval?valBuf:NULL); if (!lstrcmp(nameBuf,"TCSHONLYSTARTEXES")) init_shell_dll(); heap_free(nameBuf); if (cval) heap_free(valBuf); }
KHMEXP void perf_set_thread_desc(const char * file, int line, const wchar_t * name, const wchar_t * creator) { thread_info * t; char * fn_copy; perf_once(); t = malloc(sizeof(*t)); ZeroMemory(t, sizeof(*t)); #ifdef _WIN32 t->thread = GetCurrentThreadId(); #else #error Unsupported platform #endif StringCbCopy(t->name, sizeof(t->name), name); if (creator) StringCbCopy(t->creator, sizeof(t->creator), creator); if (file[0] == '.' && file[1] == '\\') file += 2; EnterCriticalSection(&cs_alloc); fn_copy = hash_lookup(&fn_hash, file); if (fn_copy == NULL) { size_t cblen = 0; if (FAILED(StringCbLengthA(file, MAX_PATH * sizeof(char), &cblen))) fn_copy = NULL; else { fn_copy = malloc(cblen + sizeof(char)); if (fn_copy) { hash_bin * b; int hv; StringCbCopyA(fn_copy, cblen + sizeof(char), file); hv = fn_hash.hash(fn_copy) % fn_hash.n; b = malloc(sizeof(*b)); b->data = fn_copy; b->key = fn_copy; LINIT(b); LPUSH(&fn_hash.bins[hv], b); } } } t->file = fn_copy; t->line = line; LPUSH(&threads, t); LeaveCriticalSection(&cs_alloc); }
khm_boolean afs_method_describe(afs_tk_method method, khm_int32 flags, wchar_t * wbuf, khm_size cbbuf) { khm_size idx; switch(method) { case AFS_TOKEN_AUTO: return LoadString(hResModule, ((flags & KCDB_TS_SHORT)? IDS_NC_METHOD_AUTO: IDS_NC_METHODL_AUTO), wbuf, (int) cbbuf / sizeof(wchar_t)); case AFS_TOKEN_KRB5: return LoadString(hResModule, ((flags & KCDB_TS_SHORT)? IDS_NC_METHOD_KRB5: IDS_NC_METHODL_KRB5), wbuf, (int) cbbuf / sizeof(wchar_t)); case AFS_TOKEN_KRB524: return LoadString(hResModule, ((flags & KCDB_TS_SHORT)? IDS_NC_METHOD_KRB524: IDS_NC_METHODL_KRB524), wbuf, (int) cbbuf / sizeof(wchar_t)); case AFS_TOKEN_KRB4: return LoadString(hResModule, ((flags & KCDB_TS_SHORT)? IDS_NC_METHOD_KRB4: IDS_NC_METHODL_KRB4), wbuf, (int) cbbuf / sizeof(wchar_t)); default: for (idx = 0; idx < n_extensions; idx++) { if(!extensions[idx].provide_token_acq || extensions[idx].token_acq.method_id != method) continue; if ((flags & KCDB_TS_SHORT) || extensions[idx].token_acq.long_desc == NULL) return SUCCEEDED(StringCbCopy(wbuf, cbbuf, extensions[idx].token_acq.short_desc)); else return SUCCEEDED(StringCbCopy(wbuf, cbbuf, extensions[idx].token_acq.long_desc)); } } return FALSE; }
void k5_add_file_cc(k5_ccc_data * d, wchar_t * epath) { khm_size i; khm_size cch; wchar_t path[MAX_PATH]; if (FAILED(StringCchLength(epath, MAX_PATH, &cch)) || cch == 0) return; StringCbCopy(path, sizeof(path), epath); unexpand_env_var_prefix(path, sizeof(path)); /* see if it's there first */ for (i=0; i < d->n_file_ccs; i++) { if(!_wcsicmp(d->file_ccs[i].path, path)) return; } if (d->n_file_ccs == d->nc_file_ccs) { k5_file_cc * f; d->nc_file_ccs = UBOUNDSS(d->n_file_ccs + 1, K5_FCC_ALLOC_INCR, K5_FCC_ALLOC_INCR); #ifdef DEBUG assert(d->nc_file_ccs > d->n_file_ccs); #endif f = PMALLOC(sizeof(*f) * d->nc_file_ccs); ZeroMemory(f, sizeof(*f) * d->nc_file_ccs); if (d->n_file_ccs > 0) { #ifdef DEBUG assert(d->file_ccs != NULL); #endif memcpy(f, d->file_ccs, sizeof(*f) * d->n_file_ccs); } if (d->file_ccs) PFREE(d->file_ccs); d->file_ccs = f; } StringCbCopy(d->file_ccs[d->n_file_ccs].path, sizeof(d->file_ccs[0].path), path); if(PathFileExists(path)) d->file_ccs[d->n_file_ccs].flags = K5_FCC_FLAG_EXISTS; else d->file_ccs[d->n_file_ccs].flags = 0; d->n_file_ccs++; }
kmm_plugin_i * kmmint_get_plugin_i(wchar_t * name) { kmm_plugin_i * p; size_t cb; if(FAILED(StringCbLength(name, KMM_MAXCB_NAME, &cb))) return NULL; cb += sizeof(wchar_t); EnterCriticalSection(&cs_kmm); p = (kmm_plugin_i *) hash_lookup(hash_plugins, (void *) name); if(p == NULL) { p = PMALLOC(sizeof(kmm_plugin_i)); ZeroMemory(p, sizeof(kmm_plugin_i)); p->magic = KMM_PLUGIN_MAGIC; p->p.name = PMALLOC(cb); StringCbCopy(p->p.name, cb, name); p->state = KMM_PLUGIN_STATE_NONE; hash_add(hash_plugins, (void *) p->p.name, (void *) p); kmmint_list_plugin(p); } LeaveCriticalSection(&cs_kmm); return p; }
//꼬리에 삽입 DWORD Insert(LISTMGR* pListMgr, PROCESS_INFO* pData) { LLIST *pNewList; pNewList = (LLIST*)HeapAlloc(GetProcessHeap(), HEAP_NO_SERIALIZE, sizeof(LLIST)); pNewList->data.Depth = pData->Depth; pNewList->data.Pid = pData->Pid; pNewList->data.ParentId = pData->ParentId; StringCbCopy(pNewList->data.pszProcessName, 128, pData->pszProcessName); pNewList->pNext = NULL; if (pListMgr->NumOfContents == 0) { pListMgr->pHead = pNewList; pListMgr->pCur = pNewList; pListMgr->pTail = pNewList; } else { pListMgr->pTail->pNext = pNewList; pListMgr->pTail = pNewList; } return ++pListMgr->NumOfContents; }
KHMEXP khm_int32 KHMAPI kcdb_type_get_name(khm_int32 id, wchar_t * buffer, khm_size * cbbuf) { size_t cbsize; kcdb_type_i * t; if(id < 0 || id > KCDB_TYPE_MAX_ID || !cbbuf) return KHM_ERROR_INVALID_PARAM; t = kcdb_type_tbl[id]; if(!t) return KHM_ERROR_NOT_FOUND; if(FAILED(StringCbLength(t->type.name, KCDB_MAXCB_NAME, &cbsize))) return KHM_ERROR_UNKNOWN; cbsize += sizeof(wchar_t); if(!buffer || *cbbuf < cbsize) { *cbbuf = cbsize; return KHM_ERROR_TOO_LONG; } StringCbCopy(buffer, *cbbuf, t->type.name); *cbbuf = cbsize; return KHM_ERROR_SUCCESS; }
khm_int32 KHMAPI kcdb_type_data_toString( const void * d, khm_size cbd, wchar_t * buffer, khm_size * cb_buf, khm_int32 flags) { size_t cbsize; if(!cb_buf) return KHM_ERROR_INVALID_PARAM; cbsize = sizeof(GENERIC_DATA_STR); if(!buffer || *cb_buf < cbsize) { *cb_buf = cbsize; return KHM_ERROR_TOO_LONG; } StringCbCopy(buffer, *cb_buf, GENERIC_DATA_STR); *cb_buf = cbsize; return KHM_ERROR_SUCCESS; }
khm_int32 KHMAPI kvno_toString(const void * data, khm_size cbdata, wchar_t *destbuf, khm_size *pcbdestbuf, khm_int32 flags) { int resid = 0; int kvno; wchar_t buf[256]; size_t cblength; if (cbdata != sizeof(khm_int32)) return KHM_ERROR_INVALID_PARAM; kvno = *((khm_int32 *) data); StringCbPrintf(buf, sizeof(buf), L"#%d", kvno); StringCbLength(buf, ARRAYLENGTH(buf), &cblength); cblength += sizeof(wchar_t); if (!destbuf || *pcbdestbuf < cblength) { *pcbdestbuf = cblength; return KHM_ERROR_TOO_LONG; } else { StringCbCopy(destbuf, *pcbdestbuf, buf); *pcbdestbuf = cblength; return KHM_ERROR_SUCCESS; } }
int CWnd::ShowErrorMessage(UINT nIDMsgStr,UINT nIDTitleStr,UINT uType) const { if (IsUnicodeSystem()) { WCHAR title[100]; WCHAR msg[1000]; LoadStringW(GetLanguageSpecificResourceHandle(),nIDMsgStr,msg,1000); if (nIDTitleStr) LoadStringW(GetLanguageSpecificResourceHandle(),nIDTitleStr,title,100); else StringCbCopyW(title,100*2,szwError); return ::MessageBoxW(m_hWnd,msg,title,uType); } else { char title[100]; char msg[1000]; LoadString(nIDMsgStr,msg,1000); if (nIDTitleStr) LoadString(nIDTitleStr,title,100); else StringCbCopy(title,100,szError); return ::MessageBox(m_hWnd,msg,title,uType); } }
khm_int32 KHMAPI afs_type_principal_toString(const void * d, khm_size cbd, wchar_t * buffer, khm_size * cb_buf, khm_int32 flags) { size_t cbsize; struct ktc_principal * p; wchar_t sprinc[512] = L""; if(!cb_buf) return KHM_ERROR_INVALID_PARAM; p = (struct ktc_principal *) d; // assume this works. afs_princ_to_string(p, sprinc, sizeof(sprinc)); StringCbLength(sprinc, sizeof(sprinc), &cbsize); cbsize += sizeof(wchar_t); if(!buffer || *cb_buf < cbsize) { *cb_buf = cbsize; return KHM_ERROR_TOO_LONG; } StringCbCopy(buffer, *cb_buf, sprinc); *cb_buf = cbsize; return KHM_ERROR_SUCCESS; }
HRESULT CLocalCertStoreImp::GetDecodedCertName(PCERT_NAME_BLOB pCertName, DWORD dwStrType, LPTSTR szCertName, ULONG nBufferMax) { DWORD dwDataLength = 0; PWCHAR pString = NULL; HRESULT hr = S_OK; if (pCertName == NULL) { return E_INVALIDARG; } // find the length first dwDataLength = ::CertNameToStr(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, pCertName, dwStrType, NULL, 0); if (dwDataLength == 0) { return E_FAIL; } pString = new WCHAR[dwDataLength]; if (pString == NULL) { return E_OUTOFMEMORY; } CertNameToStr(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, pCertName, dwStrType, pString, dwDataLength); StringCbCopy(szCertName, nBufferMax, pString); // perform cleanup delete[] pString; pString = NULL; return hr; }
/* * Gets where the next screenshot should be saved to. * Returns true if ready, false if user cancels */ BOOL get_screenshot_filename(TCHAR *ext) { StringCbCopy(screenshot_fn_backup, sizeof(screenshot_fn_backup), screenshot_file_name); if (screenshot_autosave) { /* do file save */ if (screenshot_use_increasing) { get_next_filename(ext); } } else { int index; if (_tcscmp(ext, pngext) == 0) { index = 2; } else { index = 1; } #ifdef _WINDOWS #ifndef _WINDLL if (SaveFile(screenshot_file_name, _T("Graphics Interchange Format (*.gif)\0*.gif\0Portable Network Graphics (*.png)\0*.png\0All Files (*.*)\0*.*\0\0"), _T("Wabbitemu Screenshot File Target"), ext, 0, index)) //if we cancel, mark the menu and set to idle return FALSE; #endif #endif } return TRUE; }
PIMAGE_SECTION_HEADER GetExportSection(LPVOID ImageBase) { CHAR SectionName[9] = {0}; DWORD ExportRVA = NtHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; DWORD ExportSize = NtHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size; printf("\n[*] ExportDirectory RVA: %08X", ExportRVA); printf("\n[*] ExportDirectory Size: %d", ExportSize); //PIMAGE_SECTION_HEADER Section = (PIMAGE_SECTION_HEADER) ((DWORD) NtHeaders + sizeof(IMAGE_NT_HEADERS)); PIMAGE_SECTION_HEADER Section = IMAGE_FIRST_SECTION(NtHeaders); //Predefined Macro #ifdef _DEBUG printf("\n[?] First Section Offset: %08X(%d)", ((DWORD) Section - (DWORD) ImageBase), ((DWORD) Section - (DWORD) ImageBase)); StringCbCopy((STRSAFE_LPSTR) SectionName, 8, (STRSAFE_LPCSTR) Section->Name); printf("\n[?] Name: %s", SectionName); printf("\n[?] RVA: %08X", Section->VirtualAddress); printf("\n[?] PtrToRawData: %08X", Section->PointerToRawData); printf("\n[?] SizeOfRawData: %d", Section->SizeOfRawData); #endif // DEBUG PIMAGE_SECTION_HEADER ExportSection = GetRvaEnclosingSection(ExportRVA); if (ExportSection) { printf("\n[*] Section for Export Table:"); printf("\n[*] Name: %s", ExportSection->Name); printf("\n[*] RVA: %08X", ExportSection->VirtualAddress); printf("\n[*] PtrToRawData: %08X", ExportSection->PointerToRawData); printf("\n[*] SizeOfRawData: %d", ExportSection->SizeOfRawData); } return ExportSection; }
void init_hb_subst(void) { int i= 0; size_t len; char envbuf[1024]; char *ptr; char *p2; envbuf[0]=0; GetEnvironmentVariable("TCSHSUBSTHB",envbuf,1024); ptr = &envbuf[0]; if (!*ptr) return; p2 = ptr; while (*ptr) { if (*ptr == ';') { len = ptr - p2; if (!len){ ptr++; continue; } hb_subst_array[i] = heap_alloc(len+1); StringCbCopy(hb_subst_array[i],len + 1, p2); i++; p2 = ptr+1; } ptr++; } }
KHMEXP khm_int32 KHMAPI khui_alert_set_title(khui_alert * alert, const wchar_t * title) { size_t cb = 0; assert(alert->magic == KHUI_ALERT_MAGIC); if(title) { if(FAILED(StringCbLength(title, KHUI_MAXCB_TITLE, &cb))) { return KHM_ERROR_INVALID_PARAM; } cb += sizeof(wchar_t); } EnterCriticalSection(&cs_alerts); if(alert->title && (alert->flags & KHUI_ALERT_FLAG_FREE_TITLE)) { PFREE(alert->title); alert->title = NULL; alert->flags &= ~KHUI_ALERT_FLAG_FREE_TITLE; } if(title) { alert->title = PMALLOC(cb); StringCbCopy(alert->title, cb, title); alert->flags |= KHUI_ALERT_FLAG_FREE_TITLE; } alert->flags |= KHUI_ALERT_FLAG_MODIFIED; LeaveCriticalSection(&cs_alerts); return KHM_ERROR_SUCCESS; }
BOOL is_url(const char *thecmd) { char *protocol; const char *c; HKEY hkey; char buf[2]; DWORD type; DWORD size; c = strchr(thecmd, ':'); size = (DWORD)(c - thecmd); if (!c || size <= 1) return FALSE; protocol = (char *)heap_alloc(size + 2); StringCbCopy(protocol,size+2, thecmd); protocol[size] = '\0'; if (RegOpenKeyEx(HKEY_CLASSES_ROOT, protocol, 0, KEY_READ, &hkey) != ERROR_SUCCESS ) { heap_free(protocol); return FALSE; } heap_free(protocol); type = REG_SZ; size = sizeof(buf); if ( RegQueryValueEx(hkey, "URL Protocol", NULL, &type, (BYTE*)buf, &size) != ERROR_SUCCESS) { RegCloseKey(hkey); return FALSE; } RegCloseKey(hkey); return TRUE; }
/* * uname(struct utsname *name) */ void SysCalls::sys_uname(CONTEXT& ctx) { linux::new_utsname * pU = (linux::new_utsname *)ctx.Ebx; linux::new_utsname U; DWORD siz = sizeof(U.sysname); GetComputerName(U.sysname, &siz); StringCbCopy(U.nodename, sizeof(U.nodename), U.sysname); StringCbCopy(U.release, sizeof(U.release), g_pKernelTable->m_KernelVersion.c_str()); StringCbCopy(U.version, sizeof(U.version), "keow"); StringCbCopy(U.machine, sizeof(U.machine), g_pKernelTable->m_KernelCpuType.c_str()); U.domainname[0] = 0; P->WriteMemory((ADDR)pU, sizeof(U), &U); ctx.Eax = 0; }
KHMEXP khm_int32 KHMAPI kcdb_credtype_get_name( khm_int32 id, wchar_t * buf, khm_size * cbbuf) { size_t s; kcdb_credtype_i * t; khm_int32 rv = KHM_ERROR_SUCCESS; if(!cbbuf || id < 1 || id > KCDB_CREDTYPE_MAX_ID) return KHM_ERROR_INVALID_PARAM; EnterCriticalSection(&cs_credtype); t = kcdb_credtype_tbl[id]; if(t) { StringCbLength(t->ct.name, KCDB_MAXCB_NAME, &s); s += sizeof(wchar_t); if(!buf || *cbbuf < s) { *cbbuf = s; rv = KHM_ERROR_TOO_LONG; } else { StringCbCopy(buf, *cbbuf, t->ct.name); *cbbuf = s; } } else { *cbbuf = 0; rv = KHM_ERROR_NOT_FOUND; } LeaveCriticalSection(&cs_credtype); return rv; }
/* String */ khm_int32 KHMAPI kcdb_type_string_toString( const void * d, khm_size cbd, wchar_t * buffer, khm_size * cb_buf, khm_int32 flags) { size_t cbsize; wchar_t * sd; if(!cb_buf) return KHM_ERROR_INVALID_PARAM; sd = (wchar_t *) d; if(FAILED(StringCbLength(sd, KCDB_TYPE_MAXCB, &cbsize))) return KHM_ERROR_INVALID_PARAM; cbsize += sizeof(wchar_t); if(!buffer || *cb_buf < cbsize) { *cb_buf = cbsize; return KHM_ERROR_TOO_LONG; } StringCbCopy(buffer, *cb_buf, sd); *cb_buf = cbsize; return KHM_ERROR_SUCCESS; }
khm_int32 KHMAPI kcdb_type_string_dup( const void * d_src, khm_size cbd_src, void * d_dst, khm_size * cbd_dst) { size_t cbsize; if(!cbd_dst) return KHM_ERROR_INVALID_PARAM; if(cbd_src == KCDB_CBSIZE_AUTO) { cbd_src = KCDB_TYPE_MAXCB; } if(FAILED(StringCbLength((const wchar_t *) d_src, cbd_src, &cbsize))) { return KHM_ERROR_UNKNOWN; } cbsize += sizeof(wchar_t); if(!d_dst || *cbd_dst < cbsize) { *cbd_dst = cbsize; return KHM_ERROR_TOO_LONG; } StringCbCopy((wchar_t *) d_dst, *cbd_dst, (const wchar_t *) d_src); *cbd_dst = cbsize; return KHM_ERROR_SUCCESS; }
khm_int32 KHMAPI afs_type_method_toString(const void * data, khm_size cb_data, wchar_t * s_buf, khm_size * pcb_s_buf, khm_int32 flags) { khm_int32 * pmethod = (khm_int32 *) data; wchar_t wbuf[KHUI_MAXCCH_LONG_DESC]; khm_size cb; if (!data || cb_data != sizeof(khm_int32)) return KHM_ERROR_INVALID_PARAM; wbuf[0] = L'\0'; if (!afs_method_describe(*pmethod, flags, wbuf, sizeof(wbuf))) { LoadString(hResModule, IDS_NC_METHOD_INVALID, wbuf, ARRAYLENGTH(wbuf)); } StringCbLength(wbuf, sizeof(wbuf), &cb); cb += sizeof(wchar_t); if (!s_buf || *pcb_s_buf < cb) { *pcb_s_buf = cb; return KHM_ERROR_TOO_LONG; } else { StringCbCopy(s_buf, *pcb_s_buf, wbuf); *pcb_s_buf = cb; return KHM_ERROR_SUCCESS; } }
khm_int32 KHMAPI kcdb_type_int64_toString( const void * d, khm_size cbd, wchar_t * buffer, khm_size * cb_buf, khm_int32 flags) { size_t cbsize; wchar_t ibuf[22]; if(!cb_buf) return KHM_ERROR_INVALID_PARAM; StringCbPrintf(ibuf, sizeof(ibuf), L"%I64d", *((__int64 *) d)); StringCbLength(ibuf, sizeof(ibuf), &cbsize); cbsize += sizeof(wchar_t); if(!buffer || *cb_buf < cbsize) { *cb_buf = cbsize; return KHM_ERROR_TOO_LONG; } StringCbCopy((wchar_t *) buffer, *cb_buf, ibuf); *cb_buf = cbsize; return KHM_ERROR_SUCCESS; }
KHMEXP khm_int32 KHMAPI khui_cfg_get_name(khui_config_node vnode, wchar_t * buf, khm_size * cb_buf) { khui_config_node_i * node; khm_int32 rv = KHM_ERROR_SUCCESS; if (!cb_buf || !cfgui_is_valid_node_handle(vnode)) return KHM_ERROR_INVALID_PARAM; EnterCriticalSection(&cs_cfgui); if (cfgui_is_valid_node_handle(vnode)) { khm_size cb; node = cfgui_node_i_from_handle(vnode); StringCbLength(node->reg.name, KHUI_MAXCCH_NAME, &cb); if (buf == NULL || cb > *cb_buf) { *cb_buf = cb; rv = KHM_ERROR_TOO_LONG; } else { StringCbCopy(buf, *cb_buf, node->reg.name); *cb_buf = cb; } } else { rv = KHM_ERROR_INVALID_PARAM; } LeaveCriticalSection(&cs_cfgui); return rv; }
static void SendIceMsg( std::string sMsg, CString sFlag ) { HWND hWnd = ::FindWindow( NULL, "ICEClientDemo" ); if ( hWnd != NULL ) { int nWsize = sMsg.size() + 16; int nPsize = sFlag.GetLength() + 16; char* pWaram = new char[ nWsize ]; char* pParam = new char[ nPsize ]; ZeroMemory( pWaram, nWsize ); ZeroMemory( pParam, nPsize ); StringCbCopy( pWaram, nWsize, sMsg.c_str() ); StringCbCopy( pParam, nPsize, sFlag ); ::PostMessage( hWnd, WM_ICE_MESSAGE, (WPARAM)pWaram, (LPARAM)(char*)pParam ); } }