VC++.NET做了一个小程序,自动把其它的通讯薄(比如D:/PXALL.WAB)添加入OUTLOOKEXPRESS的通讯薄中.程序是非托管的不必CLR支持的WIN32程序,在VS2005中正常调试,但是运行生成的.EXE则出现异常!!请高人指点!!!
// updateOutlookExpress.cpp : 定义应用程序的入口点。
//
#include "stdafx.h"
#include "wab.h"
#include "Wabapi.h"
#include "updateOutlookExpress.h"
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTRlpCmdLine,
int nCmdShow)
{
LPWABOPEN lpfnWABOpen = NULL;
// Defined in Wabapi.h.
//LPWABIMPORT
HINSTANCE hinstWAB = NULL;
LPWABOBJECT lppWABObject;
LPADRBOOK lppAdrBook;
HRESULT hr = E_FAIL;
LPWABIMPORTPARAM lpWABParam;
TCHARszWABDllPath[MAX_PATH];
DWORDdwType = 0;
ULONGcbData = sizeof(szWABDllPath);
HKEY hKey = NULL;
*szWABDllPath = '\0';
// First we look under the default WAB DLL path location in the
// Registry.
// WAB_DLL_PATH_KEY is defined in wabapi.h
//
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &hKey))
RegQueryValueEx( hKey, L"", NULL, &dwType, (LPBYTE) szWABDllPath, &cbData);
if(hKey) RegCloseKey(hKey);
// if the Registry came up blank, we do a loadlibrary on the wab32.dll
// WAB_DLL_NAME is defined in wabapi.h
hinstWAB = LoadLibrary( (lstrlen(szWABDllPath)) ? szWABDllPath : WAB_DLL_NAME );
//hinstWAB = LoadLibrary(L"c:\\Program Files\\Common Files\\System\\wab32"
;
if (hinstWAB)
{
lpfnWABOpen = (LPWABOPEN) GetProcAddress(hinstWAB, "WABOpen"
;
if (lpfnWABOpen)
{
hr = lpfnWABOpen (&lppAdrBook, &lppWABObject,NULL, 0);
if (hr != S_OK) {
MessageBox(NULL,L"Outlook Express 通讯薄更新失败!",L"Update",MB_OK);
exit(1);
}
lpWABParam=(LPWABIMPORTPARAM)(malloc(sizeof(WABIMPORTPARAM)));
lpWABParam->lpszFileName="d:\\pxall.wab";//"\\\\webproxy\\芳烃\\pxall.wab";
lpWABParam->lpAdrBook=lppAdrBook;
//GetProcAddress(hinstWAB, "WABIMP_IMPORT_WAB"
;
hinstWAB=LoadLibrary(L"C:\\Program Files\\Outlook Express\\wabimp.dll"
;
lppWABObject->Release();
HRESULT res=lppWABObject->Import((LPSTR)lpWABParam);
if(res!=S_OK){
MessageBox(NULL,L"Outlook Express 通讯薄更新失败!",L"Update",MB_OK);
exit(1);
}
}
}
MessageBox(NULL,L"Outlook Express 通讯薄更新完成!",L"Update",MB_OK);
FreeLibrary(hinstWAB);
return 1;
}
|