decklink: Implement Windows string conversion with common API between MinGW and MSVC

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4738>
This commit is contained in:
Sebastian Dröge 2023-06-01 15:16:47 +03:00 committed by Sebastian Dröge
parent ab582a3b7d
commit f1e7ac13cd

View file

@ -32,20 +32,26 @@
#include "win/DeckLinkAPI.h"
#include <stdio.h>
#include <comutil.h>
#define bool BOOL
#define COMSTR_T BSTR
/* MinGW does not have comsuppw.lib, so no _com_util::ConvertBSTRToString */
# ifdef __MINGW32__
# define CONVERT_COM_STRING(s) G_STMT_START { BSTR _s = (BSTR)s; s = (char*) malloc(100); wcstombs(s, _s, 100); ::SysFreeString(_s); } G_STMT_END
# define FREE_COM_STRING(s) free(s);
# define CONVERT_TO_COM_STRING(s) G_STMT_START { char * _s = (char *)s; s = (BSTR) malloc(100); mbstowcs(s, _s, 100); g_free(_s); } G_STMT_END
# else
# define CONVERT_COM_STRING(s) G_STMT_START { BSTR _s = (BSTR)s; s = _com_util::ConvertBSTRToString(_s); ::SysFreeString(_s); } G_STMT_END
# define FREE_COM_STRING(s) G_STMT_START { delete[] s; } G_STMT_END
# define CONVERT_TO_COM_STRING(s) G_STMT_START { char * _s = (char *)s; s = _com_util::ConvertStringToBSTR(_s); g_free(_s); } G_STMT_END
# endif /* __MINGW32__ */
#define CONVERT_COM_STRING(s) G_STMT_START { \
BSTR _s = (BSTR)s; \
int _s_length = ::SysStringLen(_s); \
int _length = ::WideCharToMultiByte(CP_ACP, 0, (wchar_t*)_s, _s_length, NULL, 0, NULL, NULL); \
s = (char *) malloc(_length); \
::WideCharToMultiByte(CP_ACP, 0, (wchar_t*)_s, _s_length, s, _length, NULL, NULL); \
::SysFreeString(_s); \
} G_STMT_END
#define FREE_COM_STRING(s) free(s);
#define CONVERT_TO_COM_STRING(s) G_STMT_START { \
char * _s = (char *)s; \
int _s_length = strlen((char*)_s); \
int _length = ::MultiByteToWideChar(CP_ACP, 0, (char*)_s, _s_length, NULL, 0); \
s = ::SysAllocStringLen(NULL, _length); \
::MultiByteToWideChar(CP_ACP, 0, (char*)_s, _s_length, s, _length); \
g_free(_s); \
} G_STMT_END
#elif defined(__APPLE__)
#include "osx/DeckLinkAPI.h"