Finally trying to figure out what a elusive Windows API type definition is supposed to be in native PureBasic is over. *wild cheers*
If anyone wants too, feel free to post "updates" of the list to this thread when MicroSoft decides to add more types/definitions, or if I missed anything etc. all standard stuff and then some should be ther though I hope.
This is considered public domain btw, use and abuse.
Maybe by saving the array to a file and redoing the code a bit someone could make a really cool PureBasic IDE tool/plugin *grin*.
Or just compile this as it is to a exe, and call it Type Lookup or something

If anyone is wondering why I did it exactly this way, it's simple...
I not only wanted to know what PureBasic type to use to match a Windows API one, I also wanted to know what types that one was chained through (type of a type of a type of a type) as well.
Try to lookup (run the tool first silly): hcursor
Yeah, I know, creepy. No wonder Windows is so complex O.o
Code: Select all
EnableExplicit
Structure _type_list_lookup_struct_
type$
base$
note$
core.i
EndStructure
Macro AddTypeToTypelist(typeval,baseval,noteval="",coreval=#False)
typelist(size)\type$=typeval
typelist(size)\base$=baseval
typelist(size)\note$=noteval
typelist(size)\core=coreval
size+1
ReDim typelist(size)
EndMacro
Procedure.s GetTypeType(type$)
Static init.i=#False,Dim typelist._type_list_lookup_struct_(0),size.i
Protected result$,endpos.i,i.i,n.i,lc.i=#False,uc.i=#False
If Not init
;Core native types, base types and derivatives rely on these.
AddTypeToTypelist("NATIVE_BYTE",".b or .Byte","1 byte",#True)
AddTypeToTypelist("NATIVE_WORD",".w or .Word","2 bytes",#True)
AddTypeToTypelist("NATIVE_LONG",".l or .Long","4 bytes",#True)
AddTypeToTypelist("NATIVE_CHAR",".c or .Character","1 bytes (ascii) or 2 bytes (unicode)",#True)
AddTypeToTypelist("NATIVE_INT",".i or .Integer","4 bytes (x86) / 8 bytes (x64)",#True)
AddTypeToTypelist("NATIVE_POINTER","* (pointer)","4 bytes (x86) / 8 bytes (x64)",#True)
AddTypeToTypelist("NATIVE_QUAD",".q or .Quad","8 bytes",#True)
AddTypeToTypelist("NATIVE_FLOAT",".f or .Float","4 bytes",#True)
AddTypeToTypelist("NATIVE_DOUBLE",".d or .Double","8 bytes",#True)
AddTypeToTypelist("","no native equivalent",".i or .Integer might work",#True)
;Base types that the rest of the list may reference.
AddTypeToTypeList("*pointer","NATIVE_POINTER","normal pointer")
AddTypeToTypeList("__ptrdiff_type__","NATIVE_INT","for pointer arithmetic, alternatively a *pointer")
AddTypeToTypeList("__int8","NATIVE_BYTE","signed")
AddTypeToTypeList("unsigned __int8","NATIVE_BYTE","unsigned")
AddTypeToTypeList("__int16","NATIVE_WORD","signed")
AddTypeToTypeList("unsigned __int16","NATIVE_WORD","unsigned")
AddTypeToTypeList("__int32","NATIVE_LONG","signed")
AddTypeToTypeList("unsigned __int32","NATIVE_LONG","unsigned")
AddTypeToTypeList("__int64","NATIVE_QUAD","signed")
AddTypeToTypeList("unsigned __int64","NATIVE_QUAD","unsigned")
AddTypeToTypeList("__wchar_t","unsigned short","wide char/unicode")
AddTypeToTypeList("float","NATIVE_FLOAT")
AddTypeToTypeList("double","NATIVE_DOUBLE")
;Base type variants, and specials
AddTypeToTypeList("char","__int8",)
AddTypeToTypeList("unsigned char","unsigned __int8")
AddTypeToTypeList("short"," __int16")
AddTypeToTypeList("unsigned short","unsigned __int16")
AddTypeToTypeList("int","__int32")
AddTypeToTypeList("unsigned int","unsigned __int32")
AddTypeToTypeList("long","__int32")
AddTypeToTypeList("unsigned long","unsigned __int32")
AddTypeToTypeList("long long","__int64")
AddTypeToTypeList("unsigned long long","unsigned __int64")
AddTypeToTypeList("void","","could be anything")
AddTypeToTypeList("signed","__int32")
AddTypeToTypeList("unsigned","unsigned __int32")
AddTypeToTypeList("short int","__int16")
AddTypeToTypeList("long int","__int32")
AddTypeToTypeList("long long int","__int64")
AddTypeToTypeList("signed short int","__int16")
AddTypeToTypeList("signed long","__int64")
AddTypeToTypeList("signed long int","__int32")
AddTypeToTypeList("signed long long int","__int64")
AddTypeToTypeList("unsigned short int","unsigned __int16")
AddTypeToTypeList("unsigned long int","unsigned __int32")
AddTypeToTypeList("unsigned long long int","unsigned __int64")
AddTypeToTypeList("long double","double")
AddTypeToTypeList("wchar_t","__wchar_t")
AddTypeToTypeList("__ptr32","__int32","pointer on x86, truncated pointer on x64")
AddTypeToTypeList("__ptr64","__int64","pointer on x64, sign extended pointer on x86")
AddTypeToTypeList("__stdcall","*pointer","pointer to standard WINAPI function")
AddTypeToTypeList("__cdecl","*pointer","pointer to C style function")
AddTypeToTypeList("__fastcall","*pointer","a special variant of __stdcall")
AddTypeToTypeList("__clrcall","*pointer","a special variant of __stdcall")
AddTypeToTypeList("const","","specifies this is a constant typed var similar to Define <var>.<type>=<val>")
AddTypeToTypeList("__sptr","*pointer","signed")
AddTypeToTypeList("__uptr","*pointer","unsigned")
AddTypeToTypeList("unsigned __ptrdiff_type__","NATIVE_INT","for pointer arithmetic, alternatively a *pointer, unsigned")
AddTypeToTypeList("*halfpointer","","16bit on x86 / 32bit on x64, no native equivalent, signed")
AddTypeToTypeList("unsigned *halfpointer","","16bit on x86 / 32bit on x64, no native equivalent, unsigned")
;Derivatives. Add new types to the following list, they are listed alphabetically, be aware of possible cross-references in it.
AddTypeToTypeList("ATOM","WORD")
AddTypeToTypeList("BOOL","int")
AddTypeToTypeList("BOOLEAN","BYTE")
AddTypeToTypeList("BYTE","unsigned char")
AddTypeToTypeList("CALLBACK","__stdcall")
AddTypeToTypeList("CHAR","char")
AddTypeToTypeList("COLORREF","DWORD")
AddTypeToTypeList("CONST","const")
AddTypeToTypeList("DWORD","unsigned long")
AddTypeToTypeList("DWORDLONG","ULONGLONG")
AddTypeToTypeList("DWORD_PTR","ULONG_PTR")
AddTypeToTypeList("DWORD32","unsigned int")
AddTypeToTypeList("DWORD64","unsigned __int64")
AddTypeToTypeList("FLOAT","float")
AddTypeToTypeList("HACCEL","HANDLE")
AddTypeToTypeList("HALF_PTR","*halfpointer")
AddTypeToTypeList("HANDLE","PVOID")
AddTypeToTypeList("HBITMAP","HANDLE")
AddTypeToTypeList("HBRUSH","HANDLE")
AddTypeToTypeList("HCOLORSPACE","HANDLE")
AddTypeToTypeList("HCONV","HANDLE")
AddTypeToTypeList("HCONVLIST","HANDLE")
AddTypeToTypeList("HCURSOR","HICON")
AddTypeToTypeList("HDC","HANDLE")
AddTypeToTypeList("HDDEDATA","HANDLE")
AddTypeToTypeList("HDESK","HANDLE")
AddTypeToTypeList("HDROP","HANDLE")
AddTypeToTypeList("HDWP","HANDLE")
AddTypeToTypeList("HENHMETAFILE","HANDLE")
AddTypeToTypeList("HFILE","int")
AddTypeToTypeList("HFONT","HANDLE")
AddTypeToTypeList("HGDIOBJ","HANDLE")
AddTypeToTypeList("HGLOBAL","HANDLE")
AddTypeToTypeList("HHOOK","HANDLE")
AddTypeToTypeList("HICON","HANDLE")
AddTypeToTypeList("HINSTANCE","HANDLE")
AddTypeToTypeList("HKEY","HANDLE")
AddTypeToTypeList("HKL","HANDLE")
AddTypeToTypeList("HLOCAL","HANDLE")
AddTypeToTypeList("HMENU","HANDLE")
AddTypeToTypeList("HMETAFILE","HANDLE")
AddTypeToTypeList("HMODULE","HANDLE")
AddTypeToTypeList("HMONITOR","HANDLE")
AddTypeToTypeList("HPALETTE","HANDLE")
AddTypeToTypeList("HPEN","HANDLE")
AddTypeToTypeList("HRESULT","LONG")
AddTypeToTypeList("HRGN","HANDLE")
AddTypeToTypeList("HRSRC","HANDLE")
AddTypeToTypeList("HSZ","HANDLE")
AddTypeToTypeList("HWINSTA","HANDLE")
AddTypeToTypeList("HWND","HANDLE")
AddTypeToTypeList("INT","int")
AddTypeToTypeList("INT_PTR","__ptrdiff_type__")
AddTypeToTypeList("INT32","signed int")
AddTypeToTypeList("INT64","signed __int64")
AddTypeToTypeList("LANGID","WORD")
AddTypeToTypeList("LCID","DWORD")
AddTypeToTypeList("LCTYPE","DWORD")
AddTypeToTypeList("LGRPID","DWORD")
AddTypeToTypeList("LONG","long")
AddTypeToTypeList("LONGLONG","__int64")
AddTypeToTypeList("LONG_PTR","__ptrdiff_type__")
AddTypeToTypeList("LONG32","signed int")
AddTypeToTypeList("LONG64","__int64")
AddTypeToTypeList("LPARAM","LONG_PTR")
AddTypeToTypeList("LPBOOL","*pointer")
AddTypeToTypeList("LPBYTE","*pointer")
AddTypeToTypeList("LPCOLORREF","*pointer")
AddTypeToTypeList("LPCSTR","*pointer")
AddTypeToTypeList("LPCTSTR","*pointer")
AddTypeToTypeList("LPCVOID","*pointer")
AddTypeToTypeList("LPCWSTR","*pointer")
AddTypeToTypeList("LPDWORD","*pointer")
AddTypeToTypeList("LPHANDLE","*pointer")
AddTypeToTypeList("LPINT","*pointer")
AddTypeToTypeList("LPLONG","*pointer")
AddTypeToTypeList("LPSTR","*pointer")
AddTypeToTypeList("LPTSTR","*pointer")
AddTypeToTypeList("LPVOID","*pointer")
AddTypeToTypeList("LPWORD","*pointer")
AddTypeToTypeList("LPWSTR","*pointer")
AddTypeToTypeList("LRESULT","*pointer")
AddTypeToTypeList("PBOOL","*pointer")
AddTypeToTypeList("PBOOLEAN","*pointer")
AddTypeToTypeList("PBYTE","*pointer")
AddTypeToTypeList("PCHAR","*pointer")
AddTypeToTypeList("PCSTR","*pointer")
AddTypeToTypeList("PCTSTR","*pointer")
AddTypeToTypeList("PCWSTR","*pointer")
AddTypeToTypeList("PDWORD","*pointer")
AddTypeToTypeList("PDWORDLONG","*pointer")
AddTypeToTypeList("PDWORD_PTR","*pointer")
AddTypeToTypeList("PDWORD32","*pointer")
AddTypeToTypeList("PDWORD64","*pointer")
AddTypeToTypeList("PFLOAT","*pointer")
AddTypeToTypeList("PHALF_PTR","*pointer")
AddTypeToTypeList("PHANDLE","*pointer")
AddTypeToTypeList("PHKEY","*pointer")
AddTypeToTypeList("PINT","*pointer")
AddTypeToTypeList("PINT_PTR","*pointer")
AddTypeToTypeList("PINT32","*pointer")
AddTypeToTypeList("PINT64","*pointer")
AddTypeToTypeList("PLCID","*pointer")
AddTypeToTypeList("PLONG","*pointer")
AddTypeToTypeList("PLONGLONG","*pointer")
AddTypeToTypeList("PLONG_PTR","*pointer")
AddTypeToTypeList("PLONG32","*pointer")
AddTypeToTypeList("PLONG64","*pointer")
AddTypeToTypeList("POINTER_32","__ptr32")
AddTypeToTypeList("POINTER_64","__ptr64")
AddTypeToTypeList("POINTER_SIGNED","__sptr")
AddTypeToTypeList("POINTER_UNSIGNED","__uptr")
AddTypeToTypeList("PSHORT","*pointer")
AddTypeToTypeList("PSIZE_T","*pointer")
AddTypeToTypeList("PSSIZE_T","*pointer")
AddTypeToTypeList("PSTR","*pointer")
AddTypeToTypeList("PTBYTE","*pointer")
AddTypeToTypeList("PTCHAR","*pointer")
AddTypeToTypeList("PTSTR","*pointer")
AddTypeToTypeList("PUCHAR","*pointer")
AddTypeToTypeList("PUHALF_PTR","*pointer")
AddTypeToTypeList("PUINT","*pointer")
AddTypeToTypeList("PUINT_PTR","*pointer")
AddTypeToTypeList("PUINT32","*pointer")
AddTypeToTypeList("PUINT64","*pointer")
AddTypeToTypeList("PULONG","*pointer")
AddTypeToTypeList("PULONGLONG","*pointer")
AddTypeToTypeList("PULONG_PTR","*pointer")
AddTypeToTypeList("PULONG32","*pointer")
AddTypeToTypeList("PULONG64","*pointer")
AddTypeToTypeList("PUSHORT","*pointer")
AddTypeToTypeList("PVOID","*pointer")
AddTypeToTypeList("PWCHAR","*pointer")
AddTypeToTypeList("PWORD","*pointer")
AddTypeToTypeList("PWSTR","*pointer")
AddTypeToTypeList("SC_HANDLE","HANDLE")
AddTypeToTypeList("SC_LOCK","LPVOID")
AddTypeToTypeList("SERVICE_STATUS_HANDLE","HANDLE")
AddTypeToTypeList("SHORT","SHORT")
AddTypeToTypeList("SIZE_T","ULONG_PTR")
AddTypeToTypeList("SSIZE_T","LONG_PTR")
AddTypeToTypeList("TBYTE","NATIVE_CHAR")
AddTypeToTypeList("TCHAR","NATIVE_CHAR")
AddTypeToTypeList("UCHAR","unsigned char")
AddTypeToTypeList("UHALF_PTR","unsigned *halfpointer")
AddTypeToTypeList("UINT","NATIVE_LONG")
AddTypeToTypeList("UINT_PTR","unsigned __ptrdiff_type__")
AddTypeToTypeList("UINT32","unsigned int")
AddTypeToTypeList("UINT64","usigned __int64")
AddTypeToTypeList("ULONG","unsigned long")
AddTypeToTypeList("ULONGLONG","unsigned __int64")
AddTypeToTypeList("ULONG_PTR","unsigned __ptrdiff_type__")
AddTypeToTypeList("ULONG32","unsigned int")
AddTypeToTypeList("ULONG64","unsigned __int64")
AddTypeToTypeList("UNICODE_STRING","*pointer")
AddTypeToTypeList("USHORT","unsigned shor")
AddTypeToTypeList("USN","LONGLONG")
AddTypeToTypeList("VOID","void")
AddTypeToTypeList("WCHAR","wchar_t")
AddTypeToTypeList("WINAPI","__stdcall")
AddTypeToTypeList("WORD","unsigned short")
AddTypeToTypeList("WPARAM","UINT_PTR")
;Phew, that's it (for now).
init=#True
EndIf
endpos=size-1
For i=0 To endpos
If typelist(i)\type$=type$
n+1
If typelist(i)\core
result$+#CRLF$+"Z. "+"PB type = "+typelist(i)\base$+" ("+typelist(i)\note$+")"+#CRLF$
Break
Else
If typelist(i)\note$<>""
result$+Str(n)+". "+typelist(i)\type$+" = "+typelist(i)\note$+#CRLF$
Else
result$+Str(n)+". "+typelist(i)\type$+#CRLF$
EndIf
type$=typelist(i)\base$
i=0
EndIf
Else
If i>=endpos
If Not lc
type$=LCase(type$)
lc=#True
i=0
Continue
Else
If Not uc
type$=UCase(type$)
uc=#True
i=0
Continue
EndIf
EndIf
Break
EndIf
EndIf
Next
If result$=""
result$="No match!"
EndIf
ProcedureReturn result$
EndProcedure
;Example
Define match$
Repeat
match$=InputRequester("Recursive match-chain lookup of WinAPI types!","Enter type to match with PureBasic native type:","")
If match$
MessageRequester("Recursive match-chain result:",GetTypeType(match$))
EndIf
Until match$=""