mirror of
https://github.com/UzixLS/KernelEx.git
synced 2025-07-19 07:21:20 +03:00
import KernelEx-4.5-Beta1
This commit is contained in:
85
apilibs/kexbases/User32/thuni_macro.h
Executable file
85
apilibs/kexbases/User32/thuni_macro.h
Executable file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* KernelEx
|
||||
*
|
||||
* Copyright (C) 2009, Tihiy
|
||||
*
|
||||
* This file is part of KernelEx source code.
|
||||
*
|
||||
* KernelEx is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation; version 2 of the License.
|
||||
*
|
||||
* KernelEx is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU Make; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <malloc.h>
|
||||
#include "kexcoresdk.h"
|
||||
|
||||
#ifndef __THUNIMACRO_H
|
||||
#define __THUNIMACRO_H
|
||||
|
||||
#define VALID_PTR(x) (HIWORD(x))
|
||||
|
||||
#define MAX_STACK 512
|
||||
|
||||
//In macroses: convert A<->W on stack
|
||||
#define STACK_WtoA(strW,strA) \
|
||||
strA = (LPSTR)strW; \
|
||||
if HIWORD(strW) \
|
||||
{ \
|
||||
int c = lstrlenW((LPWSTR)strW); \
|
||||
c = (c+1)*2; \
|
||||
strA = (LPSTR)alloca(c); \
|
||||
WideCharToMultiByte(CP_ACP, 0, (LPWSTR)strW, -1, (LPSTR)strA, c, NULL, NULL); \
|
||||
}
|
||||
|
||||
#define STACK_AtoW(strA,strW) \
|
||||
strW = (LPWSTR)strA; \
|
||||
if (HIWORD(strA)) \
|
||||
{ \
|
||||
int c = lstrlenA((LPSTR)strA); \
|
||||
c++; \
|
||||
strW = (LPWSTR)alloca(c*sizeof(WCHAR)); \
|
||||
MultiByteToWideChar(CP_ACP, 0, (LPSTR)strA, -1, (LPWSTR)strW, c); \
|
||||
}
|
||||
|
||||
//Out macroses: allocate buffer, call W>-<A function, convert A<->W
|
||||
#define ABUFFER_ALLOC(buffer,len) \
|
||||
int buffer##size = ((len+1) * 2); \
|
||||
LPSTR buffer##heap = NULL; \
|
||||
if (buffer##size>MAX_STACK) \
|
||||
{ \
|
||||
buffer##heap = (LPSTR)HeapAlloc(GetProcessHeap(),0,buffer##size); \
|
||||
buffer = buffer##heap; \
|
||||
} \
|
||||
else \
|
||||
buffer = (LPSTR)alloca( buffer##size ); \
|
||||
*buffer='\0';
|
||||
|
||||
#define WBUFFER_ALLOC(buffer,len) \
|
||||
int buffer##size = ((len+1) * sizeof(WCHAR)); \
|
||||
LPWSTR buffer##heap = NULL; \
|
||||
if (buffer##size>MAX_STACK) \
|
||||
{ \
|
||||
buffer##heap = (LPWSTR)HeapAlloc(GetProcessHeap(),0,buffer##size); \
|
||||
buffer = buffer##heap; \
|
||||
} \
|
||||
else \
|
||||
buffer = (LPWSTR)alloca( buffer##size ); \
|
||||
*buffer='\0';
|
||||
|
||||
#define ABUFFER_toW(bufferA,bufferW,lenW) MultiByteToWideChar(CP_ACP, 0, bufferA, -1, (LPWSTR)bufferW, lenW);
|
||||
#define WBUFFER_toA(bufferW,bufferA,lenA) WideCharToMultiByte(CP_ACP, 0, bufferW, -1, (LPSTR)bufferA, lenA, NULL, NULL);
|
||||
|
||||
#define BUFFER_FREE(buffer) \
|
||||
if ( buffer##heap ) HeapFree(GetProcessHeap(),0,buffer##heap); \
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user