A2W no ATL


Author: Dave
Date: 01.26.23 - 10:02pm



I like the Express edition of VS2008. Its super fast and lite but does not have the ATL headers. Below is A2W macro for use without the ATLCONV.H header. You can extract W2A too if you want from here
#define USES_CONVERSION int _convert = 0; (_convert); UINT _acp = CP_THREAD_ACP; (_acp); LPCWSTR _lpw = NULL; (_lpw); LPCSTR _lpa = NULL; (_lpa)

inline __out_ecount_z_opt(nChars) LPWSTR WINAPI AtlA2WHelper(__out_ecount_z(nChars) LPWSTR lpw, __in_z LPCSTR lpa, __in int nChars, __in UINT acp) throw()
{
	assert(lpa != NULL);
	assert(lpw != NULL);
	if (lpw == NULL || lpa == NULL)
		return NULL;
	// verify that no illegal character present
	// since lpw was allocated based on the size of lpa
	// don't worry about the number of chars
	lpw[0] = '';
	int ret = MultiByteToWideChar(acp, 0, lpa, -1, lpw, nChars);
	if(ret == 0)
	{
		assert(FALSE);
		return NULL;
	}		
	return lpw;
}

#define A2W(lpa) (
	((_lpa = lpa) == NULL) ? NULL : (
		_convert = (lstrlenA(_lpa)+1),
		(INT_MAX/2<_convert)? NULL :  
		AtlA2WHelper((LPWSTR) alloca(_convert*sizeof(WCHAR)), _lpa, _convert, _acp)))





Comments: (0)

 
Leave Comment:
Name:
Email: (not shown)
Message: (Required)
Math Question: 59 + 29 = ? followed by the letter: O 



About Me
More Blogs
Main Site
Posts: (All)
2024 ( 2 )
2023 (9)
     VB6 Virtual Files
     File handles across dlls
     python abort / script timeout
     py4vb
     VB6 Python embed w/debugger
     python embedding
     VB6 IDE Enhancements
     No Sleep
     A2W no ATL
2022 (4)
     More VB6 - C data passing
     Vb6 Asm listing
     Byte Array C to VB6
     Planet Source Code DVDs
2021 (2)
     Obscure VB
     VB6 IDE SP6
2020 ( 4 )
2019 ( 5 )
2018 ( 6 )
2017 ( 6 )
2016 ( 22 )
2015 ( 15 )
2014 ( 25 )
2013 ( 4 )
2012 ( 10 )
2011 ( 7 )
2010 ( 11 )
2009 ( 3 )