|
|
// dllmain.cpp : 定义 DLL 的初始化例程。
|
|
|
//
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
#include <afxwin.h>
|
|
|
#include <afxdllx.h>
|
|
|
#include "FltDensityAnalyzer.h"
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
#define new DEBUG_NEW
|
|
|
#endif
|
|
|
|
|
|
static AFX_EXTENSION_MODULE FaultDensityLibDLL = { NULL, NULL };
|
|
|
|
|
|
extern "C" int APIENTRY
|
|
|
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
|
|
|
{
|
|
|
// 如果使用 lpReserved,请将此移除
|
|
|
UNREFERENCED_PARAMETER(lpReserved);
|
|
|
|
|
|
if (dwReason == DLL_PROCESS_ATTACH)
|
|
|
{
|
|
|
TRACE0("FaultDensityLib.DLL 正在初始化!\n");
|
|
|
|
|
|
// 扩展 DLL 一次性初始化
|
|
|
if (!AfxInitExtensionModule(FaultDensityLibDLL, hInstance))
|
|
|
return 0;
|
|
|
|
|
|
// 将此 DLL 插入到资源链中
|
|
|
// 注意: 如果此扩展 DLL 由
|
|
|
// MFC 规则 DLL (如 ActiveX 控件)隐式链接到,
|
|
|
// 而不是由 MFC 应用程序链接到,则需要
|
|
|
// 将此行从 DllMain 中移除并将其放置在一个
|
|
|
// 从此扩展 DLL 导出的单独的函数中。 使用此扩展 DLL 的
|
|
|
// 规则 DLL 然后应显式
|
|
|
// 调用该函数以初始化此扩展 DLL。 否则,
|
|
|
// CDynLinkLibrary 对象不会附加到
|
|
|
// 规则 DLL 的资源链,并将导致严重的
|
|
|
// 问题。
|
|
|
|
|
|
new CDynLinkLibrary(FaultDensityLibDLL);
|
|
|
|
|
|
}
|
|
|
else if (dwReason == DLL_PROCESS_DETACH)
|
|
|
{
|
|
|
TRACE0("FaultDensityLib.DLL 正在终止!\n");
|
|
|
|
|
|
// 在调用析构函数之前终止该库
|
|
|
AfxTermExtensionModule(FaultDensityLibDLL);
|
|
|
}
|
|
|
return 1; // 确定
|
|
|
}
|
|
|
|
|
|
extern "C" __declspec(dllexport)
|
|
|
double CalculateFaultDensity(LPCTSTR drawFile, LPCTSTR faultLayer, LPCTSTR borderLayer
|
|
|
, double gridWidth, double gridHeight, double minFltLength
|
|
|
, bool includeSubLayers, bool byRealArea
|
|
|
, LPCTSTR distributionFile, LPCTSTR polygonsFile)
|
|
|
{
|
|
|
CFltDensityAnalyzer fda;
|
|
|
|
|
|
fda.ReadFltFile(drawFile);
|
|
|
fda.ReadFlts(faultLayer, includeSubLayers);
|
|
|
fda.ReadBorder(borderLayer);
|
|
|
|
|
|
fda.SetOutputPaths(distributionFile, polygonsFile);
|
|
|
fda.SetGrid(gridWidth, gridHeight);
|
|
|
fda.m_minFltLength = minFltLength;
|
|
|
fda.m_bCalcWithRealArea = byRealArea;
|
|
|
double dReturn = fda.CalcDensity();
|
|
|
if (distributionFile != NULL) {
|
|
|
fda.WriteGridFltsInfo();
|
|
|
}
|
|
|
if (polygonsFile != NULL) {
|
|
|
fda.WriteCellPolygons();
|
|
|
}
|
|
|
return dReturn;
|
|
|
} |