MinGW和MSVC崩溃信息收集快捷DLL
MinGW/QT - Release:
QMAKE_CXXFLAGS_RELEASE += -g
QMAKE_CFLAGS_RELEASE += -g
QMAKE_LFLAGS_RELEASE = -mthreads
可选项:
QMAKE_CFLAGS_RELEASE -= -O2
QMAKE_CXXFLAGS_RELEASE -= -O2
MSVC - Release:
Generate Debug Information optimized for sharing and publishing (/DEBUG:FULL)
使用简单,自己的代码入口函数加入即可:
if (sizeof(void*) == sizeof(unsigned long))
{
::LoadLibraryW(L"D:\\CPCR32.DLL");
}
else
{
::LoadLibraryW(L"D:\\CPCR64.DLL");
}
调用工程资源示例代码:
class CrashStart
{
public:
static CrashStart* Inst(UINT uResID, LPCWSTR lpcwTypeName)
{
static CrashStart CrashStartInstance(uResID, lpcwTypeName);
return(&CrashStartInstance);
}
private:
CrashStart(UINT uResID, LPCWSTR lpcwTypeName)
{
StartupCrashed(uResID, lpcwTypeName);
}
virtual ~CrashStart()
{
CleanupCrashed();
}
HMODULE m_CrashDll = NULL;
int StartupCrashed(UINT uResID, LPCWSTR lpcwTypeName)
{
HRSRC hDll = NULL;
HGLOBAL pDll = NULL;
hDll = ::FindResourceW(::GetModuleHandleW(NULL), MAKEINTRESOURCEW(uResID), lpcwTypeName);
if (hDll != NULL)
{
DWORD dwResLen = ::SizeofResource(::GetModuleHandleW(NULL), hDll);
pDll = ::LoadResource(::GetModuleHandleW(NULL), hDll);
if (pDll != NULL)
{
WCHAR wTempFile[MAX_PATH] = { 0 };
::GetTempPathW(MAX_PATH, wTempFile);
::wsprintfW(wTempFile, L"%scrash.%d", wTempFile, uResID);
FILE* fp = _wfopen(wTempFile, L"wb");
if (fp != NULL)
{
fwrite(pDll, dwResLen, 1, fp);
fclose(fp);
}
m_CrashDll = ::LoadLibraryW(wTempFile);
::FreeResource(pDll);
if (m_CrashDll != NULL)
{
return (0);
}
}
}
return (-1);
}
int CleanupCrashed()
{
if (m_CrashDll != NULL)
{
::FreeLibrary(m_CrashDll);
m_CrashDll = NULL;
return (0);
}
return (-1);
}
};
在main中调用:
CrashStart::Inst((sizeof(unsigned long) == sizeof(void*))?33333:44444, L"IDRBMP");