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

📄 adofiltr.cpp

📁 windows ce开发技巧与实例光盘代码
💻 CPP
字号:
/////////////////////////////////////////////////////////////////////////////
//
// AdoFiltr.cpp : Wrapper functions for the DESKTOPTODEVICE and
// DEVICETODESKTOP functions exported by ADOFILTR.DLL.
//
//
// Copyright (c) 2000-2001 Nathan Lewis
// nlewis@programmer.net
// http://www.ticz.com/~nlewis
//
//
// This program is free software; you can redistribute it and/or modify it
// so long as credit is given to the original author listed above.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include <tchar.h>
#include "AdoFiltr.h"


/////////////////////////////////////////////////////////////////////////////
// Local function prototypes

HMODULE LoadAdoFiltrDll();

HRESULT CallAdoFiltrFunc(LPCSTR pszFuncName, LPCTSTR pszDesktopLocn,
						 LPCTSTR pszTableList, BOOL bSync, BOOL bOverwrite,
						 LPCTSTR pszDeviceLocn);



/////////////////////////////////////////////////////////////////////////////
//
// DesktopToDevice - Wrapper function to load the ADOFILTR.DLL and call the
// DESKTOPTODEVICE function exported by it.
//
/////////////////////////////////////////////////////////////////////////////
HRESULT DesktopToDevice(LPCTSTR pszDesktopLocn,
						LPCTSTR pszTableList,
						BOOL bSync/* = FALSE*/,
						BOOL bOverwrite/* = TRUE*/,
						LPCTSTR pszDeviceLocn/* = NULL*/)
{
	return CallAdoFiltrFunc("DESKTOPTODEVICE", pszDesktopLocn, pszTableList,
		bSync, bOverwrite, pszDeviceLocn);
}


/////////////////////////////////////////////////////////////////////////////
//
// DeviceToDesktop - Wrapper function to load the ADOFILTR.DLL and call the
// DEVICETODESKTOP function exported by it.
//
/////////////////////////////////////////////////////////////////////////////
HRESULT DeviceToDesktop(LPCTSTR pszDesktopLocn,
						LPCTSTR pszTableList,
						BOOL bSync/* = FALSE*/,
						BOOL bOverwrite/* = TRUE*/,
						LPCTSTR pszDeviceLocn/* = NULL*/)
{
	return CallAdoFiltrFunc("DEVICETODESKTOP", pszDesktopLocn, pszTableList,
		bSync, bOverwrite, pszDeviceLocn);
}


/////////////////////////////////////////////////////////////////////////////
//
// LoadAdoFiltrDll - Attempts to load ADOFILTR.DLL from the directory CE
// Services / ActiveSync was installed into.
//
/////////////////////////////////////////////////////////////////////////////
HMODULE LoadAdoFiltrDll()
{
	HKEY hKey=NULL;
	HMODULE hLib=NULL;
	TCHAR szPath[MAX_PATH]={0};
	LONG lPath=sizeof(szPath);

	// Get path where CE Services / ActiveSync was installed from registry
	if(ERROR_SUCCESS==RegOpenKeyEx(HKEY_LOCAL_MACHINE,
		_T("Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\CEAPPMGR.EXE"),
		0, KEY_READ, &hKey))
	{
		if(ERROR_SUCCESS==RegQueryValue(hKey, NULL, szPath, &lPath))
		{
			// Replace the filename (CEAPPMGR.EXE) with DLL filename
			LPTSTR pFile=_tcsrchr(szPath, L'\\');

			if(pFile)
			{
				lstrcpy(_tcsinc(pFile), _T("adofiltr.dll"));

				// Now load the DLL
				hLib=LoadLibrary(szPath);
			}
		}

		RegCloseKey(hKey);
	}

	return hLib;
}


/////////////////////////////////////////////////////////////////////////////
//
// CallAdoFiltrFunc - Calls the specified AdoFiltr function (either
// DESKTOPTODEVICE or DEVICETODESKTOP) to transfer tables between the desktop
// and the device.
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CallAdoFiltrFunc(LPCSTR pszFuncName, LPCTSTR pszDesktopLocn,
						 LPCTSTR pszTableList, BOOL bSync, BOOL bOverwrite,
						 LPCTSTR pszDeviceLocn)
{
	// Start by loading the DLL
	HRESULT hResult=NO_ERROR;
	HMODULE hLib=LoadAdoFiltrDll();

	if(NULL==hLib)
		hResult=HRESULT_FROM_WIN32(GetLastError());
	else
	{
		// Get the address of the specified function within the DLL
		typedef HRESULT (WINAPI* pfnDTD)(LPCTSTR,LPCTSTR,BOOL,int,LPCTSTR);

		pfnDTD pfn=(pfnDTD)GetProcAddress(hLib, pszFuncName);

		if(NULL==pfn)
			hResult=HRESULT_FROM_WIN32(GetLastError());
		else
		{
			// Call the function
			hResult=pfn(pszDesktopLocn, pszTableList, bSync, bOverwrite,
				pszDeviceLocn);
		}

		// Unload the DLL
		FreeLibrary(hLib);
	}

	return hResult;
}

⌨️ 快捷键说明

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