OSDN Git Service

Add support for process protection (prevents from loading untrustworthy DLLs with...
[ffftp/ffftp.git] / mbswrapper.h
1 // mbswrapper.h
2 // Copyright (C) 2011 Suguru Kawamoto
3 // マルチバイト文字ワイド文字APIラッパー
4
5 #ifndef __MBSWRAPPER_H__
6 #define __MBSWRAPPER_H__
7
8 #include <stdio.h>
9 #include <windows.h>
10 #include <shlobj.h>
11
12 #ifndef DO_NOT_REPLACE
13
14 #undef WinMain
15 #define WinMain WinMainM
16 int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow);
17 #undef LoadLibrary
18 #define LoadLibrary LoadLibraryM
19 HMODULE LoadLibraryM(LPCSTR lpLibFileName);
20 #undef CreateFile
21 #define CreateFile CreateFileM
22 HANDLE CreateFileM(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
23 #undef MessageBox
24 #define MessageBox MessageBoxM
25 int MessageBoxM(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType);
26 #undef FindFirstFile
27 #define FindFirstFile FindFirstFileM
28 HANDLE FindFirstFileM(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData);
29 #undef FindNextFile
30 #define FindNextFile FindNextFileM
31 BOOL FindNextFileM(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData);
32 #undef GetLogicalDriveStrings
33 #define GetLogicalDriveStrings GetLogicalDriveStringsM
34 DWORD GetLogicalDriveStringsM(DWORD nBufferLength, LPSTR lpBuffer);
35 #undef RegisterClassEx
36 #define RegisterClassEx RegisterClassExM
37 ATOM RegisterClassExM(CONST WNDCLASSEXA * v0);
38 #undef CreateWindowEx
39 #define CreateWindowEx CreateWindowExM
40 HWND CreateWindowExM(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);
41 #undef GetWindowLong
42 #define GetWindowLong GetWindowLongM
43 LONG GetWindowLongM(HWND hWnd, int nIndex);
44 #undef SetWindowLong
45 #define SetWindowLong SetWindowLongM
46 LONG SetWindowLongM(HWND hWnd, int nIndex, LONG dwNewLong);
47 #undef DefWindowProc
48 #define DefWindowProc DefWindowProcM
49 LRESULT DefWindowProcM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
50 #undef CallWindowProc
51 #define CallWindowProc CallWindowProcM
52 LRESULT CallWindowProcM(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
53 #undef SendMessage
54 #define SendMessage SendMessageM
55 LRESULT SendMessageM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
56 #undef DefDlgProc
57 #define DefDlgProc DefDlgProcM
58 LRESULT DefDlgProcM(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
59 #undef SendDlgItemMessage
60 #define SendDlgItemMessage SendDlgItemMessageM
61 LRESULT SendDlgItemMessageM(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam);
62 #undef SetWindowText
63 #define SetWindowText SetWindowTextM
64 BOOL SetWindowTextM(HWND hWnd, LPCSTR lpString);
65 #undef DragQueryFile
66 #define DragQueryFile DragQueryFileM
67 UINT DragQueryFileM(HDROP hDrop, UINT iFile, LPSTR lpszFile, UINT cch);
68 #undef GetCommandLine
69 #define GetCommandLine GetCommandLineM
70 LPSTR GetCommandLineM();
71 #undef GetCurrentDirectory
72 #define GetCurrentDirectory GetCurrentDirectoryM
73 DWORD GetCurrentDirectoryM(DWORD nBufferLength, LPSTR lpBuffer);
74 #undef SetCurrentDirectory
75 #define SetCurrentDirectory SetCurrentDirectoryM
76 BOOL SetCurrentDirectoryM(LPCSTR lpPathName);
77 #undef SetDllDirectory
78 #define SetDllDirectory SetDllDirectoryM
79 BOOL SetDllDirectoryM(LPCSTR lpPathName);
80 #undef GetTempPath
81 #define GetTempPath GetTempPathM
82 DWORD GetTempPathM(DWORD nBufferLength, LPSTR lpBuffer);
83 #undef GetFileAttributes
84 #define GetFileAttributes GetFileAttributesM
85 DWORD GetFileAttributesM(LPCSTR lpFileName);
86 #undef GetModuleFileName
87 #define GetModuleFileName GetModuleFileNameM
88 DWORD GetModuleFileNameM(HMODULE hModule, LPCH lpFilename, DWORD nSize);
89 #undef RegOpenKeyEx
90 #define RegOpenKeyEx RegOpenKeyExM
91 LSTATUS RegOpenKeyExM(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult);
92 #undef RegCreateKeyEx
93 #define RegCreateKeyEx RegCreateKeyExM
94 LSTATUS RegCreateKeyExM(HKEY hKey, LPCSTR lpSubKey, DWORD Reserved, LPSTR lpClass, DWORD dwOptions, REGSAM samDesired, CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition);
95 #undef RegDeleteValue
96 #define RegDeleteValue RegDeleteValueM
97 LSTATUS RegDeleteValueM(HKEY hKey, LPCSTR lpValueName);
98 #undef RegQueryValueEx
99 #define RegQueryValueEx RegQueryValueExM
100 LSTATUS RegQueryValueExM(HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData);
101 #undef RegSetValueEx
102 #define RegSetValueEx RegSetValueExM
103 LSTATUS RegSetValueExM(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE* lpData, DWORD cbData);
104 #undef TextOut
105 #define TextOut TextOutM
106 BOOL TextOutM(HDC hdc, int x, int y, LPCSTR lpString, int c);
107 #undef GetTextExtentPoint32
108 #define GetTextExtentPoint32 GetTextExtentPoint32M
109 BOOL GetTextExtentPoint32M(HDC hdc, LPCSTR lpString, int c, LPSIZE psizl);
110 #undef PropertySheet
111 #define PropertySheet PropertySheetM
112 INT_PTR PropertySheetM(LPCPROPSHEETHEADERA v0);
113 #undef GetOpenFileName
114 #define GetOpenFileName GetOpenFileNameM
115 BOOL GetOpenFileNameM(LPOPENFILENAMEA v0);
116 #undef GetSaveFileName
117 #define GetSaveFileName GetSaveFileNameM
118 BOOL GetSaveFileNameM(LPOPENFILENAMEA v0);
119 #undef HtmlHelp
120 #define HtmlHelp HtmlHelpM
121 HWND HtmlHelpM(HWND hwndCaller, LPCSTR pszFile, UINT uCommand, DWORD_PTR dwData);
122 #undef CreateProcess
123 #define CreateProcess CreateProcessM
124 BOOL CreateProcessM(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation);
125 #undef FindExecutable
126 #define FindExecutable FindExecutableM
127 HINSTANCE FindExecutableM(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult);
128 #undef ShellExecute
129 #define ShellExecute ShellExecuteM
130 HINSTANCE ShellExecuteM(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd);
131 #undef SHBrowseForFolder
132 #define SHBrowseForFolder SHBrowseForFolderM
133 PIDLIST_ABSOLUTE SHBrowseForFolderM(LPBROWSEINFOA lpbi);
134 #undef SHGetPathFromIDList
135 #define SHGetPathFromIDList SHGetPathFromIDListM
136 BOOL SHGetPathFromIDListM(PCIDLIST_ABSOLUTE pidl, LPSTR pszPath);
137 #undef SHFileOperation
138 #define SHFileOperation SHFileOperationM
139 int SHFileOperationM(LPSHFILEOPSTRUCTA lpFileOp);
140 #undef AppendMenu
141 #define AppendMenu AppendMenuM
142 BOOL AppendMenuM(HMENU hMenu, UINT uFlags, UINT_PTR uIDNewItem, LPCSTR lpNewItem);
143 #undef GetMenuItemInfo
144 #define GetMenuItemInfo GetMenuItemInfoM
145 BOOL GetMenuItemInfoM(HMENU hmenu, UINT item, BOOL fByPosition, LPMENUITEMINFOA lpmii);
146 #undef CreateFontIndirect
147 #define CreateFontIndirect CreateFontIndirectM
148 HFONT CreateFontIndirectM(CONST LOGFONTA *lplf);
149 #undef ChooseFont
150 #define ChooseFont ChooseFontM
151 BOOL ChooseFontM(LPCHOOSEFONTA v0);
152 #undef DialogBoxParam
153 #define DialogBoxParam DialogBoxParamM
154 INT_PTR DialogBoxParamM(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam);
155 #undef CreateDialogParam
156 #define CreateDialogParam CreateDialogParamM
157 HWND CreateDialogParamM(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam);
158 #undef mkdir
159 #define mkdir _mkdirM
160 int mkdirM(const char * _Path);
161 #undef _mkdir
162 #define _mkdir _mkdirM
163 int _mkdirM(const char * _Path);
164 #undef rmdir
165 #define rmdir rmdirM
166 int rmdirM(const char * _Path);
167 #undef _rmdir
168 #define _rmdir _rmdirM
169 int _rmdirM(const char * _Path);
170 #undef _mbslen
171 #define _mbslen _mbslenM
172 size_t _mbslenM(const unsigned char * _Str);
173 #undef _mbschr
174 #define _mbschr _mbschrM
175 unsigned char * _mbschrM(const unsigned char * _Str, unsigned int _Ch);
176 #undef _mbsrchr
177 #define _mbsrchr _mbsrchrM
178 unsigned char * _mbsrchrM(const unsigned char * _Str, unsigned int _Ch);
179 #undef _mbsstr
180 #define _mbsstr _mbsstrM
181 unsigned char * _mbsstrM(const unsigned char * _Str, const unsigned char * _Substr);
182 #undef _mbscmp
183 #define _mbscmp _mbscmpM
184 int _mbscmpM(const unsigned char * _Str1, const unsigned char * _Str2);
185 #undef _mbsicmp
186 #define _mbsicmp _mbsicmpM
187 int _mbsicmpM(const unsigned char * _Str1, const unsigned char * _Str2);
188 #undef _mbsncmp
189 #define _mbsncmp _mbsncmpM
190 int _mbsncmpM(const unsigned char * _Str1, const unsigned char * _Str2, size_t _MaxCount);
191 #undef _mbslwr
192 #define _mbslwr _mbslwrM
193 unsigned char * _mbslwrM(unsigned char * _String);
194 #undef _mbsupr
195 #define _mbsupr _mbsuprM
196 unsigned char * _mbsuprM(unsigned char * _String);
197 #undef _mbsninc
198 #define _mbsninc _mbsnincM
199 unsigned char * _mbsnincM(const unsigned char * _Str, size_t _Count);
200 #undef fopen
201 #define fopen fopenM
202 FILE * fopenM(const char * _Filename, const char * _Mode);
203
204 #undef CreateWindow
205 #define CreateWindow(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam) CreateWindowEx(0L, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
206 #undef DialogBox
207 #define DialogBox(hInstance, lpTemplate, hWndParent, lpDialogFunc) DialogBoxParam(hInstance, lpTemplate, hWndParent, lpDialogFunc, 0L)
208
209 #endif
210
211 int MtoW(LPWSTR pDst, int size, LPCSTR pSrc, int count);
212 int WtoM(LPSTR pDst, int size, LPCWSTR pSrc, int count);
213 int AtoW(LPWSTR pDst, int size, LPCSTR pSrc, int count);
214 int WtoA(LPSTR pDst, int size, LPCWSTR pSrc, int count);
215 int TerminateStringM(LPSTR lpString, int size);
216 int TerminateStringW(LPWSTR lpString, int size);
217 int TerminateStringA(LPSTR lpString, int size);
218 size_t GetMultiStringLengthM(LPCSTR lpString);
219 size_t GetMultiStringLengthW(LPCWSTR lpString);
220 size_t GetMultiStringLengthA(LPCSTR lpString);
221 int MtoWMultiString(LPWSTR pDst, int size, LPCSTR pSrc);
222 int WtoMMultiString(LPSTR pDst, int size, LPCWSTR pSrc);
223 int AtoWMultiString(LPWSTR pDst, int size, LPCSTR pSrc);
224 int WtoAMultiString(LPSTR pDst, int size, LPCWSTR pSrc);
225 char* AllocateStringM(int size);
226 wchar_t* AllocateStringW(int size);
227 char* AllocateStringA(int size);
228 wchar_t* DuplicateMtoW(LPCSTR lpString, int c);
229 wchar_t* DuplicateMtoWBuffer(LPCSTR lpString, int c, int size);
230 wchar_t* DuplicateMtoWMultiString(LPCSTR lpString);
231 wchar_t* DuplicateMtoWMultiStringBuffer(LPCSTR lpString, int size);
232 char* DuplicateWtoM(LPCWSTR lpString, int c);
233 wchar_t* DuplicateAtoW(LPCSTR lpString, int c);
234 char* DuplicateWtoA(LPCWSTR lpString, int c);
235 void FreeDuplicatedString(void* p);
236
237 int WINAPI WinMainM(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
238
239 #endif
240