diff --git a/dll/win32/imm32/CMakeLists.txt b/dll/win32/imm32/CMakeLists.txt index e4dff4ee9da..269d42486a9 100644 --- a/dll/win32/imm32/CMakeLists.txt +++ b/dll/win32/imm32/CMakeLists.txt @@ -27,6 +27,6 @@ add_rc_deps(imm32.rc ${imm32_rc_deps}) add_library(imm32 MODULE ${SOURCE} imm32.rc) set_module_type(imm32 win32dll UNICODE ENTRYPOINT ImmDllInitialize 12) -target_link_libraries(imm32 wine win32ksys uuid) +target_link_libraries(imm32 wine2ros win32ksys uuid) add_importlibs(imm32 advapi32 user32 gdi32 kernel32 ntdll) add_cd_file(TARGET imm32 DESTINATION reactos/system32 FOR all) diff --git a/dll/win32/imm32/debug.h b/dll/win32/imm32/debug.h deleted file mode 100644 index c77d0937c61..00000000000 --- a/dll/win32/imm32/debug.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * PROJECT: ReactOS IMM32 - * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) - * PURPOSE: Debugging IMM32 - * COPYRIGHT: Copyright 2025 Katayama Hirofumi MZ - */ - -#pragma once - -typedef enum tagDEBUGCHANNEL -{ - DbgChimm = 0, -} DEBUGCHANNEL; - -#if DBG - #ifndef __RELFILE__ - #define __RELFILE__ __FILE__ - #endif - - #define ERR_LEVEL 0x1 - #define TRACE_LEVEL 0x8 - - #define WINE_DEFAULT_DEBUG_CHANNEL(x) static int DbgDefaultChannel = DbgCh##x; - #define DBG_IS_CHANNEL_ENABLED(ch) Imm32IsDebugChannelEnabled(ch) - - #define DBG_PRINT(ch, level, tag, fmt, ...) (void)( \ - (((level) == ERR_LEVEL) || DBG_IS_CHANNEL_ENABLED(ch)) ? \ - (DbgPrint("(%s:%d) %s" fmt, __RELFILE__, __LINE__, (tag), ##__VA_ARGS__), FALSE) : TRUE \ - ) - - #define ERR(fmt, ...) DBG_PRINT(DbgDefaultChannel, ERR_LEVEL, "err: ", fmt, ##__VA_ARGS__) - #define WARN(fmt, ...) DBG_PRINT(DbgDefaultChannel, ERR_LEVEL, "warn: ", fmt, ##__VA_ARGS__) - #define FIXME(fmt, ...) DBG_PRINT(DbgDefaultChannel, ERR_LEVEL, "fixme: ", fmt, ##__VA_ARGS__) - #define TRACE(fmt, ...) DBG_PRINT(DbgDefaultChannel, TRACE_LEVEL, "", fmt, ##__VA_ARGS__) -#else - #define WINE_DEFAULT_DEBUG_CHANNEL(x) - #define DBG_IS_CHANNEL_ENABLED(ch,level) - #define DBG_PRINT(ch,level) - #define ERR(fmt, ...) - #define WARN(fmt, ...) - #define FIXME(fmt, ...) - #define TRACE(fmt, ...) -#endif - -#if DBG -static inline BOOL -Imm32IsDebugChannelEnabled(DEBUGCHANNEL channel) -{ - CHAR szValue[MAX_PATH], *pch0, *pch; - - if (!GetEnvironmentVariableA("DEBUGCHANNEL", szValue, _countof(szValue))) - return FALSE; - - for (pch0 = szValue;; pch0 = pch + 1) - { - pch = strchr(pch0, ','); - if (pch) - *pch = ANSI_NULL; - if (channel == DbgChimm && _stricmp(pch0, "imm") == 0) - return TRUE; - if (!pch) - return FALSE; - } -} -#endif - -/* #define UNEXPECTED() (ASSERT(FALSE), TRUE) */ -#define UNEXPECTED() TRUE - -/* Unexpected Condition Checkers */ -#if DBG - #define FAILED_UNEXPECTEDLY(hr) \ - (FAILED(hr) ? (ERR("FAILED(0x%08X)\n", hr), UNEXPECTED()) : FALSE) - #define IS_NULL_UNEXPECTEDLY(p) \ - (!(p) ? (ERR("%s was NULL\n", #p), UNEXPECTED()) : FALSE) - #define IS_ZERO_UNEXPECTEDLY(p) \ - (!(p) ? (ERR("%s was zero\n", #p), UNEXPECTED()) : FALSE) - #define IS_TRUE_UNEXPECTEDLY(x) \ - ((x) ? (ERR("%s was %d\n", #x, (int)(x)), UNEXPECTED()) : FALSE) - #define IS_ERROR_UNEXPECTEDLY(x) \ - ((x) != ERROR_SUCCESS ? (ERR("%s was %d\n", #x, (int)(x)), UNEXPECTED()) : FALSE) -#else - #define FAILED_UNEXPECTEDLY(hr) FAILED(hr) - #define IS_NULL_UNEXPECTEDLY(p) (!(p)) - #define IS_ZERO_UNEXPECTEDLY(p) (!(p)) - #define IS_TRUE_UNEXPECTEDLY(x) (x) - #define IS_ERROR_UNEXPECTEDLY(x) ((x) != ERROR_SUCCESS) -#endif - -#define IS_CROSS_THREAD_HIMC(hIMC) IS_TRUE_UNEXPECTEDLY(Imm32IsCrossThreadAccess(hIMC)) -#define IS_CROSS_PROCESS_HWND(hWnd) IS_TRUE_UNEXPECTEDLY(Imm32IsCrossProcessAccess(hWnd)) diff --git a/dll/win32/imm32/precomp.h b/dll/win32/imm32/precomp.h index d887d8a9f38..ee9fa237b6b 100644 --- a/dll/win32/imm32/precomp.h +++ b/dll/win32/imm32/precomp.h @@ -44,7 +44,33 @@ #include -#include "debug.h" +#include + +/* #define UNEXPECTED() (ASSERT(FALSE), TRUE) */ +#define UNEXPECTED() TRUE + +/* Unexpected Condition Checkers */ +#if DBG + #define FAILED_UNEXPECTEDLY(hr) \ + (FAILED(hr) ? (ERR("FAILED(0x%08X)\n", hr), UNEXPECTED()) : FALSE) + #define IS_NULL_UNEXPECTEDLY(p) \ + (!(p) ? (ERR("%s was NULL\n", #p), UNEXPECTED()) : FALSE) + #define IS_ZERO_UNEXPECTEDLY(p) \ + (!(p) ? (ERR("%s was zero\n", #p), UNEXPECTED()) : FALSE) + #define IS_TRUE_UNEXPECTEDLY(x) \ + ((x) ? (ERR("%s was %d\n", #x, (int)(x)), UNEXPECTED()) : FALSE) + #define IS_ERROR_UNEXPECTEDLY(x) \ + ((x) != ERROR_SUCCESS ? (ERR("%s was %d\n", #x, (int)(x)), UNEXPECTED()) : FALSE) +#else + #define FAILED_UNEXPECTEDLY(hr) FAILED(hr) + #define IS_NULL_UNEXPECTEDLY(p) (!(p)) + #define IS_ZERO_UNEXPECTEDLY(p) (!(p)) + #define IS_TRUE_UNEXPECTEDLY(x) (x) + #define IS_ERROR_UNEXPECTEDLY(x) ((x) != ERROR_SUCCESS) +#endif + +#define IS_CROSS_THREAD_HIMC(hIMC) IS_TRUE_UNEXPECTEDLY(Imm32IsCrossThreadAccess(hIMC)) +#define IS_CROSS_PROCESS_HWND(hWnd) IS_TRUE_UNEXPECTEDLY(Imm32IsCrossProcessAccess(hWnd)) #define IMM_INIT_MAGIC 0x19650412 #define IMM_INVALID_CANDFORM ULONG_MAX diff --git a/dll/win32/netapi32/CMakeLists.txt b/dll/win32/netapi32/CMakeLists.txt index 0c0c08744f1..f0a675abd69 100644 --- a/dll/win32/netapi32/CMakeLists.txt +++ b/dll/win32/netapi32/CMakeLists.txt @@ -1,9 +1,7 @@ include_directories( - ${REACTOS_SOURCE_DIR}/sdk/include/reactos/idl - ${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine) + ${REACTOS_SOURCE_DIR}/sdk/include/reactos/idl) -add_definitions(-D__WINESRC__) spec2def(netapi32.dll netapi32.spec ADD_IMPORTLIB) add_rpc_files(client ${REACTOS_SOURCE_DIR}/sdk/include/reactos/idl/atsvc.idl @@ -53,7 +51,7 @@ add_library(netapi32 MODULE ${CMAKE_CURRENT_BINARY_DIR}/netapi32.def) set_module_type(netapi32 win32dll) -target_link_libraries(netapi32 wine ${PSEH_LIB}) +target_link_libraries(netapi32 wine2ros ${PSEH_LIB}) add_delay_importlibs(netapi32 samlib secur32) add_importlibs(netapi32 iphlpapi ws2_32 advapi32 rpcrt4 msvcrt kernel32 ntdll) add_pch(netapi32 netapi32.h "${PCH_SKIP_SOURCE}") diff --git a/dll/win32/netapi32/netapi32.h b/dll/win32/netapi32/netapi32.h index 4f4bcb63a43..4030d91e823 100644 --- a/dll/win32/netapi32/netapi32.h +++ b/dll/win32/netapi32/netapi32.h @@ -1,7 +1,9 @@ #ifndef __WINE_NETAPI32_H__ #define __WINE_NETAPI32_H__ +#ifndef __REACTOS__ #include +#endif #include #include @@ -19,8 +21,12 @@ #include #include +#ifdef __REACTOS__ +#include +#else #include #include +#endif #define NTOS_MODE_USER #include diff --git a/sdk/lib/CMakeLists.txt b/sdk/lib/CMakeLists.txt index e3344d8c621..e639ca3ca58 100644 --- a/sdk/lib/CMakeLists.txt +++ b/sdk/lib/CMakeLists.txt @@ -56,6 +56,7 @@ add_subdirectory(ucrt) add_subdirectory(udmihelp) add_subdirectory(uuid) add_subdirectory(vcruntime) +add_subdirectory(wine2ros) add_subdirectory(wdmguid) else() diff --git a/sdk/lib/wine2ros/CMakeLists.txt b/sdk/lib/wine2ros/CMakeLists.txt new file mode 100644 index 00000000000..93b88f1d602 --- /dev/null +++ b/sdk/lib/wine2ros/CMakeLists.txt @@ -0,0 +1,7 @@ + +list(APPEND SOURCE + wine2ros.c +) +add_library(wine2ros STATIC ${SOURCE}) +add_dependencies(wine2ros psdk) +target_include_directories(wine2ros INTERFACE ${REACTOS_SOURCE_DIR}/sdk/lib/wine2ros) diff --git a/sdk/lib/wine2ros/wine2ros.c b/sdk/lib/wine2ros/wine2ros.c new file mode 100644 index 00000000000..067ef5d86a4 --- /dev/null +++ b/sdk/lib/wine2ros/wine2ros.c @@ -0,0 +1,235 @@ +/* + * PROJECT: ReactOS Wine-To-ReactOS + * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) + * PURPOSE: Reducing dependency on Wine + * COPYRIGHT: Copyright 2025 Katayama Hirofumi MZ + */ + +#if DBG + +#include +#include +#include +#include +#include "wine2ros.h" + +BOOL +IntIsDebugChannelEnabled(_In_ PCSTR channel) +{ + CHAR szValue[MAX_PATH]; + PCHAR pch0, pch1; + BOOL ret; + DWORD error; + + error = GetLastError(); + ret = GetEnvironmentVariableA("DEBUGCHANNEL", szValue, _countof(szValue)); + SetLastError(error); + + if (!ret) + return FALSE; + + for (pch0 = szValue;; pch0 = pch1 + 1) + { + pch1 = strchr(pch0, ','); + if (pch1) + *pch1 = ANSI_NULL; + if (_stricmp(pch0, channel) == 0) + return TRUE; + if (!pch1) + return FALSE; + } +} + +#define DEBUGSTR_HEX "0123456789ABCDEF" +#define DEBUGSTR_QUOTE_TAIL_LEN 8 + +static PSTR +debugstr_quote_a( + _Out_ PSTR pszBuf, + _In_ SIZE_T cchBuf, + _In_opt_ PCSTR pszSrc) +{ + PCH pch = pszBuf; + PCCH pchSrc = pszSrc; + + if (!pszSrc) + return "(null)"; + + if (!((ULONG_PTR)pszSrc >> 16)) + { + snprintf(pszBuf, cchBuf, "%p", pszSrc); + return pszBuf; + } + + *pch++ = '"'; + --cchBuf; + + for (; cchBuf > DEBUGSTR_QUOTE_TAIL_LEN; ++pchSrc) + { + switch (*pchSrc) + { + case '\'': case '\"': case '\\': case '\t': case '\r': case '\n': + *pch++ = '\\'; + if (*pchSrc == '\t') + *pch++ = 't'; + else if (*pchSrc == '\r') + *pch++ = 'r'; + else if (*pchSrc == '\n') + *pch++ = 'n'; + else + *pch++ = *pchSrc; + cchBuf -= 2; + break; + default: + { + if (*pchSrc >= ' ') + { + *pch++ = *pchSrc; + --cchBuf; + } + else + { + *pch++ = '\\'; + *pch++ = 'x'; + *pch++ = DEBUGSTR_HEX[(*pchSrc >> 4) & 0xF]; + *pch++ = DEBUGSTR_HEX[*pchSrc & 0xF]; + cchBuf -= 4; + } + break; + } + } + } + + if (cchBuf <= DEBUGSTR_QUOTE_TAIL_LEN) + { + *pch++ = '.'; + *pch++ = '.'; + *pch++ = '.'; + } + *pch++ = '"'; + *pch = ANSI_NULL; + return pszBuf; +} + +static PSTR +debugstr_quote_w( + _Out_ PSTR pszBuf, + _In_ SIZE_T cchBuf, + _In_opt_ PCWSTR pszSrc) +{ + PCH pch = pszBuf; + PCWCH pchSrc = pszSrc; + + if (!pszSrc) + return "(null)"; + + if (!((ULONG_PTR)pszSrc >> 16)) + { + snprintf(pszBuf, cchBuf, "%p", pszSrc); + return pszBuf; + } + + *pch++ = '"'; + --cchBuf; + + for (; cchBuf > DEBUGSTR_QUOTE_TAIL_LEN; ++pchSrc) + { + switch (*pchSrc) + { + case L'\'': case L'\"': case L'\\': case L'\t': case L'\r': case L'\n': + *pch++ = '\\'; + if (*pchSrc == L'\t') + *pch++ = 't'; + else if (*pchSrc == L'\r') + *pch++ = 'r'; + else if (*pchSrc == L'\n') + *pch++ = 'n'; + else + *pch++ = *pchSrc; + cchBuf -= 2; + break; + default: + { + if (*pchSrc >= L' ' && *pchSrc < 0x100) + { + *pch++ = (CHAR)*pchSrc; + --cchBuf; + } + else + { + *pch++ = '\\'; + *pch++ = 'x'; + *pch++ = DEBUGSTR_HEX[(*pchSrc >> 12) & 0xF]; + *pch++ = DEBUGSTR_HEX[(*pchSrc >> 8) & 0xF]; + *pch++ = DEBUGSTR_HEX[(*pchSrc >> 4) & 0xF]; + *pch++ = DEBUGSTR_HEX[*pchSrc & 0xF]; + cchBuf -= 6; + } + break; + } + } + } + + if (cchBuf <= DEBUGSTR_QUOTE_TAIL_LEN) + { + *pch++ = '.'; + *pch++ = '.'; + *pch++ = '.'; + } + *pch++ = '"'; + *pch = ANSI_NULL; + return pszBuf; +} + +#define DEBUGSTR_NUM_BUFFS 5 +#define DEBUGSTR_BUFF_SIZE MAX_PATH + +static LPSTR +debugstr_next_buff(void) +{ + static CHAR s_bufs[DEBUGSTR_NUM_BUFFS][DEBUGSTR_BUFF_SIZE]; + static SIZE_T s_index = 0; + PCHAR ptr = s_bufs[s_index]; + s_index = (s_index + 1) % _countof(s_bufs); + return ptr; +} + +PCSTR +debugstr_a(_In_opt_ PCSTR pszA) +{ + return debugstr_quote_a(debugstr_next_buff(), DEBUGSTR_BUFF_SIZE, pszA); +} + +PCSTR +debugstr_w(_In_opt_ PCWSTR pszW) +{ + return debugstr_quote_w(debugstr_next_buff(), DEBUGSTR_BUFF_SIZE, pszW); +} + +PCSTR +debugstr_guid(_In_opt_ const GUID *id) +{ + PCHAR ptr; + + if (!id) + return "(null)"; + + ptr = debugstr_next_buff(); + + if (!((ULONG_PTR)id >> 16)) + { + snprintf(ptr, DEBUGSTR_BUFF_SIZE, "%p", id); + } + else + { + snprintf(ptr, DEBUGSTR_BUFF_SIZE, + "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", + id->Data1, id->Data2, id->Data3, + id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3], + id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7]); + } + + return ptr; +} + +#endif /* DBG */ diff --git a/sdk/lib/wine2ros/wine2ros.h b/sdk/lib/wine2ros/wine2ros.h new file mode 100644 index 00000000000..8ee36f2fee4 --- /dev/null +++ b/sdk/lib/wine2ros/wine2ros.h @@ -0,0 +1,88 @@ +/* + * PROJECT: ReactOS Wine-To-ReactOS + * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) + * PURPOSE: Reducing dependency on Wine + * COPYRIGHT: Copyright 2025 Katayama Hirofumi MZ + */ + +#pragma once + +/* */ +#if DBG + #ifndef __RELFILE__ + #define __RELFILE__ __FILE__ + #endif + + #define ERR_LEVEL 0x1 + #define TRACE_LEVEL 0x8 + + #define WINE_DEFAULT_DEBUG_CHANNEL(x) static PCSTR DbgDefaultChannel = #x; + + BOOL IntIsDebugChannelEnabled(_In_ PCSTR channel); + + #define DBG_PRINT(ch, level, tag, fmt, ...) (void)( \ + (((level) == ERR_LEVEL) || IntIsDebugChannelEnabled(ch)) ? \ + (DbgPrint("(%s:%d) %s" fmt, __RELFILE__, __LINE__, (tag), ##__VA_ARGS__), FALSE) : TRUE \ + ) + + #define ERR(fmt, ...) DBG_PRINT(DbgDefaultChannel, ERR_LEVEL, "err: ", fmt, ##__VA_ARGS__) + #define WARN(fmt, ...) DBG_PRINT(DbgDefaultChannel, ERR_LEVEL, "warn: ", fmt, ##__VA_ARGS__) + #define FIXME(fmt, ...) DBG_PRINT(DbgDefaultChannel, ERR_LEVEL, "fixme: ", fmt, ##__VA_ARGS__) + #define TRACE(fmt, ...) DBG_PRINT(DbgDefaultChannel, TRACE_LEVEL, "", fmt, ##__VA_ARGS__) + + #define UNIMPLEMENTED FIXME("%s is unimplemented", __FUNCTION__); + + PCSTR debugstr_a(_In_opt_ PCSTR pszA); + PCSTR debugstr_w(_In_opt_ PCWSTR pszW); + PCSTR debugstr_guid(_In_opt_ const GUID *id); +#else + #define WINE_DEFAULT_DEBUG_CHANNEL(x) + #define IntIsDebugChannelEnabled(channel) FALSE + #define DBG_PRINT(ch, level) + #define ERR(fmt, ...) + #define WARN(fmt, ...) + #define FIXME(fmt, ...) + #define TRACE(fmt, ...) + #define UNIMPLEMENTED + #define debugstr_a(pszA) ((PCSTR)NULL) + #define debugstr_w(pszW) ((PCSTR)NULL) + #define debugstr_guid(id) ((PCSTR)NULL) +#endif + +/* */ +#define memicmpW(s1,s2,n) _wcsnicmp((s1),(s2),(n)) +#define strlenW(s) wcslen((s)) +#define strcpyW(d,s) wcscpy((d),(s)) +#define strcatW(d,s) wcscat((d),(s)) +#define strcspnW(d,s) wcscspn((d),(s)) +#define strstrW(d,s) wcsstr((d),(s)) +#define strtolW(s,e,b) wcstol((s),(e),(b)) +#define strchrW(s,c) wcschr((s),(c)) +#define strrchrW(s,c) wcsrchr((s),(c)) +#define strncmpW(s1,s2,n) wcsncmp((s1),(s2),(n)) +#define strncpyW(s1,s2,n) wcsncpy((s1),(s2),(n)) +#define strcmpW(s1,s2) wcscmp((s1),(s2)) +#define strcmpiW(s1,s2) _wcsicmp((s1),(s2)) +#define strncmpiW(s1,s2,n) _wcsnicmp((s1),(s2),(n)) +#define strtoulW(s1,s2,b) wcstoul((s1),(s2),(b)) +#define strspnW(str, accept) wcsspn((str),(accept)) +#define strpbrkW(str, accept) wcspbrk((str),(accept)) +#define tolowerW(n) towlower((n)) +#define toupperW(n) towupper((n)) +#define islowerW(n) iswlower((n)) +#define isupperW(n) iswupper((n)) +#define isalphaW(n) iswalpha((n)) +#define isalnumW(n) iswalnum((n)) +#define isdigitW(n) iswdigit((n)) +#define isxdigitW(n) iswxdigit((n)) +#define isspaceW(n) iswspace((n)) +#define iscntrlW(n) iswcntrl((n)) +#define atoiW(s) _wtoi((s)) +#define atolW(s) _wtol((s)) +#define strlwrW(s) _wcslwr((s)) +#define struprW(s) _wcsupr((s)) +#define sprintfW _swprintf +#define vsprintfW _vswprintf +#define snprintfW _snwprintf +#define vsnprintfW _vsnwprintf +#define isprintW iswprint