xmlReadMemory - unknown 'url' parameter - c++

I have my xml as char buffer (that's fetched from server, I don't want to save it -> takes extra time and is completely obsolete):
char myword[] = "...xml..."
xmlSchemaParserCtxtPtr ctxt = xmlSchemaNewParserCtxt(xsdFilePath);
xmlDocPtr doc = ?;
Now I need to get doc. I'm trying to use following function:
doc = xmlReadMemory(myword, sizeof(myword), ?URL?, NULL, 0)
But the problem is with URL, what should I put in there..? Am I using this function right? Maybe there is another way to get xmlDocPtr?
BTW: I need xmlDocPtr to perform:
ret = xmlSchemaValidateDoc(ctxt, doc);

Simply pass a NULL pointer:
doc = xmlReadMemory(myword, sizeof(myword), NULL, NULL, 0);

Related

Reforging (Rochet2) to AzerothCore

Does anyone has already successfully added Rochet2's Reforging script on AC ?
Mine works but not completely.
On character login the script should re-apply bonuses on reforged (& equipped) items, but it seems "player->GetItemByGuid()" can't find the requested item, so it's returning nothing.
TrinityCore code (works) :
uint32 lowGUID = (*result)[0].GetUInt32();
Item* invItem = player->GetItemByGuid(ObjectGuid(HighGuid::Item, 0, lowGUID));
if (invItem)
player->_ApplyItemMods(invItem, invItem->GetSlot(), false);
ReforgeData& data = player->reforgeMap[lowGUID];
data.increase = (*result)[1].GetUInt32();
data.decrease = (*result)[2].GetUInt32();
data.stat_value = (*result)[3].GetInt32();
if (invItem)
player->_ApplyItemMods(invItem, invItem->GetSlot(), true);
AzerothCore code (works, but "if (invItem)" condition never satisfied.
uint32 lowGUID = (*result)[0].GetUInt32();
Item* invItem = player->GetItemByGuid((uint64) MAKE_NEW_GUID(HIGHGUID_ITEM, 0, lowGUID));
if (invItem /*&& invItem->IsEquipped()*/)
player->_ApplyItemMods(invItem, invItem->GetSlot(), false);
ReforgeData& data = player->reforgeMap[lowGUID];
data.increase = (*result)[1].GetUInt32();
data.decrease = (*result)[2].GetUInt32();
data.stat_value = (*result)[3].GetInt32();
if (invItem /*&& invItem->IsEquipped()*/)
player->_ApplyItemMods(invItem, invItem->GetSlot(), true);
MAKE_NEW_GUID() returns something that looks like a guid.
But I don't know why "player->GetItemByGuid()" can't find the item.
The order of arguments to MAKE_NEW_GUID is different from ObjectGuid constructor. So since your arguments are in wrong order then the result is also wrong and item is not found. See the definition and use of MAKE_NEW_GUID for the correct order of arguments.

Insert raw file data into BLOB ("OLE Object") field of Access table using ADO

I am trying to insert a file into MS Access database, into a field of OLE Object type. I am using C++ and ADO.
Currently I get error Invalid pointer error.
I think that my problem is mishandling variants since this is the first time I use them. I am learning from this code example but have problem understanding how to insert file from disk into variant.
They read it from database, and copied it into new record so the part where I read file from disk and then insert it into variant is missing.
I am firing off my code in GUI when menu item is selected. Database has one table named test with fields ID which is primary key and field which is of OLE Object type.
After searching online I have found nothing that can help me.
Here is smallest code snippet possible that illustrates the problem ( error checking is minimal):
wchar_t *bstrConnect = L"Provider=Microsoft.ACE.OLEDB.12.0; \
Data Source = C:\\Users\\Smiljkovic85\\Desktop\\OLE.accdb";
try
{
HRESULT hr = CoInitialize(NULL);
// connection
ADODB::_ConnectionPtr pConn(L"ADODB.Connection");
// recordset
ADODB::_RecordsetPtr pRS(L"ADODB.Recordset");
// connect to DB
hr = pConn->Open(bstrConnect, L"admin", L"", ADODB::adConnectUnspecified);
// open file
std::ifstream in(L"C:\\Users\\Smiljkovic85\\Desktop\\file.pdf",
std::ios::ate | std::ios::binary);
// get file size
int fileSize = in.tellg();
// here I tried to adapt code from the example linked above
pRS->Open(L"test", _variant_t((IDispatch*)pConn, true),
ADODB::adOpenKeyset, ADODB::adLockOptimistic, ADODB::adCmdTable);
// add new record
pRS->AddNew();
// copy pasted
_variant_t varChunk;
SAFEARRAY FAR *psa;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
// modify to our file size
rgsabound[0].cElements = fileSize;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
//=================== try to add file into variant
char *chData = (char *)psa->pvData;
chData = new char[fileSize];
in.read(chData, fileSize);
/* ============= I have even tried the following :
char *chData = new char[fileSize];
in.read(chData, fileSize);
BYTE* pData;
SafeArrayAccessData(psa, (void **)&pData);
memcpy(pData, chData, fileSize);
SafeArrayUnaccessData(psa);
===============*/
//=================================================
// Assign the Safe array to a variant.
varChunk.vt = VT_ARRAY | VT_UI1;
varChunk.parray = psa;
pRS->Fields->GetItem(L"field")->AppendChunk(varChunk);
// add this record into DB
pRS->Update();
// cleanup
delete[] chData;
in.close();
pRS->Close();
pConn->Close();
CoUninitialize();
}
catch (_com_error e)
{
MessageBox(hWnd, (LPWSTR)e.Description(), L"", 0);
}
Can you help me to modify this code snippet so I can insert file into variant?
EDIT:
I have searched here for help and two posts that gave me an idea. Still none of my solutions work. You can see them in the above code snippet, in the comments.
What I get now, is the following error: a problem occurred while microsoft access was communicating with the ole server or activex control in MS Access. I have searched online for solution but had no luck, every link claims it has to do with access and not with the code.
Please help...
Since you are already using ADODB.Connection and ADODB.Recordset objects you should be able to use a binary ADODB.Stream object to manipulate the file contents with
.LoadFromFile to fill the Stream with the file contents, and
.Read to pull it back out of the Stream and store it in the database field.
Unfortunately I cannot offer a C++ example, but in VBA the code would be:
Dim con As ADODB.Connection, rst As ADODB.Recordset, strm As ADODB.Stream
Set con = New ADODB.Connection
con.Open _
"Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=C:\Users\Public\Database1.accdb"
Set rst = New ADODB.Recordset
rst.Open "test", con, adOpenKeyset, adLockOptimistic, adCmdTable
Set strm = New ADODB.Stream
strm.Type = adTypeBinary
strm.Open
strm.LoadFromFile "C:\Users\Gord\Desktop\test.pdf"
rst.AddNew
strm.Position = 0
rst.Fields("FileData").Value = strm.Read
rst.Update
rst.Close
Set rst = Nothing
con.Close
Set con = Nothing
strm.Close
Set strm = Nothing

Using UpdateResource with StringTables in C++

I need to edit the resources of a file in C++ using UpdateResource(), however I am unsure on how to go about getting the data for the 5th parameter (lpData).
I have no idea about how to create the data that needs to be provided for the function and the structure of the data, Can anybody provide guidance on how to go about getting/creating the data?
Simply you can use:
wchar_t wszMyText[] = L"Some text";
HANDLE hUpdate = BeginUpdateResourceW( L"/path/to/file", FALSE );
// test return value.
BOOL res = UpdateResourceW( hUpdate, RT_STRING, L"MyResource", wszMyText,
sizeof(wszMyText) - sizeof(wchar_t);
// check return value
EndUpdateResource( hUpdate, FALSE );

InternetCrackUrl not returning lpszHostName properly

I am developing a plugin for NSIS (Unicode) and I am trying to use InternetCrackUrl() to get the hostname of a URL (ie: http://www.google.com/test.html -> www.google.com) but instead of lpszHostName just returning "www.google.com", it returns "www.google.com/test.html".
Here is my code:
void __declspec(dllexport) Example(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) {
g_hwndParent=hwndParent;
EXDLL_INIT();
LPWSTR szURI = new WCHAR[string_size];
URL_COMPONENTS urlComp;
// Sets szURI to "http://www.xyz.com/test.html"
popstring(szURI);
wstring strUri = szURI;
ZeroMemory(&urlComp, sizeof(urlComp));
urlComp.dwStructSize = sizeof(urlComp);
// Set required component lengths to non-zero so that they are cracked.
urlComp.dwHostNameLength = static_cast<DWORD>(-1);
urlComp.dwSchemeLength = static_cast<DWORD>(-1);
urlComp.dwUrlPathLength = static_cast<DWORD>(-1);
urlComp.dwExtraInfoLength = static_cast<DWORD>(-1);
if (!InternetCrackUrlW(strUri.c_str(), strUri.length(), 0, &urlComp)) {
return _T("InternetCrackUrl failed");
}
// urlComp.lpszHostName = www.xyz.com/test.html
}
Any ideas?
If you don't provide your own buffer InternetCrackUrl will return pointers to characters in the original string you pass as input. It doesn't copy the string.
So, lpszHostName will point to the first character, and dwHostNameLength will give you the number of chars that make the host name.
That is the expected behavior.
Because when you say www.google.com it translates to http://www.google.com/test.html.
The URL is really www.google.com/test.html which is what is returned.
To get what you need, you will need to do some string manipulation.
You could use the strrchr function or the find_first_of method of the std::string class.

Unable to set Reporting Services Parameters

I'm generating a reporting services report from an ASP.NET (MVC) based application but am having problems setting the parameters for the report.
I believe the issue has only occurred since we upgraded SQL Server from 2005 to 2008 R2 (and Reporting Services along with it).
The original error encountered was from calling rsExec.Render:
Procedure or function 'pCommunication_ReturnRegistrationLetterDetails'
expects parameter '#guid', which was not supplied.
Debugging the code I noticed that rsExec.SetExecutionParameters is returning the following response:
Cannot call 'NameOfApp.SQLRSExec.ReportExecutionService.SetExecutionParameters(NameOfApp.SQLRSExec.ParameterValue[],
string)' because it is a web method.
Here is the function in it's entirety:
public static bool ProduceReportToFile(string reportname, string filename, string[,] reportparams,
string fileformat)
{
bool successful = false;
SQLRS.ReportingService2005 rs = new SQLRS.ReportingService2005();
SQLRSExec.ReportExecutionService rsExec = new NameOfApp.SQLRSExec.ReportExecutionService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Prepare Render arguments
string historyID = null;
string deviceInfo = null;
// Prepare format - available options are "PDF","Word","CSV","TIFF","XML","EXCEL"
string format = fileformat;
Byte[] results;
string encoding = String.Empty;
string mimeType = String.Empty;
string extension = String.Empty;
SQLRSExec.Warning[] warnings = null;
string[] streamIDs = null;
// Define variables needed for GetParameters() method
// Get the report name
string _reportName = reportname;
string _historyID = null;
bool _forRendering = false;
SQLRS.ParameterValue[] _values = null;
SQLRS.DataSourceCredentials[] _credentials = null;
SQLRS.ReportParameter[] _parameters = null;
// Get if any parameters needed.
_parameters = rs.GetReportParameters(_reportName, _historyID,
_forRendering, _values, _credentials);
// Load the selected report.
SQLRSExec.ExecutionInfo ei =
rsExec.LoadReport(_reportName, historyID);
// Prepare report parameter.
// Set the parameters for the report needed.
SQLRSExec.ParameterValue[] parameters =
new SQLRSExec.ParameterValue[1];
// Place to include the parameter.
if (_parameters.Length > 0)
{
for (int i = 0; i < _parameters.Length; i++)
{
parameters[i] = new SQLRSExec.ParameterValue();
parameters[i].Label = reportparams[i,0];
parameters[i].Name = reportparams[i, 0];
parameters[i].Value = reportparams[i, 1];
}
}
rsExec.SetExecutionParameters(parameters, "en-us");
results = rsExec.Render(format, deviceInfo,
out extension, out encoding,
out mimeType, out warnings, out streamIDs);
// Create a file stream and write the report to it
using (FileStream stream = System.IO.File.OpenWrite(filename))
{
stream.Write(results, 0, results.Length);
}
successful = true;
return successful;
}
Any ideas why I'm now unable to set parameters? The report generation works without issue if parameters aren't required.
Looks like it may have been an issue with how reporting services passes parameters through to the stored procedure providing the data. A string guid was being passed through to the report and the stored procedure expected a varchar guid. I suspect reporting services may have been noticing the string followed the guid format pattern and so passed it through as a uniqueidentifier to the stored procedure.
I changed the data source for the report from "stored procedure" to "text" and set the SQL as "EXEC pMyStoredOProcName #guid".
Please note the guid being passed in as a string to the stored procedure is probably not best practice... I was simply debugging an issue with another developers code.
Parameter _reportName cannot be null or empty. The [CLASSNAME].[METHODNAME]() reflection API could not create and return the SrsReportNameAttribute object
In this specific case it looks like an earlier full compile did not finish.
If you encounter this problem I would suggest that you first compile the class mentioned in the error message and see if this solves the problem.
go to AOT (get Ctrl+D)
in classes find CLASSNAME
3.compile it (F7)