I am trying to execute the imgSessionSaveBufferEx function:
I would like to save an image into PNG format, what should I input as the parameter for Int8* file_name?
imgSessionSaveBufferEx(sessionID, NULL, ______);
The sequence of attempts are below:
imgSessionSaveBufferEx(sessionID, NULL, "test.png");
imgSessionSaveBufferEx(sessionID, NULL, reinterpret_cast<Int8*>("test.png"));
// this is the answer, provided by Botje
imgSessionSaveBufferEx(sessionID, NULL, reinterpret_cast<Int8*>(const_cast<char *>("test.png")));
Related
I am writing a CLR profiler using the ICorProfilerInfo interface.
When using SetEnterLeaveFunctionHooks, the callback methods are passed a FunctionID.
How do I get the metadata (I am after the name in particular), of a function given this FunctionID?
An MSDN article suggests that the first call should be to GetFunctionInfo. The documentation for this function states:
The profiler code can call ICorProfilerInfo::GetModuleMetaData to obtain a metadata interface for a given module. The metadata token that is returned to the location referenced by pToken can then be used to access the metadata for the function.
It does not elaborate on the last sentence ('the metadata token ... can be used to access metadata for the function').
How does this work?
So far, I am doing the following:
void MyProfiler::EnterMethod(FunctionID functionID)
{
ClassID classId = 0;
ModuleID moduleId = 0;
mdToken metaDataToken = 0;
IMetaDataImport* metaDataImport = NULL;
// (m_info is ICorProfilerInfo3)
m_info->GetFunctionInfo(functionID, &classId, &moduleId, &metaDataToken);
m_info->GetModuleMetaData(moduleId, ofRead, IID_IMetaDataImport, (IUnknown**)&metaDataImport);
// What goes here?
}
I have tried to call GetTypeRefProps like this:
mdToken ptkResolutionScope;
WCHAR szName[1024];
ULONG cchName = 1024;
ULONG pchName;
HRESULT result = MetaDataImport->GetTypeRefProps(pToken, &ptkResolutionScope, szName, cchName, &pchName);
The final call returns S_FALSE, and does not populate szName.
GetTypeRefProps is only applicable when your token is a TypeRef token, GetFunctionInfo will give you a MethodDef token which requires you to use the GetMethodProps method.
metaDataImport->GetMethodProps(metaDataToken, NULL, szName, cchName, &pchName, NULL, NULL, NULL, NULL, NULL);
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);
I was tring to use SymEnumSourceFiles to get the file name within the debugging module.But the file name as a parameter in the callback function seems incomplete. e.g. A file named"c:\program files\test\test.cpp" only showed "c:\program fi" in the FileName part of the PSOURCEFILE type parameter, and that's very wired.
Here is my code:
struct foo
{
static BOOL CALLBACK run( PSOURCEFILE pSourceFile, PVOID UserContext)
{
static TCHAR szFileName[MAX_PATH] = _T("");
if (_tcscmp(szFileName, pSourceFile->FileName))
{
_tcscpy(szFileName, pSourceFile->FileName);
}
return TRUE;
}
};
HANDLE hCurrentProcess = GetCurrentProcess();
SymInitialize(hCurrentProcess, NULL, FALSE);
DWORD64 BaseOfDll = SymLoadModule64(hCurrentProcess,
NULL,
(LPCSTR)_bstr_t(lpszFile),
NULL,0,0);
if(!SymEnumSourceFiles(hCurrentProcess, BaseOfDll, NULL, foo::run, (PVOID)pCallBack))
{
ATLTRACE(_T(__FUNCTION__) _T(" error:0x%x\n"), GetLastError());
}
SymUnloadModule64(hCurrentProcess, BaseOfDll);
SymCleanup(hCurrentProcess);
Can anyone tell me where I go wrong please?
PS. When I simply replace SymEnumSourceFiles with SymEnumLines and change the callback function, the file name I got is correct.
There used to be a bug with SymEnumSymbols where symbol name was not zero terminated, maybe this one is related. Try zeroing out the filename after copying it (pSourceFile->FileName[0] = 0;).
Try ANSI version of SymEnumSourceFiles. There seems to be a bug in SymEnumSourceFilesW function.
I'm trying to use CreateProcess to open a game .exe but I'm having the unhandled exception error. I already figured out the problem and the solution, but I need to get the path for the second parameter of CreateProcess from a file dialog box (that part is done and works). The problem is:
For the second parameter of CreateProcess, I need to declare a variable with the value to it (the 2nd param), but if I "point" it to the variable of the path to the file selected in the file dialog box, it doesn't work anymore.
I'm sorry if this is a really dumb question, but I'm starting in C++.
The code that works is here:
wchar_t szGameDir[] = L"PATH_TO_EXE";
if ( CreateProcess (
NULL,
szGameDir, NULL, NULL, FALSE,
CREATE_UNICODE_ENVIRONMENT,
NULL, NULL,
&pstStartupInfo, &pstProcInfo ) )
But when I set szGameDir to the value of 'pszGameDir' (path to the EXE selected by the user), it gives the unhandled exception error...
wchar_t* szGameDir = pszGameDir;
if ( CreateProcess (
NULL,
szGameDir, NULL, NULL, FALSE,
CREATE_UNICODE_ENVIRONMENT,
NULL, NULL,
&pstStartupInfo, &pstProcInfo ) )
And this is where I initialize 'pszGameDir':
OPENFILENAME DialogBox;
ZeroMemory ( &DialogBox, sizeof(DialogBox) );
DialogBox.lStructSize = sizeof(OPENFILENAME);
DialogBox.hwndOwner = NULL;
DialogBox.lpstrFilter = L"Grand Theft Auto: Vice City (*.exe)\0*.exe\0";
DialogBox.lpstrFile = (LPTSTR)this->pszGameDir;
DialogBox.nMaxFile = MAX_PATH;
DialogBox.nMaxFileTitle = sizeof ( L"gta-vc.exe" );
DialogBox.lpstrTitle = L"Please, select 'gta-vc.exe'";
DialogBox.Flags = 0x02000000 | 0x00001000 | 0x00000400 | 0x10000000 | 0x00020000 | 0x00000800 | 0x0000008;
DialogBox.nFileExtension = (WORD)"exe";
DialogBox.lpstrDefExt = L"exe";
return GetOpenFileName ( &DialogBox ) != 0 ? 1 : NULL;
Can someone help me? (Yes, I did search already, but honestly I haven't found about this specific thing, I wasn't able to fix it either..)
CreateProcess needs the command line parameter to be writeable. Read the description of the argument at MSDN:
The Unicode version of this function, CreateProcessW, can modify the contents of this string. Therefore, this parameter cannot be a pointer to read-only memory (such as a const variable or a literal string). If this parameter is a constant string, the function may cause an access violation.
It has to be writeable, I am afraid.
I've looked for examples and documentation, but I still can't figure this out...
How do you use RegQueryValueEx (not the PdhXxx functions) to query for something like Disk Bytes/sec?
I've tried the following:
DWORD type;
static union { TCHAR Data[32 * 1024]; PERF_DATA_BLOCK Perf; } perf;//Stack buffer
DWORD cbData = sizeof(perf);
LSTATUS s = RegQueryValueEx(HKEY_PERFORMANCE_DATA,
_T("PhysicalDisk"), NULL, &type, (LPBYTE)&perf, &cbData);
PPERF_OBJECT_TYPE pObjType =
(PPERF_OBJECT_TYPE)((BYTE*)&perf + perf.Perf.HeaderLength);
but it just returns a header with no data. :(
You can't query for the data by name like that. Instead, you need to query by index. MSDN can help you with some code to find out the appropriate index to query. Unfortunately, you need to make the determination of which index at run-time.
For example, the following SHOULD retrieve the performance data for the processor.
LSTATUS s = RegQueryValueEx(HKEY_PERFORMANCE_DATA, _T("238"), NULL,
&type, (LPBYTE)&perf, &cbData);