⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapxds.cpp

📁 mapx程序的源代码
💻 CPP
字号:
// MapXDS.cpp : Implementation of DLL Exports.


// Note: Proxy/Stub Information
//		To build a separate proxy/stub DLL, 
//		run nmake -f MapXDSps.mk in the project directory.

#include "stdafx.h"
#include "resource.h"
#include "initguid.h"
#include "MapXDS.h"

#include "MapXDS_i.c"
#include "MapXDataset.h"
#include "MDatasetInt.iid"
#include "MMapXColumnInfo.iid"

bool RegisterDatasetDriver(void);
bool UnregisterDatasetDriver(void);

CComModule _Module;

BEGIN_OBJECT_MAP(ObjectMap)
	OBJECT_ENTRY(CLSID_MapXSampleDataset, CMapXSampleDataset)
END_OBJECT_MAP()

class CMapXDSApp : public CWinApp
{
public:
	virtual BOOL InitInstance();
	virtual int ExitInstance();
};

CMapXDSApp theApp;

BOOL CMapXDSApp::InitInstance()
{
	_Module.Init(ObjectMap, m_hInstance);
	return CWinApp::InitInstance();
}

int CMapXDSApp::ExitInstance()
{
	_Module.Term();
	return CWinApp::ExitInstance();
}

/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLE

STDAPI DllCanUnloadNow(void)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
}

/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested type

STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
	return _Module.GetClassObject(rclsid, riid, ppv);
}

/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry

STDAPI DllRegisterServer(void)
{
	RegisterDatasetDriver();
	return _Module.RegisterServer(TRUE);
}

/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry

STDAPI DllUnregisterServer(void)
{
	UnregisterDatasetDriver();
	_Module.UnregisterServer();
	return S_OK;
}


#define MAPX_REGISTRY_KEY _T("Software\\MapInfo\\MapX\\DatasetEngines\\")
#define DE_LOCATION_REGVALUE _T("DE_CLSID") 

/////////////////////////////////////////////////////////////////////////////
// RegisterDatasetDriver - Adds entry to the MapX registry
bool RegisterDatasetDriver(void)
{
	wchar_t awchCLSID[256];
	TCHAR achCLSID[256];
	HRESULT hrRet = S_OK;
	GUID guid = CLSID_MapXSampleDataset;
	try {
		HRESULT hr = StringFromGUID2(guid, (LPOLESTR)awchCLSID, sizeof(wchar_t)*256);
		if(FAILED(hr)) throw hr;
		WideCharToMultiByte(CP_ACP, NULL, awchCLSID, -1, (char*)achCLSID,
			sizeof(TCHAR)*256, NULL, NULL);
		HKEY hDEBaseKey;
		long lErr = RegCreateKey(HKEY_LOCAL_MACHINE, MAPX_REGISTRY_KEY, &hDEBaseKey);
		if (lErr!=ERROR_SUCCESS) throw E_FAIL;
		// We store the type as the key name.. so format a string with its value
		CString strDEID;
		strDEID.Format("%d", DATASETENGINE_ID);
		HKEY hDEKey;
		// Create our own very special key
		lErr = RegCreateKey(hDEBaseKey, strDEID, &hDEKey);
		// don't need the Base key anymore
		RegCloseKey(hDEBaseKey); 
		if (lErr!=ERROR_SUCCESS) throw E_FAIL;
		int iValueLengthBytes=(_tcsnbcnt(achCLSID,_tcslen(achCLSID))+sizeof(TCHAR));
		lErr=RegSetValueEx(hDEKey, DE_LOCATION_REGVALUE, 0, REG_SZ, 
							(LPBYTE)achCLSID, iValueLengthBytes);
		if (lErr!=ERROR_SUCCESS) throw E_FAIL;
	}
	catch( HRESULT hrThrown ) {
		hrRet = hrThrown;
	}
	
	return(hrRet==S_OK) ? true : false;
}

/////////////////////////////////////////////////////////////////////////////
// UnregisterDatasetDriver - Removes entry to the MapX registry
bool UnregisterDatasetDriver(void)
{
	wchar_t awchCLSID[256];
	TCHAR achCLSID[256];
	HRESULT hrRet = S_OK;
	GUID guid = CLSID_MapXSampleDataset;
	try {
		HRESULT hr = StringFromGUID2(guid, (LPOLESTR)awchCLSID, sizeof(wchar_t)*256);
		if(FAILED(hr)) throw hr;
		WideCharToMultiByte(CP_ACP, NULL, awchCLSID, -1, (char*)achCLSID,
			sizeof(TCHAR)*256, NULL, NULL);
		HKEY hDEBaseKey;
		long lErr = RegOpenKey(HKEY_LOCAL_MACHINE, MAPX_REGISTRY_KEY, &hDEBaseKey);
		if (lErr!=ERROR_SUCCESS) throw E_FAIL;
		// We store the type as the key name.. so format a string with its value
		CString strDEID;
		strDEID.Format("%d", DATASETENGINE_ID);
		// Delete our own very special key
		lErr = RegDeleteKey(hDEBaseKey, strDEID);
		if (lErr!=ERROR_SUCCESS) throw E_FAIL;
	}
	catch( HRESULT hrThrown ) {
		hrRet = hrThrown;
	}
	
	return(hrRet==S_OK) ? true : false;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -