3dsmaxdlport.h File Reference

#include "utilexp.h"
#include "strbasic.h"
#include "BuildWarnings.h"
#include <wtypes.h>
#include <cmath>
#include <cstdlib>

Macros

#define DL_STDEXT   stdext
 
#define DL_NON_RTTI_OBJECT   std::__non_rtti_object
 
#define DL_TYPENAME_OUTSIDE_TEMPLATE   typename
 

Typedefs

typedef INT_PTR(CALLBACK * DL_NOTQUITE_WNDPROC) (HWND, UINT, WPARAM, LPARAM)
 

Enumerations

enum  { FNV1_32_INIT = 0x811c9dc5, FNV_32_PRIME = 0x01000193 }
 

Functions

template<typename DataPtr >
DataPtr DLGetWindowLongPtr (HWND hWnd, int n=GWLP_USERDATA, DataPtr=NULL)
 
template<typename DataPtr >
DataPtr DLGetWindowLongPtrA (HWND hWnd, int n=GWLP_USERDATA)
 
template<typename DataPtr >
DataPtr DLGetWindowLongPtrW (HWND hWnd, int n=GWLP_USERDATA)
 
template<typename DataPtr >
DataPtr DLGetWindowLongPtr (HWND hWnd, DataPtr *pPtr, int n=GWLP_USERDATA)
 
template<>
bool DLGetWindowLongPtr (HWND hWnd, int n, bool)
 
WNDPROC DLGetWindowProc (HWND hWnd)
 
WNDPROC DLGetWindowProcA (HWND hWnd)
 
WNDPROC DLGetWindowProcW (HWND hWnd)
 
HINSTANCE DLGetWindowInstance (HWND hWnd)
 
template<typename Type >
Type DLSetWindowLongPtr (HWND hWnd, Type ptr, int n=GWLP_USERDATA)
 
template<>
bool DLSetWindowLongPtr (HWND hWnd, bool bo, int n)
 
WNDPROC DLSetWindowLongPtr (HWND hWnd, WNDPROC pfn)
 
WNDPROC DLSetWindowProc (HWND hWnd, WNDPROC pfn)
 
template<typename DataPtr >
DataPtr DLGetClassLongPtr (HWND hWnd, int n, DataPtr=NULL)
 
template<typename DataPtr >
DataPtr DLGetClassLongPtrA (HWND hWnd, int n)
 
template<typename DataPtr >
DataPtr DLGetClassLongPtrW (HWND hWnd, int n)
 
template<typename DataPtr >
DataPtr DLGetClassLongPtr (HWND hWnd, DataPtr *pPtr, int n)
 
template<>
bool DLGetClassLongPtr (HWND hWnd, int n, bool)
 
WNDPROC DLGetClassWindowProc (HWND hWnd)
 
WNDPROC DLGetClassWindowProcA (HWND hWnd)
 
WNDPROC DLGetClassWindowProcW (HWND hWnd)
 
template<typename Type >
Type DLSetClassLongPtr (HWND hWnd, Type ptr, int n)
 
template<>
bool DLSetClassLongPtr (HWND hWnd, bool bo, int n)
 
template<typename Type >
Type DLSetClassLongPtrA (HWND hWnd, Type ptr, int n)
 
template<typename Type >
Type DLSetClassLongPtrW (HWND hWnd, Type ptr, int n)
 
WNDPROC DLSetClassWindowProc (HWND hWnd, WNDPROC pfn)
 
WNDPROC DLSetClassWindowProcA (HWND hWnd, WNDPROC pfn)
 
WNDPROC DLSetClassWindowProcW (HWND hWnd, WNDPROC pfn)
 
UtilExport LONG DLRegSetString (HKEY key, const MCHAR *data, const MCHAR *name=NULL)
 Wrapper around the windows function RegSetValueEx. More...
 
UtilExport LONG DLRegSetDWord (HKEY key, DWORD data, const MCHAR *name=NULL)
 Wrapper around the windows function RegSetValueEx for DWORD data. More...
 
template<typename BlobType >
LONG DLRegSetBlob (HKEY key, const BlobType *lpbValue, DWORD n, LPCMSTR lpValueName=NULL)
 
UtilExport BOOL DLGetTextExtent (HDC hDC, const MCHAR *text, LPSIZE lpExtent)
 
UtilExport BOOL DLGetTextExtent (HDC hDC, const MCHAR *text, size_t len, LPSIZE lpExtent)
 
UtilExport BOOL DLTextOut (HDC hDC, int x, int y, const MCHAR *text)
 
UtilExport BOOL DLTextOut (HDC hDC, int x, int y, const MCHAR *text, size_t len)
 
UtilExport LONG DLTabbedTextOut (HDC hDC, int x, int y, const MCHAR *text, int nTabs, const INT *pTabPositions, int nTabOrigin)
 
UtilExport int DLDrawText (HDC hDC, const MCHAR *lpString, LPRECT lpRect, UINT uFormat)
 
UtilExport int DLDrawText (HDC hDC, const MCHAR *lpString, size_t len, LPRECT lpRect, UINT uFormat)
 
WORD PointerHiPart (ULONG_PTR ptr)
 
WORD PointerLoPart (ULONG_PTR ptr)
 
WORD PointerHiPart (LONG_PTR ptr)
 
WORD PointerLoPart (LONG_PTR ptr)
 
WORD PointerHiPart (void *ptr)
 
WORD PointerLoPart (void *ptr)
 
unsigned int fnv_32_buf (const void *buf, int len, unsigned int hval)
 
template<typename T >
unsigned int DLObjectHash (T &t, int HashTableSize=0)
 
unsigned int DLPointerHash (const void *pv, int HashTableSize=0)
 
int DL_abs (int n)
 
__int64 DL_abs (__int64 n)
 
float DL_abs (float f)
 
double DL_abs (double f)
 
long double DL_abs (long double f)
 

Macro Definition Documentation

#define DL_STDEXT   stdext
#define DL_NON_RTTI_OBJECT   std::__non_rtti_object
#define DL_TYPENAME_OUTSIDE_TEMPLATE   typename

Typedef Documentation

typedef INT_PTR(CALLBACK* DL_NOTQUITE_WNDPROC) (HWND, UINT, WPARAM, LPARAM)

Enumeration Type Documentation

anonymous enum
Enumerator
FNV1_32_INIT 
FNV_32_PRIME 
437 {
438  FNV1_32_INIT = 0x811c9dc5,
439  FNV_32_PRIME = 0x01000193
440 };
Definition: 3dsmaxdlport.h:438
Definition: 3dsmaxdlport.h:439

Function Documentation

DataPtr DLGetWindowLongPtr ( HWND  hWnd,
int  n = GWLP_USERDATA,
DataPtr  = NULL 
)
49 {
50  return (DataPtr)(static_cast<LONG_PTR>(::GetWindowLongPtr(hWnd, n)));
51 }
DataPtr DLGetWindowLongPtrA ( HWND  hWnd,
int  n = GWLP_USERDATA 
)
54 {
55  return (DataPtr)(static_cast<LONG_PTR>(::GetWindowLongPtrA(hWnd, n)));
56 }
DataPtr DLGetWindowLongPtrW ( HWND  hWnd,
int  n = GWLP_USERDATA 
)
59 {
60  return (DataPtr)(static_cast<LONG_PTR>(::GetWindowLongPtrW(hWnd, n)));
61 }
DataPtr DLGetWindowLongPtr ( HWND  hWnd,
DataPtr *  pPtr,
int  n = GWLP_USERDATA 
)
64 {
65  *pPtr = DLGetWindowLongPtr<DataPtr>(hWnd, n);
66 
67  return *pPtr;
68 }
bool DLGetWindowLongPtr ( HWND  hWnd,
int  n,
bool   
)
inline
71 {
72  // Specialize for bool so we can quietly deal
73  // warning C4800: 'LONG_PTR' : forcing value to bool 'true' or 'false' (performance warning)
74  return ::GetWindowLongPtr(hWnd, n) != 0;
75 }
WNDPROC DLGetWindowProc ( HWND  hWnd)
inline
78 {
79  return DLGetWindowLongPtr<WNDPROC>(hWnd, GWLP_WNDPROC);
80 }
WNDPROC DLGetWindowProcA ( HWND  hWnd)
inline
83 {
84  return DLGetWindowLongPtrA<WNDPROC>(hWnd, GWLP_WNDPROC);
85 }
WNDPROC DLGetWindowProcW ( HWND  hWnd)
inline
88 {
89  return DLGetWindowLongPtrW<WNDPROC>(hWnd, GWLP_WNDPROC);
90 }
HINSTANCE DLGetWindowInstance ( HWND  hWnd)
inline
93 {
94  return DLGetWindowLongPtr<HINSTANCE>(hWnd, GWLP_HINSTANCE);
95 }
Type DLSetWindowLongPtr ( HWND  hWnd,
Type  ptr,
int  n = GWLP_USERDATA 
)
inline
102 {
103 #if !defined( _WIN64 )
104  // SetWindowLongPtr() maps to SetWindowLong() in 32 bit land; react accordingly to keep
105  // the compiler happy, even with /Wp64.
106  return (Type)(static_cast<LONG_PTR>(::SetWindowLongPtr(hWnd, n, (LONG)((LONG_PTR)(ptr)))));
107 #else
108  return (Type)(static_cast<LONG_PTR>(::SetWindowLongPtr(hWnd, n, (LONG_PTR)(ptr))));
109 #endif
110 }
bool DLSetWindowLongPtr ( HWND  hWnd,
bool  bo,
int  n 
)
inline
113 {
114  // Specialize for bool so we can quietly deal
115  // warning C4800: 'LONG_PTR' : forcing value to bool 'true' or 'false' (performance warning)
116  return ::SetWindowLongPtr(hWnd, n, bo) != 0;
117 }
WNDPROC DLSetWindowLongPtr ( HWND  hWnd,
WNDPROC  pfn 
)
inline
120 {
121  return DLSetWindowLongPtr<WNDPROC>(hWnd, pfn, GWLP_WNDPROC);
122 }
WNDPROC DLSetWindowProc ( HWND  hWnd,
WNDPROC  pfn 
)
inline
125 {
126  return DLSetWindowLongPtr<WNDPROC>(hWnd, pfn, GWLP_WNDPROC);
127 }
DataPtr DLGetClassLongPtr ( HWND  hWnd,
int  n,
DataPtr  = NULL 
)
138 {
139  return (DataPtr)(static_cast<LONG_PTR>(::GetClassLongPtr(hWnd, n)));
140 }
DataPtr DLGetClassLongPtrA ( HWND  hWnd,
int  n 
)
143 {
144  return (DataPtr)(static_cast<LONG_PTR>(::GetClassLongPtrA(hWnd, n)));
145 }
DataPtr DLGetClassLongPtrW ( HWND  hWnd,
int  n 
)
148 {
149  return (DataPtr)(static_cast<LONG_PTR>(::GetClassLongPtrW(hWnd, n)));
150 }
DataPtr DLGetClassLongPtr ( HWND  hWnd,
DataPtr *  pPtr,
int  n 
)
153 {
154  *pPtr = DLGetClassLongPtr<DataPtr>(hWnd, n);
155 
156  return *pPtr;
157 }
bool DLGetClassLongPtr ( HWND  hWnd,
int  n,
bool   
)
inline
160 {
161  return ::GetClassLongPtr(hWnd, n) != 0;
162 }
WNDPROC DLGetClassWindowProc ( HWND  hWnd)
inline
165 {
166  return DLGetClassLongPtr<WNDPROC>(hWnd, GCLP_WNDPROC);
167 }
WNDPROC DLGetClassWindowProcA ( HWND  hWnd)
inline
170 {
171  return DLGetClassLongPtrA<WNDPROC>(hWnd, GCLP_WNDPROC);
172 }
WNDPROC DLGetClassWindowProcW ( HWND  hWnd)
inline
175 {
176  return DLGetClassLongPtrW<WNDPROC>(hWnd, GCLP_WNDPROC);
177 }
Type DLSetClassLongPtr ( HWND  hWnd,
Type  ptr,
int  n 
)
inline
180 {
181 #if !defined( _WIN64 )
182  // SetClassLongPtr() maps to SetClassLong() in 32 bit land; react accordingly to keep
183  // the compiler happy, even with /Wp64.
184  return (Type)(static_cast<LONG_PTR>(::SetClassLongPtr(hWnd, n, (LONG)((LONG_PTR)(ptr)))));
185 #else
186  return (Type)(static_cast<LONG_PTR>(::SetClassLongPtr(hWnd, n, (LONG_PTR)(ptr))));
187 #endif
188 }
bool DLSetClassLongPtr ( HWND  hWnd,
bool  bo,
int  n 
)
inline
191 {
192  // Specialize for bool so we can quietly deal
193  // warning C4800: 'LONG_PTR' : forcing value to bool 'true' or 'false' (performance warning)
194  return ::SetClassLongPtr(hWnd, n, bo) != 0;
195 }
Type DLSetClassLongPtrA ( HWND  hWnd,
Type  ptr,
int  n 
)
inline
198 {
199 #if !defined( _WIN64 )
200  // SetClassLongPtr() maps to SetClassLong() in 32 bit land; react accordingly to keep
201  // the compiler happy, even with /Wp64.
202  return (Type)(static_cast<LONG_PTR>(::SetClassLongPtrA(hWnd, n, (LONG)((LONG_PTR)(ptr)))));
203 #else
204  return (Type)(static_cast<LONG_PTR>(::SetClassLongPtrA(hWnd, n, (LONG_PTR)(ptr))));
205 #endif
206 }
Type DLSetClassLongPtrW ( HWND  hWnd,
Type  ptr,
int  n 
)
inline
209 {
210 #if !defined( _WIN64 )
211  // SetClassLongPtr() maps to SetClassLong() in 32 bit land; react accordingly to keep
212  // the compiler happy, even with /Wp64.
213  return (Type)(static_cast<LONG_PTR>(::SetClassLongPtrW(hWnd, n, (LONG)((LONG_PTR)(ptr)))));
214 #else
215  return (Type)(static_cast<LONG_PTR>(::SetClassLongPtrW(hWnd, n, (LONG_PTR)(ptr))));
216 #endif
217 }
WNDPROC DLSetClassWindowProc ( HWND  hWnd,
WNDPROC  pfn 
)
inline
220 {
221  return DLSetClassLongPtr<WNDPROC>(hWnd, pfn, GCLP_WNDPROC);
222 }
WNDPROC DLSetClassWindowProcA ( HWND  hWnd,
WNDPROC  pfn 
)
inline
225 {
226  return DLSetClassLongPtrA<WNDPROC>(hWnd, pfn, GCLP_WNDPROC);
227 }
WNDPROC DLSetClassWindowProcW ( HWND  hWnd,
WNDPROC  pfn 
)
inline
230 {
231  return DLSetClassLongPtrW<WNDPROC>(hWnd, pfn, GCLP_WNDPROC);
232 }
UtilExport LONG DLRegSetString ( HKEY  key,
const MCHAR data,
const MCHAR name = NULL 
)

Wrapper around the windows function RegSetValueEx.

Parameters
key- The handle to an open registry key
data- The actual data to be added to the registry
name- The name of the registry key
1 HKEY query;
2 TSTR sub_key;
3 sub_key.printf(_T("Software\\Autodesk\\3dsMax\\%d.0"), MAX_VERSION_MAJOR);
4 LONG opened = ::RegOpenKeyEx(HKEY_CURRENT_USER, sub_key.data(), 0, KEY_ALL_ACCESS, &query);
5 if (opened != ERROR_SUCCESS)
6  return;
7 
8 LONG result = DLRegSetString(query, _T("TestValue"), _T("TestKey"));
UtilExport LONG DLRegSetDWord ( HKEY  key,
DWORD  data,
const MCHAR name = NULL 
)

Wrapper around the windows function RegSetValueEx for DWORD data.

Parameters
key- The handle to an open registry key
data- The actual data to be added to the registry
name- The name of the registry key
LONG DLRegSetBlob ( HKEY  key,
const BlobType *  lpbValue,
DWORD  n,
LPCMSTR  lpValueName = NULL 
)
inline
289 {
290  return ::RegSetValueEx(key, lpValueName, 0, REG_BINARY,
291  reinterpret_cast<LPBYTE>(const_cast<BlobType*>(lpbValue)),
292  n * sizeof(BlobType));
293 }
UtilExport BOOL DLGetTextExtent ( HDC  hDC,
const MCHAR text,
LPSIZE  lpExtent 
)
UtilExport BOOL DLGetTextExtent ( HDC  hDC,
const MCHAR text,
size_t  len,
LPSIZE  lpExtent 
)
UtilExport BOOL DLTextOut ( HDC  hDC,
int  x,
int  y,
const MCHAR text 
)
UtilExport BOOL DLTextOut ( HDC  hDC,
int  x,
int  y,
const MCHAR text,
size_t  len 
)
UtilExport LONG DLTabbedTextOut ( HDC  hDC,
int  x,
int  y,
const MCHAR text,
int  nTabs,
const INT *  pTabPositions,
int  nTabOrigin 
)
UtilExport int DLDrawText ( HDC  hDC,
const MCHAR lpString,
LPRECT  lpRect,
UINT  uFormat 
)
UtilExport int DLDrawText ( HDC  hDC,
const MCHAR lpString,
size_t  len,
LPRECT  lpRect,
UINT  uFormat 
)
WORD PointerHiPart ( ULONG_PTR  ptr)
inline
355 {
356  return static_cast<WORD>(ptr >> 16);
357 }
WORD PointerLoPart ( ULONG_PTR  ptr)
inline
360 {
361  return static_cast<WORD>(ptr);
362 }
WORD PointerHiPart ( LONG_PTR  ptr)
inline
365 {
366  return static_cast<WORD>((ptr >> 16) & 0xffff);
367 }
WORD PointerLoPart ( LONG_PTR  ptr)
inline
370 {
371  return static_cast<WORD>(ptr & 0xffff);
372 }
WORD PointerHiPart ( void ptr)
inline
375 {
376  return PointerHiPart(reinterpret_cast<ULONG_PTR>(ptr));
377 }
WORD PointerHiPart(ULONG_PTR ptr)
Definition: 3dsmaxdlport.h:354
WORD PointerLoPart ( void ptr)
inline
380 {
381  return PointerLoPart(reinterpret_cast<ULONG_PTR>(ptr));
382 }
WORD PointerLoPart(ULONG_PTR ptr)
Definition: 3dsmaxdlport.h:359
unsigned int fnv_32_buf ( const void buf,
int  len,
unsigned int  hval 
)
inline
461 {
462  const unsigned char *bp = (const unsigned char *)buf; /* start of buffer */
463  const unsigned char *be = bp + len; /* beyond end of buffer */
464 
465  /*
466  * FNV-1 hash each octet in the buffer
467  */
468  while (bp < be)
469  {
470  /* multiply by the 32 bit FNV magic prime mod 2^32 */
471  hval *= FNV_32_PRIME;
472 
473  /* xor the bottom with the current octet */
474  hval ^= (unsigned int)*bp++;
475  }
476 
477  /* return our new hash value */
478  return hval;
479 }
MAXMEM_EXTERN_C UtilExport int(__cdecl *MAX_heapadd)(void *memblock
Definition: 3dsmaxdlport.h:439
unsigned int DLObjectHash ( T &  t,
int  HashTableSize = 0 
)
inline
483 {
484  // Since we're always hashing single objects, we hash using the 'init value';
485  // we'd have to carry it over if we were hashing all fields in a structure, for
486  // instance.
487  // You should never never never never attempt to hash a structure by passing its
488  // pointer, since you'd end up hashing the padding bytes as well, which are definitely
489  // not going to be preserved.
490  unsigned int hash = fnv_32_buf(&t, sizeof(t), (unsigned int)FNV1_32_INIT);
491 
492  return HashTableSize ? hash % HashTableSize : hash;
493 }
Definition: 3dsmaxdlport.h:438
unsigned int fnv_32_buf(const void *buf, int len, unsigned int hval)
Definition: 3dsmaxdlport.h:460
unsigned int DLPointerHash ( const void pv,
int  HashTableSize = 0 
)
inline
496 {
497  return DLObjectHash(pv, HashTableSize);
498 }
unsigned int DLObjectHash(T &t, int HashTableSize=0)
Definition: 3dsmaxdlport.h:482
int DL_abs ( int  n)
inline
507 { return std::abs(n); }
__int64 DL_abs ( __int64  n)
inline
508 { return (n < 0) ? -n : n; }
float DL_abs ( float  f)
inline
510 { return std::fabsf(f); }
double DL_abs ( double  f)
inline
511 { return std::fabs(f); }
long double DL_abs ( long double  f)
inline
512 { return std::fabsl(f); }