我正試圖為我的專案編譯一個工具。到目前為止,我已經解決了所有的問題,但我找不到這個問題的解決方案。
如果有人能給我幫助,我將不勝感激,謝謝你。
NtlScriptEncrypter.cpp
NtlScriptEncrypter.h
class CNtlScriptEncrypter
{
public:
CNtlScriptEncrypter(void)。
~CNtlScriptEncrypter(void)。
static BOOL LoadConfigOption(OUT SConfigData* pConfigData, char* szFileName)。
static BOOL SaveConfigOption(SConfigData* pConfigData, char* szFileName, BOOL bEncrypt = FALSE)。
protected:
static BOOL LoadConfigOptionXML(OUT SConfigData* pConfigData,char* szFileName)。
static BOOL LoadConfigOptionENC(OUT SConfigData* pConfigData, char* szFileName);
static BOOL SaveConfigOptionXML(SConfigData* pConfigData, char* szFileName);
static BOOL SaveConfigOptionENC(SConfigData* pConfigData, char* szFileName, char* szCryptPassword)。
};
NtlXMLDoc.cpp
。
#include "StdAfx.h"
#include <comdef.h>
#include <atlbase.h>
#include "NtlXMLDoc.h"
//#include "NtlAssert.h"
class CCoInit
{
public:
CCoInit( void )
{
::CoInitialize( NULL ) 。
}
~CCoInit( void )
{
::CoUninitialize()。
}
};
CCoInit g_CoInit;
CNtlXMLDoc::CNtlXMLDoc(void)
{
Init()。
}
CNtlXMLDoc::~CNtlXMLDoc(void)
{
Destroy()。
}
bool CNtlXMLDoc::Create()
{
if (NULL != m_pXMLDocument)
return false;
HRESULT hResult;
hResult = :: CoCreateInstance(__uuidof(DOMDocument30), NULL, CLSCTX_INPROC_SERVER, __uuidof(IXMLDOMDocument), (void**)& m_pXMLDocument) 。
if (FAILED(hResult))
{
::CoInitialize( NULL ) 。
hResult = :: CoCreateInstance(__uuidof(DOMDocument30), NULL, CLSCTX_INPROC_SERVER, __uuidof(IXMLDOMDocument), (void**)& m_pXMLDocument) 。
if (FAILED(hResult))
{
Destroy()。
return false;
}
}
if (NULL == m_pXMLDocument)
{
Destroy()。
return false;
}
hResult = m_pXMLDocument->put_async(VARIANT_FALSE)。
if (FAILED(hResult))
{
Destroy()。
return false;
}
hResult = m_pXMLDocument->put_validateOnParse(VARIANT_FALSE)。
if (FAILED(hResult))
{
Destroy()。
return false;
}
hResult = m_pXMLDocument->put_resolveExternals(VARIANT_FALSE)。
if (FAILED(hResult))
{
Destroy()。
return false;
}
return true;
}
bool CNtlXMLDoc::Destroy()
{
if (NULL != m_pXMLDocument)
{
m_pXMLDocument->Release()。
m_pXMLDocument = NULL。
}
m_bIsFileLoaded = false;
return true;
}
void CNtlXMLDoc::Init()
{
m_pXMLDocument = NULL。
m_bIsFileLoaded = false;
}
bool CNtlXMLDoc::Load(WCHAR* pwszFileName, LONG* lLineNumber, BSTR* bstrErrorReasonString )
{
if (false != m_bIsFileLoaded)
return false;
VARIANT_BOOL status = VARIANT_FALSE;
HRESULT hResult = m_pXMLDocument->load((_variant_t)pwszFileName, &status) 。
if (FAILED(hResult))
{
return false;
}
if (VARIANT_FALSE == status)
{
IXMLDOMParseError* pXMLError = NULL;
m_pXMLDocument->get_parseError(&pXMLError)。
//BSTR bstrErrorReasonString;。
//LONG lLineNumber = 0;
BSTR bstrSrcText。
LONG lLinePosition = 0;
pXMLError->get_srcText(&bstrSrcText)。
pXMLError->get_reason(bstrErrorReasonString)。
pXMLError->get_line(lLineNumber)。
pXMLError->get_linepos(&lLinePosition)。
//::SysFreeString(*bstrErrorReasonString);
pXMLError->Release()。
return false。
}
m_bIsFileLoaded = true;
return true;
}
bool CNtlXMLDoc::Load(WCHAR* pwszFileName )
{
if (false != m_bIsFileLoaded)
return false;
VARIANT_BOOL status = VARIANT_FALSE;
HRESULT hResult = m_pXMLDocument->load((_variant_t)pwszFileName, &status) 。
if (FAILED(hResult))
{
return false;
}
if (VARIANT_FALSE == status)
{
IXMLDOMParseError* pXMLError = NULL;
m_pXMLDocument->get_parseError(&pXMLError)。
BSTR bstrErrorReasonString。
LONG lLineNumber = 0;
BSTR bstrSrcText;
LONG lLinePosition = 0;
pXMLError->get_srcText(&bstrSrcText)。
pXMLError->get_reason(&bstrErrorReasonString)。
pXMLError->get_line(&lLineNumber)。
pXMLError->get_linepos(&lLinePosition)。
::SysFreeString(bstrErrorReasonString)。
pXMLError->Release()。
return false。
}
m_bIsFileLoaded = true;
return true;
}
bool CNtlXMLDoc::Load(char* pszFileName)
{
if (false != m_bIsFileLoaded)
return false;
WCHAR wszUnicodeFileName[MAX_UNICODE_FILE_NAME_LENGTH 1] 。
ZeroMemory(wszUnicodeFileName, sizeof(WCHAR) * (MAX_UNICODE_FILE_NAME_LENGTH 1)) 。
int iWrittenChars = :: MultiByteToWideChar(GetACP(), 0, pszFileName, -1, wszUnicodeFileName, MAX_UNICODE_FILE_NAME_LENGTH)。)
wszUnicodeFileName[MAX_UNICODE_FILE_NAME_LENGTH] = L''/span>;
if (0 == iWrittenChars)
return false;
return Load(wszUnicodeFileName)。
}
bool CNtlXMLDoc::LoadXML( char* szXMLBuffer )
{
uses_conversion;
if(false != m_bIsFileLoaded)
return false;
return LoadXML(A2W(szXMLBuffer))。
}
bool CNtlXMLDoc::LoadXML( WCHAR* wszXMLBuffer )/span>
{
if (false != m_bIsFileLoaded)
return false;
VARIANT_BOOL status。
HRESULT hResult = m_pXMLDocument->loadXML(wszXMLBuffer, &status)。
if (FAILED(hResult))
{
return false;
}
if (VARIANT_FALSE == status)
{
IXMLDOMParseError* pXMLError = NULL;
m_pXMLDocument->get_parseError(&pXMLError)。
BSTR bstrErrorReasonString。
pXMLError->get_reason(&bstrErrorReasonString)。
::SysFreeString(bstrErrorReasonString)。
pXMLError->Release()。
return false。
}
m_bIsFileLoaded = true;
return true;
}
IXMLDOMNode* CNtlXMLDoc::SelectSingleNode(WCHAR* pwszXPath)
{
if (false == m_bIsFileLoaded)
return NULL。
if (NULL == pwszXPath)
return NULL;
IXMLDOMNode* pXMLNode = NULL;
BSTR bstrXPath = ::SysAllocString(pwszXPath)。
HRESULT hResult = m_pXMLDocument->selectSingleNode(bstrXPath, &pXMLNode)。
if (FAILED(hResult))
{
::SysFreeString(bstrXPath)。
return NULL。
}
::SysFreeString(bstrXPath)。
return pXMLNode;
}
IXMLDOMNode* CNtlXMLDoc::SelectSingleNode(char* pszXPath)
{
if (false == m_bIsFileLoaded)
return NULL;
WCHAR wszUnicodeXPath[MAX_UNICODE_XPATH_LENGTH 1] 。
ZeroMemory(wszUnicodeXPath, sizeof(WCHAR) * (MAX_UNICODE_XPATH_LENGTH 1)。
int iWrittenChars = :: MultiByteToWideChar(GetACP), 0, pszXPath, -1, wszUnicodeXPath, MAX_UNICODE_XPATH_LENGTH)。)
wszUnicodeXPath[MAX_UNICODE_XPATH_LENGTH] = L''/span>;
if (0 == iWrittenChars)
return NULL;
return SelectSingleNode(wszUnicodeXPath)。
}
IXMLDOMNodeList* CNtlXMLDoc::SelectNodeList(WCHAR* pwszXPath)
{
if (false == m_bIsFileLoaded)
return NULL。
if (NULL == pwszXPath)
return NULL;
IXMLDOMNodeList* pXMLNodeList = NULL;
BSTR bstrXPath = ::SysAllocString(pwszXPath)。
HRESULT hResult = m_pXMLDocument->selectNodes(bstrXPath, &pXMLNodeList)。
if (FAILED(hResult))
{
::SysFreeString(bstrXPath)。
return NULL。
}
::SysFreeString(bstrXPath)。
return pXMLNodeList;
}
IXMLDOMNodeList* CNtlXMLDoc::SelectNodeList(char* pszXPath)
{
if (false == m_bIsFileLoaded)
return NULL;
WCHAR wszUnicodeXPath[MAX_UNICODE_XPATH_LENGTH 1] 。
ZeroMemory(wszUnicodeXPath, sizeof(WCHAR) * (MAX_UNICODE_XPATH_LENGTH 1)。
int iWrittenChars = :: MultiByteToWideChar(GetACP), 0, pszXPath, -1, wszUnicodeXPath, MAX_UNICODE_XPATH_LENGTH)。)
wszUnicodeXPath[MAX_UNICODE_XPATH_LENGTH] = L''/span>;
if (0 == iWrittenChars)
return NULL;
return SelectNodeList(wszUnicodeXPath)。
}
bool CNtlXMLDoc:: GetTextWithAttributeName(IXMLDOMNode* pNode, WCHAR* pwszAttributeName, WCHAR* pwszResultText, int nBufferSizeInWChars)
{
if (NULL == pNode || NULL == pwszAttributeName || NULL == pwszResultText)
{
// NtlAssertFail("NULL == pNode || NULL == pwszAttributeName || NULL == pwszResultText");
return false。
}
if (0 >= nBufferSizeInWChars)
{
//NtlAssertFail("0 >= nBufferSizeInWChars");.
return false。
}
IXMLDOMNamedNodeMap* pMap = NULL;
pNode->get_attributes(&pMap)。
if (NULL == pMap)
{
//NtlAssertFail("無法從給定的IXMLDOMNode中獲取屬性串列。");.
return false。
}
IXMLDOMNode* pVirtualNode = NULL;
pMap->getNamedItem(pwszAttributeName, &pVirtualNode)。
if (NULL == pVirtualNode)
{
//NtlAssertFail("無法找到給定的屬性名稱。");
return false。
}
VARIANT var;
VariantInit(&var)。
pVirtualNode->get_nodeValue(&var)。
if (wcslen(V_BSTR(&var)) >=(size_t)nBufferSizeInWChars)
{
//NtlAssertFail("緩沖區的大小不足以容納整個屬性值。");
return false。
}
wcscpy_s(pwszResultText, nBufferSizeInWChars, V_BSTR(&var))。
return true。
}
bool CNtlXMLDoc:: GetTextWithAttributeName(IXMLDOMNode* pNode, char* pszAttributeName, char* pszResultText, int nBufferSizeInBytes)
{
if (NULL == pNode || NULL == pszAttributeName || NULL == pszResultText)
{
// NtlAssertFail("NULL == pNode || NULL == pszAttributeName || NULL == pszResultText");
return false。
}
if (0 >= nBufferSizeInBytes)
{
//NtlAssertFail("0 >= nBufferSizeInBytes");.
return false。
}
int nRequiredBytes = 0;
nRequiredBytes = MultiByteToWideChar(GetACP(), 0, pszAttributeName, -1, NULL, 0)。)
if (0 == nRequiredBytes)
{
//NtlAssertFail("給定的屬性名稱由于某種原因不能被轉換成WCHAR型別。");
return false。
}
if (nRequiredBytes > (CNtlXMLDoc::MAX_ATTRIBUTE_NAME_IN_WCHAR 1)
{
//NtlAssertFail("給定的屬性名稱太長了。");.
return false。
}
WCHAR pwszAttributeNameInWChar[CNtlXMLDoc::MAX_ATTRIBUTE_NAME_IN_WCHAR 1] 。
int nUsedBufferSize = MultiByteToWideChar(GetACP), 0, pszAttributeName, -1, pwszAttributeNameInWChar, (CNtlXMLDoc: :MAX_ATTRIBUTE_NAME_IN_WCHAR 1))。)
if (0 == nUsedBufferSize)
{
//NtlAssertFail("由于某些原因,給定的屬性名稱無法轉換為WCHAR型別。");
return false。
}
IXMLDOMNamedNodeMap* pMap = NULL;
pNode->get_attributes(&pMap)。
if (NULL == pMap)
{
//NtlAssertFail("無法從給定的IXMLDOMNode中獲取屬性串列。");.
return false。
}
IXMLDOMNode* pVirtualNode = NULL;
pMap->getNamedItem(pwszAttributeNameInWChar, &pVirtualNode)。
if (NULL == pVirtualNode)
{
//NtlAssertFail("無法找到給定的屬性名稱。");
return false。
}
VARIANT var;
VariantInit(&var)。
pVirtualNode->get_nodeValue(&var)。
nRequiredBytes = WideCharToMultiByte(:: GetACP(), 0, V_BSTR(& var), -1, pszResultText, 0, NULL, NULL)。)
if (nRequiredBytes > nBufferSizeInBytes)
{
//NtlAssertFail("緩沖區的大小不足以容納整個屬性值。");
return false。
}
WideCharToMultiByte(GetACP(), 0, V_BSTR(& var), -1, pszResultText, nBufferSizeInBytes, NULL, NULL)。)
return true。
}
bool CNtlXMLDoc:。 GetDataWithXPath(WCHAR* pwszXPath, WCHAR* pwszResultData, int nBufferSizeInWChars)
{
if (NULL == pwszXPath || NULL == pwszResultData || 0 >= nBufferSizeInWChars)
return false。
IXMLDOMNode* pNode = NULL;
m_pXMLDocument->selectSingleNode(pwszXPath, &pNode)。
if(!pNode)
return false。
BSTR bstr = NULL;
if (FAILED(pNode->get_text(&bstr))
{
::SysFreeString(bstr)。
pNode->Release()。
return false。
}
wcscpy_s(pwszResultData, nBufferSizeInWChars, bstr)。
::SysFreeString(bstr)。
pNode->Release()。
return true。
}
bool CNtlXMLDoc:。 GetDataWithXPath(char* pszXPath, char* pszResultData, int nBufferSizeInBytes)
{
if (NULL == pszXPath || NULL == pszResultData || 0 >= nBufferSizeInBytes)
return false。
WCHAR wszUnicodeXPath[1024 1] 。
int iRequiredChars = :: MultiByteToWideChar(GetACP(), 0, pszXPath, -1, NULL, 0)。)
if (_countof(wszUnicodeXPath) < iRequiredChars)
return false;
int iWrittenChars = :: MultiByteToWideChar(GetACP), 0, pszXPath, -1, wszUnicodeXPath, _countof(wszUnicodeXPath)) 。
if (0 == iWrittenChars)
return false;
wszUnicodeXPath[_countof(wszUnicodeXPath) - 1] = L''/span>;
WCHAR wszUnicodeResultData[1024 1] 。
if (false == GetDataWithXPath(wszUnicodeXPath, wszUnicodeResultData, _countof(wszUnicodeResultData))
return false。
iRequiredChars = :: WideCharToMultiByte(GetACP(), 0, wszUnicodeResultData, -1, NULL, 0, NULL, NULL)。
if (nBufferSizeInBytes < iRequiredChars)
return false;
iWrittenChars = :: WideCharToMultiByte(GetACP(), 0, wszUnicodeResultData, -1, pszResultData, nBufferSizeInBytes, NULL, NULL)。)
if (0 == iWrittenChars)
return false;
pszResultData[nBufferSizeInBytes - 1] = ''/span>;
return true。
}
/**.
* XML ??à?à? ?ü???| Tabà" 在這個程序中,我們可以看到,我們的檔案是由一個個不同的檔案組成的。
* param szIndentFileName á¤-??? "????ò ?o??à? ???? ??à??í。
* return ?o°? àˉ1"
*/
bool CNtlXMLDoc::SetIndent(WCHAR* szIndentFileName)
{
IXMLDOMDocument* pXSL = NULL;
CoCreateInstance(__uuidof(DOMDocument30), NULL, CLSCTX_INPROC_SERVER, __uuidof(XMLDOMDocument), (void**)& pXSL) 。
if(!pXSL)
return false。
VARIANT_BOOL vBool。
pXSL->put_async(VARIANT_FALSE)。
pXSL->load((_variant_t)szIndentFileName, & vBool);
VARIANT vObject;
VariantInit(&vObject)。
vObject.vt = VT_DISPATCH;
vObject.pdispVal = m_pXMLDocument;
m_pXMLDocument->transformNodeToObject(pXSL,vObject)。
if(pXSL)
{
pXSL->Release()。
pXSL = NULL。
}
return true。
}
IXMLDOMDocument* CNtlXMLDoc::GetDocument(void)
{
return m_pXMLDocument。
}
控制臺向我顯示的一些錯誤:
LNK2019 símbolo externo "public: bool __thiscall CNtlXMLDoc::GetTextWithAttributeName(struct IXMLDOMNode *,char *,char *,int)"/span> (? GetTextWithAttributeName@CNtlXMLDoc@@QAE_NPAUIXMLDOMNode@@PAD1H@Z),而不是在"protected: static int __cdecl CNtlScriptEncrypter::LoadConfigOptionXML(struct _SConfigData *,char *)"/span>(? LoadConfigOptionXML@CNtlScriptEncrypter@@KAHPAU_SConfigData@@PAD@Z)
我在VS 2019中使用MFC和VC Compiler 2010進行編譯。我認為我在專案屬性中鏈接了所有的庫和頭檔案。
我有大約23個錯誤,幾乎與上面的錯誤相同,都在同一個obj檔案中,并提到了NtlXMLDoc函式。
如果你能給我一些建議,那就太好了。謝謝!
這個專案不是我創建的,它是一段時間前發布的代碼,我正試圖修復它。uj5u.com熱心網友回復:
解決方案是:將包含NtlXMLDoc.cpp的專案添加到我的專案資源管理器中的參考中,因為,它們在同一個解決方案中,但卻是一個不同的專案,不知道為什么通過屬性不作業
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/317237.html
標籤:
