链接错误。CLSID_Application和IID_IPOutlookApp。
#include "stdafx.h"
#include "Contact.h"
#include "resourceppc.h"
#define INITGUID
#include <pimstore.h>
#pragma comment(lib,"pimstore.lib")
#define RELEASE_STRING(s) if (s){SysFreeString(s);}
#define RELEASE_IO(s) if (s){s->Release();s=NULL;}
HINSTANCE g_hInst;
LRESULT CALLBACK ContactDlgProc(HWND, UINT, WPARAM, LPARAM);
void ButtonWrite();
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
g_hInst=hInstance;
DialogBox(g_hInst,MAKEINTRESOURCE(IDD_DIALOG_CONTACT),NULL,(DLGPROC)ContactDlgProc);
return 1;
}
LRESULT CALLBACK ContactDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
static SHACTIVATEINFO s_sai;
switch (message)
{
case WM_INITDIALOG:
{
SetWindowText(hWnd,L"Contact");
SHINITDLGINFO shidi={0};
shidi.dwMask=SHIDIM_FLAGS;
shidi.dwFlags=SHIDIF_SIZEDLGFULLSCREEN|SHIDIF_CANCELBUTTON;
shidi.hDlg=hWnd;
if (!SHInitDialog(&shidi)) return FALSE;
}
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDC_BUTTON_OK:
ButtonWrite();
break;
case IDOK:
case IDCANCEL:
case IDM_OK:
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_SETTINGCHANGE:
SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
void ButtonWrite()
{
IContact *pContact=NULL;
BSTR bstrBirthday=NULL;
BSTR bstrFirstName=NULL;
BSTR bstrMiddleName=NULL;
BSTR bstrLastName=NULL;
IPOutlookApp * m_polApp;
if (SUCCEEDED(CoInitializeEx( NULL, 0)))
{
if(SUCCEEDED(CoCreateInstance(CLSID_Application,NULL, CLSCTX_INPROC_SERVER,
IID_IPOutlookApp, reinterpret_cast<void **>(&m_polApp))))
{
if(FAILED(m_polApp->Logon(NULL)))
{
MessageBox(NULL,_T("错误"),_T("error!"),MB_OK);
}
}
}
IFolder *m_pFolder;
IPOutlookItemCollection *m_pItems;
m_polApp->GetDefaultFolder(olFolderContacts, &m_pFolder);
m_pFolder->get_Items(&m_pItems);
m_pItems->Add((IDispatch **)&pContact);
wcscpy(bstrFirstName,L"a");
wcscpy(bstrMiddleName,L"b");
wcscpy(bstrLastName,L"c");
pContact->put_FirstName(bstrFirstName);
pContact->put_MiddleName(bstrMiddleName);
pContact->put_LastName(bstrLastName);
pContact->Save();
RELEASE_STRING(bstrBirthday);RELEASE_STRING(bstrFirstName);
RELEASE_STRING(bstrMiddleName);RELEASE_STRING(bstrLastName);
RELEASE_IO(pContact);
if (m_polApp)
{
m_polApp->Logoff();
m_polApp->Release();
}
CoUninitialize(); //释放COM
}
连接错误:
error LNK2001: 无法解析的外部符号 CLSID_Application
error LNK2001: 无法解析的外部符号 IID_IPOutlookApp
这是什么原因?