⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 conv.cpp

📁 一个解压程序,只要设定了解压路径和解压文件的种类,就可以随意解压
💻 CPP
字号:
#include <windows.h>
#include "conv.h"

typedef BOOL (*PFN_INIT_KANJI_CONTROLS)();
typedef void (*PFN_RELEASE_KANJI_CONTROLS)();
typedef DWORD (*PFN_UNICODE2SJIS)(LPCTSTR, BYTE*, DWORD);
typedef DWORD (*PFN_SJIS2UNICODE)(const BYTE*, LPTSTR, DWORD);

static HINSTANCE g_hInstKctrl = 0;
PFN_UNICODE2SJIS g_pfnunicode2sjis = 0;
PFN_SJIS2UNICODE g_pfnsjis2unicode = 0;

extern "C" void KctrlInit()
{
	WCHAR sz[2];
	::MultiByteToWideChar(932, 0, " ", 1, sz, sizeof(sz)/sizeof(sz[0]));
	if (wcscmp(sz, L" ") == 0)
		return;
	
	g_hInstKctrl = ::LoadLibrary(L"kctrl.dll");
	if (g_hInstKctrl) {
		PFN_INIT_KANJI_CONTROLS pfnInit = reinterpret_cast<PFN_INIT_KANJI_CONTROLS>(::GetProcAddress(g_hInstKctrl, L"InitKanjiControls"));
		if (!pfnInit || !(*pfnInit)()) {
			::FreeLibrary(g_hInstKctrl);
			g_hInstKctrl = 0;
		}
		g_pfnunicode2sjis = reinterpret_cast<PFN_UNICODE2SJIS>(::GetProcAddress(g_hInstKctrl, L"unicode2sjis"));
		g_pfnsjis2unicode = reinterpret_cast<PFN_SJIS2UNICODE>(::GetProcAddress(g_hInstKctrl, L"sjis2unicode"));
	}
}

extern "C" void KctrlTerm()
{
	if (g_hInstKctrl) {
		PFN_RELEASE_KANJI_CONTROLS pfnRelease = reinterpret_cast<PFN_RELEASE_KANJI_CONTROLS>(::GetProcAddress(g_hInstKctrl, L"ReleaseKanjiControls"));
		if (pfnRelease)
			(*pfnRelease)();
		::FreeLibrary(g_hInstKctrl);
	}
}

extern "C" int _WideCharToMultiByte(UINT CodePage, DWORD dwFlags,
	LPCWSTR lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr,
	int cchMultiByte, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar)
{
	if (g_hInstKctrl) {
		int nLen = 0;
		LPCWSTR pWideChar = lpWideCharStr;
		LPWSTR pWideCharAlloc = 0;
		
		if (cchWideChar != -1 && lpWideCharStr[cchWideChar]) {
			pWideCharAlloc = static_cast<LPWSTR>(malloc((cchWideChar + 1)*sizeof(WCHAR)));
			wcsncpy(pWideCharAlloc, lpWideCharStr, cchWideChar);
			pWideCharAlloc[cchWideChar] = L'\0';
			pWideChar = pWideCharAlloc;
		}
		
		nLen = (*g_pfnunicode2sjis)(pWideChar, reinterpret_cast<BYTE*>(lpMultiByteStr), cchMultiByte);
		free(pWideCharAlloc);
		
		return nLen;
	}
	else {
		return WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr,
			cchWideChar, lpMultiByteStr, cchMultiByte, lpDefaultChar, lpUsedDefaultChar);
	}
}

extern "C" int _MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr,
	int cchMultiByte, LPWSTR lpWideCharStr, int cchWideChar)
{
	if (g_hInstKctrl) {
		int nLen = 0;
		LPCSTR pMultiByte = lpMultiByteStr;
		LPSTR pMultiByteAlloc = 0;
		
		if (cchMultiByte != -1 && lpMultiByteStr[cchMultiByte]) {
			pMultiByteAlloc = static_cast<LPSTR>(malloc(cchMultiByte + 1));
			strncpy(pMultiByteAlloc, lpMultiByteStr, cchMultiByte);
			pMultiByteAlloc[cchMultiByte] = '\0';
			pMultiByte = pMultiByteAlloc;
		}
		
		nLen = (*g_pfnsjis2unicode)(reinterpret_cast<const BYTE*>(pMultiByte),
			lpWideCharStr, cchWideChar*sizeof(WCHAR))/sizeof(WCHAR);
		
		free(pMultiByteAlloc);
		
		return nLen;
	}
	else {
		return MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr,
			cchMultiByte, lpWideCharStr, cchWideChar);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -