Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/LAVFilters.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorHendrik Leppkes <h.leppkes@gmail.com>2014-05-12 18:22:41 +0400
committerHendrik Leppkes <h.leppkes@gmail.com>2014-05-12 18:26:57 +0400
commit465bd2f3a2f951885c2fc816c062c24ae1c0322c (patch)
tree8bd0621d2d4bf6a3695ef452aa7d4f5b13090a6f /common
parentd62e83d6a4144f5d407f847d8032f4151bcf409b (diff)
Add helper functions for safe unicode transformations.
Diffstat (limited to 'common')
-rw-r--r--common/DSUtilLite/DShowUtil.cpp42
-rw-r--r--common/DSUtilLite/DShowUtil.h5
2 files changed, 47 insertions, 0 deletions
diff --git a/common/DSUtilLite/DShowUtil.cpp b/common/DSUtilLite/DShowUtil.cpp
index 01cac86d..b69f70a2 100644
--- a/common/DSUtilLite/DShowUtil.cpp
+++ b/common/DSUtilLite/DShowUtil.cpp
@@ -185,6 +185,48 @@ std::wstring WStringFromGUID(const GUID& guid)
return std::wstring(StringFromGUID2(guid, buff, 127) > 0 ? buff : null);
}
+int SafeMultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar)
+{
+ int len = MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, lpWideCharStr, cchWideChar);
+ if (len == cchWideChar) {
+ lpWideCharStr[len - 1] = 0;
+ }
+ return len;
+}
+
+int SafeWideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar)
+{
+ int len = WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, lpMultiByteStr, cbMultiByte, lpDefaultChar, lpUsedDefaultChar);
+ if (len == cbMultiByte) {
+ lpMultiByteStr[len - 1] = 0;
+ }
+ return len;
+}
+
+LPWSTR CoTaskGetWideCharFromMultiByte(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cbMultiByte)
+{
+ int len = MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, nullptr, 0);
+ if (len) {
+ LPWSTR pszWideString = (LPWSTR)CoTaskMemAlloc(len * sizeof(WCHAR));
+ MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, pszWideString, len);
+
+ return pszWideString;
+ }
+ return NULL;
+}
+
+LPSTR CoTaskGetMultiByteFromWideChar(UINT CodePage, DWORD dwFlags, LPCWSTR lpMultiByteStr, int cbMultiByte)
+{
+ int len = WideCharToMultiByte(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, nullptr, 0, nullptr, nullptr);
+ if (len) {
+ LPSTR pszMBString = (LPSTR)CoTaskMemAlloc(len * sizeof(char));
+ WideCharToMultiByte(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, pszMBString, len, nullptr, nullptr);
+
+ return pszMBString;
+ }
+ return NULL;
+}
+
BSTR ConvertCharToBSTR(const char *sz)
{
bool acp = false;
diff --git a/common/DSUtilLite/DShowUtil.h b/common/DSUtilLite/DShowUtil.h
index 14063d77..fca55d20 100644
--- a/common/DSUtilLite/DShowUtil.h
+++ b/common/DSUtilLite/DShowUtil.h
@@ -117,6 +117,11 @@ extern BOOL HasSourceWithType(IPin *pPin, const GUID &mediaType);
std::wstring WStringFromGUID(const GUID& guid);
BSTR ConvertCharToBSTR(const char *sz);
+int SafeMultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar);
+int SafeWideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar);
+LPWSTR CoTaskGetWideCharFromMultiByte(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cbMultiByte);
+LPSTR CoTaskGetMultiByteFromWideChar(UINT CodePage, DWORD dwFlags, LPCWSTR lpMultiByteStr, int cbMultiByte);
+
unsigned int lav_xiphlacing(unsigned char *s, unsigned int v);
void videoFormatTypeHandler(const AM_MEDIA_TYPE &mt, BITMAPINFOHEADER **pBMI = nullptr, REFERENCE_TIME *prtAvgTime = nullptr, DWORD *pDwAspectX = nullptr, DWORD *pDwAspectY = nullptr);