Exemple #1
0
/* 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;
}
Exemple #2
0
BOOL EnableAutoLogin()
{
	TCHAR strModuleName[MAX_PATH];
	if ( !GetSupportFilePath( AWHK_MAIN_EXE, strModuleName, MAX_PATH ) )
		return FALSE;

	HKEY hKey;
	if ( ::RegOpenKeyEx(
		HKEY_CURRENT_USER,
		AWHK_RUN_KEY,
		0,
		KEY_SET_VALUE,
		&hKey ) != ERROR_SUCCESS )
	{
		return FALSE;
	}

	size_t moduleNameLen = 0;
	StringCbLength(
		strModuleName,
		MAX_PATH,
		&moduleNameLen );

	LONG ret = ::RegSetValueEx(
		hKey,
		AWHK_RUN_ENTRY_NAME,
		0,
		REG_SZ,
		(BYTE*) strModuleName, 
		(DWORD) moduleNameLen );
	
	::RegCloseKey( hKey );

	return ret == ERROR_SUCCESS;
}
Exemple #3
0
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;
}
/*****************************************************************************
DWORD WriteSfvHeader(CONST HANDLE hFile)
hFile		: (IN) handle to an open file

Return Value:
- returns NOERROR or GetLastError()
*****************************************************************************/
DWORD WriteSfvHeader(CONST HANDLE hFile)
{
    TCHAR szLine[MAX_LINE_LENGTH];
#ifdef UNICODE
    CHAR szLineAnsi[MAX_LINE_LENGTH];
#endif
    DWORD dwNumberOfBytesWritten;
    size_t stStringLength;
    VOID *szOutLine=szLine;

    StringCbPrintf(szLine, MAX_LINE_LENGTH, TEXT("; Generated by WIN-SFV32 v1 (compatible; RapidCRC http://rapidcrc.sourceforge.net unicode-file mod by OV2)%s;%s"),
                   g_program_options.bCreateUnixStyle ? TEXT("\n") : TEXT("\r\n"), g_program_options.bCreateUnixStyle ? TEXT("\n") : TEXT("\r\n"));

    StringCbLength(szLine, MAX_LINE_LENGTH, & stStringLength);

#ifdef UNICODE
    if(!g_program_options.bCreateUnicodeFiles || g_program_options.iUnicodeSaveType == UTF_8 || g_program_options.iUnicodeSaveType==UTF_8_BOM) {
        if(!WideCharToMultiByte(CP_ACP, 0, szLine, -1, szLineAnsi, MAX_UTF8_PATH, NULL, NULL) )
            return GetLastError();

        StringCbLengthA(szLineAnsi, MAX_LINE_LENGTH, & stStringLength);
        szOutLine=szLineAnsi;
    }
#endif

    if(!WriteFile(hFile, szOutLine, (DWORD)stStringLength, & dwNumberOfBytesWritten, NULL) )
        return GetLastError();

    return NOERROR;
}
Exemple #5
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;
}
Exemple #6
0
//+++	起動時しょっぱなのチェック.
static bool CheckOneInstance(LPTSTR lpstrCmdLine)
{
	//ChangeWindowMessageFilter(WM_NEWINSTANCE, MSGFLT_ADD); //+++ ユーザーメッセージを通過させるためにvistaでの開発中は必要?(て、そもそもつかえなかった)
	
	CIniFileI	pr(g_szIniFileName, _T("Main"));
	pr.QueryValue(CMainOption::s_dwMainExtendedStyle, _T("Extended_Style"));
	if (CMainOption::s_dwMainExtendedStyle & MAIN_EX_ONEINSTANCE) { // 複数起動を許可しない
		HWND hWnd = ::FindWindow(DONUT_WND_CLASS_NAME, NULL);
		if (hWnd) {		// 既に起動しているunDonutが見つかった
			COPYDATASTRUCT	cd;
			cd.dwData	= 1;
			size_t	cbCommandLine = 0;
			StringCbLength(lpstrCmdLine, sizeof(TCHAR) * 2048, &cbCommandLine);
			cd.cbData	= (DWORD)cbCommandLine + sizeof(TCHAR);
			cd.lpData	= lpstrCmdLine;
			::SendMessage(hWnd, WM_COPYDATA, NULL, (LPARAM)&cd);
		
			bool	bActive = !(CMainOption::s_dwMainExtendedStyle & MAIN_EX_NOACTIVATE);
			if (bActive)
				::SetForegroundWindow(hWnd);
			return true;
		}
	}
	return false;
}
Exemple #7
0
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;
}
Exemple #8
0
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;
    }
}
Exemple #9
0
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;
}
Exemple #10
0
// Console, Wide
VOID my_putsCW( HANDLE h, LPCTSTR s )
{
	DWORD n1, n2;
	DWORD len = 0;
	LPWSTR p;
	size_t n;

#ifdef UNICODE
	p = (LPWSTR)s;
	if( (len = StringCbLength( p, 4096, &n ) ) != S_OK ) len = 0;
	else len = n;
#else
	if( ( len = MultiByteToWideChar( CP_ACP, 0, s, -1, NULL, 0 ) ) == 0 ) return;
	if( ( p = (LPWSTR)LocalAlloc( LMEM_FIXED, len ) ) == NULL ) return;
	len = MultiByteToWideChar( CP_ACP, 0, s, -1, p, len );
#endif
	n1 = len ? len - 1 : 0;
	while( n1 ){
		if( !WriteFile( h, p, n1, &n2, NULL ) )  break;
		n1 -= n2;
	}
#ifndef UNICODE
	LocalFree( p );
#endif
}
Exemple #11
0
kmm_module_i * kmmint_get_module_i(wchar_t * name)
{
    kmm_module_i * m;
    size_t sz;

    if(FAILED(StringCbLength(name, KMM_MAXCB_NAME, &sz)))
        return NULL;
    sz += sizeof(wchar_t);

    EnterCriticalSection(&cs_kmm);
    m = (kmm_module_i *) hash_lookup(hash_modules, (void *) name);

    if(m == NULL) {
        m = PMALLOC(sizeof(kmm_module_i));
        ZeroMemory(m, sizeof(kmm_module_i));

        m->magic = KMM_MODULE_MAGIC;
        m->name = PMALLOC(sz);
        StringCbCopy(m->name, sz, name);
        m->state = KMM_MODULE_STATE_NONE;

        hash_add(hash_modules, (void *) m->name, (void *) m);
        LPUSH(&kmm_all_modules, m);
    }
    LeaveCriticalSection(&cs_kmm);

    return m;
}
Exemple #12
0
void GDisplay::DrawDescription(HDC hDC, LPRECT lpRect)
{
	TCHAR szTitle[LONG_STR_LEN];
	size_t nSize;

	HFONT hOldFont = (HFONT)::SelectObject(hDC, m_hFont);

	for (int k = 0; k < m_nChartCount; k++)
	{
		UINT id = SIMVAR_BASE_ID + m_nSimVarID[k];
		if(MyLoadString(id, szTitle, LONG_STR_LEN))
		{
			if(SUCCEEDED(StringCbLength(szTitle, LONG_STR_LEN, &nSize)))
			{
				SetTextColor(hDC, m_clrMarker[k]);

				TextOut(hDC, 
					lpRect->left - m_dxText, 
					lpRect->bottom + 16 + 18*k, 
					szTitle, (int)nSize/sizeof(TCHAR));	
			}
		}
	}

	::SelectObject(hDC, hOldFont);

}
Exemple #13
0
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;
    }
}
Exemple #14
0
BOOL WINAPI GetProcessName(DWORD dwPid, TCHAR* lpBuffer, size_t dwBufsize)
{
	HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
	PROCESSENTRY32 pe = { sizeof(pe), 0 };
	size_t nLen;

	if (hSnap == INVALID_HANDLE_VALUE)
		return FALSE;

	if (!Process32First(hSnap, &pe))
		return FALSE;

	do
	{
		try
		{
			if (dwPid != pe.th32ProcessID)
				continue;

			StringCbLength(pe.szExeFile, MAX_PATH - 1, &nLen);
			CharUpperBuffW(pe.szExeFile, nLen);
			StringCbCopy(lpBuffer, dwBufsize, pe.szExeFile);
		}
		catch (...)
		{
			CloseHandle(hSnap);
			return FALSE;
		}
	} while (Process32Next(hSnap, &pe));

	CloseHandle(hSnap);

	return TRUE;
}
Exemple #15
0
// Console, ANSI
VOID my_putsCA( HANDLE h, LPCTSTR s )
{
	DWORD n1, n2;
	DWORD len = 0;
	LPSTR p;

#ifdef UNICODE
	UINT cp = GetConsoleOutputCP();

	if( ( len = WideCharToMultiByte( cp, 0, s, -1, NULL, 0, NULL, NULL ) ) == 0 ) return;
	if( ( p = (LPSTR)LocalAlloc( LMEM_FIXED, len ) ) == NULL ) return;
	len = WideCharToMultiByte( cp, 0, s, -1, p, len, NULL, NULL );
#else
	size_t n;
	p = (LPTSTR)s;
	if( StringCbLength( p, 4096, &n ) != S_OK ) len = 0;
	else len = n;
#endif

	n1 = len ? len -1 : 0;
	while( n1 ){
		if( !WriteFile( h, p, n1, &n2, NULL ) )  break;
		n1 -= n2;
	}
#ifdef UNICODE
	LocalFree( p );
#endif
}
Exemple #16
0
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;
}
Exemple #17
0
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;
}
Exemple #18
0
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;
}
Exemple #19
0
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;
}
Exemple #20
0
int RecogniseECU (ECU_info* dllECUinfo)
{
    unsigned int i, s_crc, FindOffset, HexCount ;
    char* FileDescr="HYUNDAY Bosch M7.9.7";
//	char cf_crc[30];

    unsigned char HexBytes1[]= {0x00, 0x00, 0x80, 0x00, 0xFD, 0x5E, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0xFF, 0xFB, 0x80, 0x00};
    unsigned char HexBytes2[]= {0x00, 0x00, 0x80, 0x00, 0xFF, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0xFF, 0xFB, 0x80, 0x00};
    HexCount=16;

    DWORD Buffer= (DWORD)dllECUinfo->EcuBuffer;


    //Распознаем ECU
    if (dllECUinfo->EcuFileSize!=ECUFILESIZE)
    {
        return 0;
    }

    FindOffset=FindHexStr(0, dllECUinfo->EcuFileSize, (unsigned char*)Buffer , HexBytes1, HexCount);
    if (FindOffset==0xFFFFFFFF)
    {
        FindOffset=FindHexStr(0, dllECUinfo->EcuFileSize, (unsigned char*)Buffer , HexBytes2, HexCount);
        if (FindOffset==0xFFFFFFFF)
        {
            return 0;
        }
    }
    if (!FindFixCRC(dllECUinfo, 0))
    {
        return 0;
    }

    /*	for (i = 0; i < dllECUinfo->EcuFileSize; i++)
    		{
    			f_crc+= *(unsigned char*)(Buffer+i);
    		}
    */
    StringCbLength(FileDescr, 50, &s_crc);
    StringCbCopyN (dllECUinfo->ECU_Descr, 100, FileDescr, s_crc);
    /*	IntToChar (f_crc, cf_crc);
    	StringCbLength(cf_crc, 50, &s_crc);
    	StringCbCatN (dllECUinfo->ECU_Descr, 100, cf_crc, s_crc+1 );
    */
    /*	FindOffset=FindHexStr(0, dllECUinfo->EcuFileSize, (unsigned char*)Buffer , HexBytes, HexCount);
    	f_crc=SummInt8(0, dllECUinfo->EcuFileSize-1, (unsigned char*)Buffer );
    	s_crc=SummInt16Intel(0, dllECUinfo->EcuFileSize-1, (unsigned char*)Buffer );
    	s_crc=SummInt16Mot(0, dllECUinfo->EcuFileSize-1, (unsigned char*)Buffer );
    */


    return 1;

}
Exemple #21
0
khm_boolean KHMAPI kcdb_type_string_isValid(
    const void * d,
    khm_size cbd)
{
    size_t cbsize;

    if(cbd == KCDB_CBSIZE_AUTO)
        cbd = KCDB_TYPE_MAXCB;

    if(FAILED(StringCbLength((wchar_t *) d, cbd, &cbsize)))
        return FALSE;
    else
        return TRUE;
}
Exemple #22
0
KHMEXP wchar_t *
perf_wcsdup(const char * file, int line, const wchar_t * str) {
    size_t cb;
    wchar_t * dest;

    if (FAILED(StringCbLength(str, MAXCB_STR, &cb)))
        return NULL;
    cb += sizeof(wchar_t);

    dest = (wchar_t *) perf_malloc(file, line, cb);
    StringCbCopy(dest, cb, str);

    return dest;
}
Exemple #23
0
KHMEXP khm_int32 KHMAPI kmq_register_type(wchar_t * name,
                                          khm_int32 * new_id)
{
    int i;
    khm_int32 rv = KHM_ERROR_SUCCESS;
    BOOL registered = FALSE;
    int first_free = 0;
    size_t sz;

    if(FAILED(StringCbLength(name, KMQ_MAXCB_TYPE_NAME, &sz)) ||
       sz == 0)
        return KHM_ERROR_INVALID_PARAM;
    sz += sizeof(wchar_t);

    EnterCriticalSection(&cs_kmq_types);
    for(i=KMSGBASE_USER; i <= KMQ_MSG_TYPE_MAX; i++) {
        if(msg_types[i] == NULL) {
            if(first_free == 0)
                first_free = i;
            /* continue searching since we might find that this type
               is already registered. */
        } else {
            if(msg_types[i]->name != NULL &&
               !wcscmp(msg_types[i]->name, name)) {

                registered = TRUE;
                if (new_id)
                    *new_id = i;
                break;
            }
        }
    }

    if(registered) {
        rv = KHM_ERROR_EXISTS;
    } else if(first_free == 0) {
        rv = KHM_ERROR_NO_RESOURCES;
    } else {
        kmqint_msg_type_create(first_free);
        msg_types[first_free]->name = PMALLOC(sz);
        StringCbCopy(msg_types[first_free]->name, sz, name);

        if(new_id != NULL)
            *new_id = first_free;
    }
    LeaveCriticalSection(&cs_kmq_types);

    return rv;
}
Exemple #24
0
kmm_plugin_i *
kmmint_find_plugin_i(wchar_t * name)
{
    kmm_plugin_i * p;
    size_t cb;

    if(FAILED(StringCbLength(name, KMM_MAXCB_NAME, &cb)))
        return NULL;

    EnterCriticalSection(&cs_kmm);
    p = (kmm_plugin_i *) hash_lookup(hash_plugins, (void *) name);
    LeaveCriticalSection(&cs_kmm);

    return p;
}
Exemple #25
0
/*****************************************************************************
DWORD WriteHashLine(CONST HANDLE hFile, CONST TCHAR szFilename[MAX_PATH_EX], CONST TCHAR szHashResult[RESULT_AS_STRING_MAX_LENGTH], BOOL bIsSfv)
	hFile		    : (IN) handle to an open file
	szFilename	    : (IN) string of the filename that we want to write into the hash file
	szHashResult	: (IN) string of the hash result
    bIsSfv          : (IN) is this a sfv hash

Return Value:
- returns NOERROR or GetLastError()
*****************************************************************************/
DWORD WriteHashLine(CONST HANDLE hFile, CONST TCHAR szFilename[MAX_PATH_EX], CONST TCHAR szHashResult[RESULT_AS_STRING_MAX_LENGTH], BOOL bIsSfv)
{
	TCHAR szFilenameTemp[MAX_PATH_EX];
	TCHAR szLine[MAX_LINE_LENGTH];
#ifdef UNICODE
	CHAR szLineAnsi[MAX_LINE_LENGTH];
#endif
	DWORD dwNumberOfBytesWritten;
	size_t stStringLength;
	VOID *szOutLine=szLine;

    if(!RegularFromLongFilename(szFilenameTemp, szFilename)) {
	    if(g_program_options.bCreateUnixStyle)
		    ReplaceChar(szFilenameTemp, MAX_PATH_EX, TEXT('\\'), TEXT('/'));
    }

    if(bIsSfv)
        StringCchPrintf(szLine, MAX_LINE_LENGTH, TEXT("%s %s%s"), szFilenameTemp,
		    szHashResult, g_program_options.bCreateUnixStyle ? TEXT("\n") : TEXT("\r\n"));
    else
        StringCchPrintf(szLine, MAX_LINE_LENGTH, TEXT("%s *%s%s"), szHashResult,
		    szFilenameTemp, g_program_options.bCreateUnixStyle ? TEXT("\n") : TEXT("\r\n"));

	StringCbLength(szLine, MAX_LINE_LENGTH, & stStringLength);

#ifdef UNICODE
    // we only need the conversion if we don't write unicode data
	if(!g_program_options.bCreateUnicodeFiles) {
		if(!WideCharToMultiByte(CP_ACP, 0, szLine, -1, szLineAnsi, MAX_UTF8_PATH, NULL, NULL) )
			return GetLastError();

		StringCbLengthA(szLineAnsi, MAX_LINE_LENGTH, & stStringLength);
		szOutLine=szLineAnsi;
    } else if(g_program_options.iUnicodeSaveType == UTF_8 || g_program_options.iUnicodeSaveType==UTF_8_BOM) {
		if(!WideCharToMultiByte(CP_UTF8, 0, szLine, -1, szLineAnsi, MAX_UTF8_PATH, NULL, NULL) )
			return GetLastError();

		StringCbLengthA(szLineAnsi, MAX_LINE_LENGTH, & stStringLength);
		szOutLine=szLineAnsi;
	}
#endif

	if(!WriteFile(hFile, szOutLine, (DWORD)stStringLength, & dwNumberOfBytesWritten, NULL) )
		return GetLastError();

	return NOERROR;
}
Exemple #26
0
void WriteStringToRegistry(_In_ HKEY hKey, _In_z_ LPCTSTR szValueName, _In_z_ LPCTSTR szValue)
{
    HRESULT hRes = S_OK;
    size_t cbValue = 0;

    // Reg needs bytes, so CB is correct here
    EC_H(StringCbLength(szValue,STRSAFE_MAX_CCH * sizeof(TCHAR),&cbValue));
    cbValue += sizeof(TCHAR); // NULL terminator

    WC_W32(RegSetValueEx(
               hKey,
               szValueName,
               NULL,
               REG_SZ,
               (LPBYTE) szValue,
               (DWORD) cbValue));
} // WriteStringToRegistry
Exemple #27
0
int ms_to_csv_test(void) {
  wchar_t wbuf[512];
  int i;
  khm_int32 code = 0;
  size_t cbbuf;
  size_t cbr;
  size_t cbnull;

  printf("khc_multi_string_to_csv() test:\n");

  for(i=0; i<n_strings; i++) {
    cbbuf = sizeof(wbuf);
    printf("Multi string:[");
    print_ms(strings[i].ms);
    printf("]->");
    code = khc_multi_string_to_csv(NULL, &cbnull, strings[i].ms);
    code = khc_multi_string_to_csv(wbuf, &cbbuf, strings[i].ms);
    if(code) {
      printf(" returned %d\n", code);
      return code;
    }
    printf("CSV[%S]", wbuf);
    if(wcscmp(wbuf, strings[i].csv)) {
      printf(" MISMATCH!");
      return 1;
    }

    StringCbLength(wbuf, sizeof(wbuf), &cbr);
    cbr+= sizeof(wchar_t);

    if(cbr != cbbuf) {
      printf(" Length mismatch");
      return 1;
    }

    if(cbnull != cbr) {
      printf(" NULL length mismatch");
      return 1;
    }

    printf("\n");
  }

  return code;
}
Exemple #28
0
BOOL CRegistry::WriteString(LPCTSTR pszValueName, LPCTSTR pszString)
{
	size_t cbData;

	ASSERT(m_hRoot);
	ASSERT(m_hCurrentKey);

	if (SUCCEEDED(StringCbLength(pszString, MAX_PATH, &cbData)))
	{
		if (::RegSetValueEx(m_hCurrentKey, (LPTSTR)pszValueName, 0, REG_SZ,
			(CONST BYTE *) pszString, (DWORD)cbData) != ERROR_SUCCESS)
		{
			REGISTRY_ERROR;
			return FALSE;
		}
	}
	return TRUE;
}
Exemple #29
0
KHMEXP khm_int32 KHMAPI kcdb_credtype_describe(
    khm_int32 id,
    wchar_t * buf,
    khm_size * cbbuf,
    khm_int32 flags)
{
    size_t s;
    size_t maxs;
    wchar_t * str;
    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) {
        if(flags & KCDB_TS_SHORT) {
            str = (t->ct.short_desc)?t->ct.short_desc:t->ct.name;
            maxs = (t->ct.short_desc)?KCDB_MAXCB_SHORT_DESC:KCDB_MAXCB_NAME;
        } else {
            str = (t->ct.long_desc)?t->ct.long_desc:((t->ct.short_desc)?t->ct.short_desc:t->ct.name);
            maxs = (t->ct.long_desc)?KCDB_MAXCB_LONG_DESC:((t->ct.short_desc)?KCDB_MAXCB_SHORT_DESC:KCDB_MAXCB_NAME);
        }
        StringCbLength(str, maxs, &s);
        s += sizeof(wchar_t);
        if(!buf || *cbbuf < s) {
            *cbbuf = s;
            rv = KHM_ERROR_TOO_LONG;
        } else {
            StringCbCopy(buf, *cbbuf, str);
            *cbbuf = s;
        }
    } else {
        if(buf && *cbbuf > 0)
            *buf = L'\0';
        *cbbuf = 0;
        rv = KHM_ERROR_NOT_FOUND;
    }
    LeaveCriticalSection(&cs_credtype);

    return rv;
}
Exemple #30
0
KHMEXP khm_int32 KHMAPI
khui_cfg_open(khui_config_node vparent,
              const wchar_t * name,
              khui_config_node * result) {
    khui_config_node_i * parent;
    khui_config_node_i * c;
    size_t sz;

    cfgui_init_once();

    if ((vparent &&
         !cfgui_is_valid_node_handle(vparent)) ||
        FAILED(StringCbLength(name, KHUI_MAXCCH_NAME, &sz)) ||
        !result)
        return KHM_ERROR_INVALID_PARAM;

    EnterCriticalSection(&cs_cfgui);
    if (vparent)
        parent = cfgui_node_i_from_handle(vparent);
    else
        parent = cfgui_root_config;

    c = TFIRSTCHILD(parent);
    while(c) {
        if (!(c->flags & KHUI_CN_FLAG_DELETED) &&
            !wcscmp(c->reg.name, name))
            break;
        c = LNEXT(c);
    }

    if (c) {
        *result = cfgui_handle_from_node_i(c);
        cfgui_hold_node(c);
    } else {
        *result = NULL;
    }
    LeaveCriticalSection(&cs_cfgui);

    if (*result)
        return KHM_ERROR_SUCCESS;
    else
        return KHM_ERROR_NOT_FOUND;
}