- Code reorganized to move virtual methods and constructors to cpp

- winstd::bstr and winstd::variant helpers introduced
This commit is contained in:
Simon Rozman 2016-05-20 16:09:33 +02:00
parent 3167ef22d9
commit 5519358291
14 changed files with 494 additions and 0 deletions

View File

@ -73,6 +73,9 @@
</PropertyGroup>
<ItemGroup>
<ClCompile Include="..\src\Base64.cpp" />
<ClCompile Include="..\src\COM.cpp" />
<ClCompile Include="..\src\Crypt.cpp" />
<ClCompile Include="..\src\EAP.cpp" />
<ClCompile Include="..\src\ETW.cpp" />
<ClCompile Include="..\src\StdAfx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
@ -80,6 +83,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\src\Win.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\WinStd\Base64.h" />

View File

@ -20,6 +20,18 @@
<ClCompile Include="..\src\ETW.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\COM.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\Crypt.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\EAP.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\Win.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\StdAfx.h">

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

234
src/COM.cpp Normal file
View File

@ -0,0 +1,234 @@
/*
Copyright 1991-2016 Amebis
Copyright 2016 GÉANT
This file is part of WinStd.
Setup 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, either version 3 of the License, or
(at your option) any later version.
Setup 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 Setup. If not, see <http://www.gnu.org/licenses/>.
*/
#include "StdAfx.h"
//////////////////////////////////////////////////////////////////////
// winstd::bstr
//////////////////////////////////////////////////////////////////////
winstd::bstr::bstr() : handle<BSTR>()
{
}
winstd::bstr::bstr(_In_ LPCOLESTR src) : handle<BSTR>(SysAllocString(src))
{
}
winstd::bstr::bstr(_In_ LPCOLESTR src, _In_ UINT len) : handle<BSTR>(SysAllocStringLen(src, len))
{
}
winstd::bstr::~bstr()
{
if (m_h)
SysFreeString(m_h);
}
void winstd::bstr::free_internal()
{
SysFreeString(m_h);
}
winstd::bstr::handle_type winstd::bstr::duplicate_internal(_In_ handle_type h) const
{
return SysAllocStringLen(h, SysStringLen(h));
}
//////////////////////////////////////////////////////////////////////
// winstd::variant
//////////////////////////////////////////////////////////////////////
winstd::variant::variant()
{
VariantInit(this);
}
winstd::variant::variant(_In_ const VARIANT& varSrc)
{
vt = VT_EMPTY;
VariantCopy(this, &varSrc);
}
winstd::variant::variant(_In_ bool bSrc)
{
vt = VT_BOOL;
boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE;
}
winstd::variant::variant(_In_ char cSrc)
{
vt = VT_I1;
cVal = cSrc;
}
winstd::variant::variant(_In_ unsigned char nSrc)
{
vt = VT_UI1;
bVal = nSrc;
}
winstd::variant::variant(_In_ short nSrc)
{
vt = VT_I2;
iVal = nSrc;
}
winstd::variant::variant(_In_ unsigned short nSrc)
{
vt = VT_UI2;
uiVal = nSrc;
}
winstd::variant::variant(_In_ int nSrc, _In_ VARTYPE vtSrc)
{
assert(vtSrc == VT_I4 || vtSrc == VT_INT);
vt = vtSrc;
intVal = nSrc;
}
winstd::variant::variant(_In_ unsigned int nSrc, _In_ VARTYPE vtSrc)
{
assert(vtSrc == VT_UI4 || vtSrc == VT_UINT);
vt = vtSrc;
uintVal= nSrc;
}
winstd::variant::variant(_In_ long nSrc, _In_ VARTYPE vtSrc)
{
assert(vtSrc == VT_I4 || vtSrc == VT_ERROR);
vt = vtSrc;
lVal = nSrc;
}
winstd::variant::variant(_In_ unsigned long nSrc)
{
vt = VT_UI4;
ulVal = nSrc;
}
winstd::variant::variant(_In_ float fltSrc)
{
vt = VT_R4;
fltVal = fltSrc;
}
winstd::variant::variant(_In_ double dblSrc, _In_ VARTYPE vtSrc)
{
assert(vtSrc == VT_R8 || vtSrc == VT_DATE);
vt = vtSrc;
dblVal = dblSrc;
}
winstd::variant::variant(_In_ long long nSrc)
{
vt = VT_I8;
llVal = nSrc;
}
winstd::variant::variant(_In_ unsigned long long nSrc)
{
vt = VT_UI8;
ullVal = nSrc;
}
winstd::variant::variant(_In_ CY cySrc)
{
vt = VT_CY;
cyVal.Hi = cySrc.Hi;
cyVal.Lo = cySrc.Lo;
}
winstd::variant::variant(_In_z_ LPCOLESTR lpszSrc)
{
vt = VT_EMPTY;
*this = lpszSrc;
}
winstd::variant::variant(_In_z_ BSTR bstr)
{
vt = VT_EMPTY;
*this = bstr;
}
winstd::variant::variant(_In_opt_ IDispatch* pSrc)
{
vt = VT_DISPATCH;
pdispVal = pSrc;
if (pdispVal != NULL)
pdispVal->AddRef();
}
winstd::variant::variant(_In_opt_ IUnknown* pSrc)
{
vt = VT_UNKNOWN;
punkVal = pSrc;
if (punkVal != NULL)
punkVal->AddRef();
}
winstd::variant::variant(_In_ const SAFEARRAY *pSrc)
{
assert(pSrc != NULL);
LPSAFEARRAY pCopy;
HRESULT hRes = SafeArrayCopy((LPSAFEARRAY)pSrc, &pCopy);
if (SUCCEEDED(hRes)) {
SafeArrayGetVartype((LPSAFEARRAY)pSrc, &vt);
vt |= VT_ARRAY;
parray = pCopy;
} else
assert(0);
}
winstd::variant::~variant()
{
VariantClear(this);
}

149
src/Crypt.cpp Normal file
View File

@ -0,0 +1,149 @@
/*
Copyright 1991-2016 Amebis
Copyright 2016 GÉANT
This file is part of WinStd.
Setup 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, either version 3 of the License, or
(at your option) any later version.
Setup 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 Setup. If not, see <http://www.gnu.org/licenses/>.
*/
#include "StdAfx.h"
//////////////////////////////////////////////////////////////////////
// winstd::cert_context
//////////////////////////////////////////////////////////////////////
winstd::cert_context::~cert_context()
{
if (m_h)
CertFreeCertificateContext(m_h);
}
void winstd::cert_context::free_internal()
{
CertFreeCertificateContext(m_h);
}
winstd::cert_context::handle_type winstd::cert_context::duplicate_internal(_In_ handle_type h) const
{
return CertDuplicateCertificateContext(h);
}
//////////////////////////////////////////////////////////////////////
// winstd::cert_chain_context
//////////////////////////////////////////////////////////////////////
winstd::cert_chain_context::~cert_chain_context()
{
if (m_h)
CertFreeCertificateChain(m_h);
}
void winstd::cert_chain_context::free_internal()
{
CertFreeCertificateChain(m_h);
}
winstd::cert_chain_context::handle_type winstd::cert_chain_context::duplicate_internal(_In_ handle_type h) const
{
return CertDuplicateCertificateChain(h);
}
//////////////////////////////////////////////////////////////////////
// winstd::cert_store
//////////////////////////////////////////////////////////////////////
winstd::cert_store::~cert_store()
{
if (m_h)
CertCloseStore(m_h, 0);
}
void winstd::cert_store::free_internal()
{
CertCloseStore(m_h, 0);
}
//////////////////////////////////////////////////////////////////////
// winstd::crypt_prov
//////////////////////////////////////////////////////////////////////
winstd::crypt_prov::~crypt_prov()
{
if (m_h)
CryptReleaseContext(m_h, 0);
}
void winstd::crypt_prov::free_internal()
{
CryptReleaseContext(m_h, 0);
}
//////////////////////////////////////////////////////////////////////
// winstd::crypt_hash
//////////////////////////////////////////////////////////////////////
winstd::crypt_hash::~crypt_hash()
{
if (m_h)
CryptDestroyHash(m_h);
}
void winstd::crypt_hash::free_internal()
{
CryptDestroyHash(m_h);
}
winstd::crypt_hash::handle_type winstd::crypt_hash::duplicate_internal(_In_ handle_type h) const
{
handle_type hNew = NULL;
return CryptDuplicateHash(h, NULL, 0, &hNew) ? hNew : NULL;
}
//////////////////////////////////////////////////////////////////////
// winstd::crypt_key
//////////////////////////////////////////////////////////////////////
winstd::crypt_key::~crypt_key()
{
if (m_h)
CryptDestroyKey(m_h);
}
void winstd::crypt_key::free_internal()
{
CryptDestroyKey(m_h);
}
winstd::crypt_key::handle_type winstd::crypt_key::duplicate_internal(_In_ handle_type h) const
{
handle_type hNew = NULL;
return CryptDuplicateKey(h, NULL, 0, &hNew) ? hNew : NULL;
}

40
src/EAP.cpp Normal file
View File

@ -0,0 +1,40 @@
/*
Copyright 1991-2016 Amebis
Copyright 2016 GÉANT
This file is part of WinStd.
Setup 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, either version 3 of the License, or
(at your option) any later version.
Setup 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 Setup. If not, see <http://www.gnu.org/licenses/>.
*/
#include "StdAfx.h"
//////////////////////////////////////////////////////////////////////
// winstd::eap_attr
//////////////////////////////////////////////////////////////////////
winstd::eap_attr::eap_attr()
{
eaType = eatReserved;
dwLength = 0;
pValue = NULL;
}
winstd::eap_attr::~eap_attr()
{
if (pValue)
delete pValue;
}

Binary file not shown.

55
src/Win.cpp Normal file
View File

@ -0,0 +1,55 @@
/*
Copyright 1991-2016 Amebis
Copyright 2016 GÉANT
This file is part of WinStd.
Setup 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, either version 3 of the License, or
(at your option) any later version.
Setup 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 Setup. If not, see <http://www.gnu.org/licenses/>.
*/
#include "StdAfx.h"
//////////////////////////////////////////////////////////////////////
// winstd::library
//////////////////////////////////////////////////////////////////////
winstd::library::~library()
{
if (m_h)
FreeLibrary(m_h);
}
void winstd::library::free_internal()
{
FreeLibrary(m_h);
}
//////////////////////////////////////////////////////////////////////
// winstd::heap
//////////////////////////////////////////////////////////////////////
winstd::heap::~heap()
{
if (m_h)
HeapDestroy(m_h);
}
void winstd::heap::free_internal()
{
HeapDestroy(m_h);
}