📄 getcontancts.cpp
字号:
// GetContancts.cpp : 定义 DLL 应用程序的入口点。
//
/*#define INITGUID*/
#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include <aygshell.h>
#include <pimstore.h>
IPOutlookApp *g_polApp = NULL;
void ShutdownPoom();
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
if (SUCCEEDED(CoInitializeEx( NULL, 0)))
{
// Now, let's get the main outlook application
if (SUCCEEDED(CoCreateInstance(CLSID_Application, NULL, CLSCTX_INPROC_SERVER,
IID_IPOutlookApp, reinterpret_cast<void **>(&g_polApp))))
{
// login to the Pocket Outlook object model
if(SUCCEEDED(g_polApp->Logon(NULL)))
{
// can't login to the app
DEBUGMSG(TRUE,(TEXT("Laod Dll\r\n")));
}
}
}
break;
case DLL_PROCESS_DETACH:
ShutdownPoom();
break;
}
return TRUE;
}
extern "C" _declspec(dllexport) BOOL PopulateList()
{
MessageBox(NULL,TEXT("11"),TEXT("22"),MB_OK);
IFolder * pCurrFldr = NULL;
IPOutlookItemCollection * pItemCol = NULL;
// Get the folder and its items, depending on
// the folder type
if (SUCCEEDED(g_polApp->GetDefaultFolder(olFolderContacts, &pCurrFldr)))
{
if (SUCCEEDED(pCurrFldr->get_Items(&pItemCol)))
{
BSTR bstrFirstName;
BSTR bstrLastName;
BSTR bstrPhoneNumber;
BSTR bstrContactInfo;
IContact * pContact = NULL;
int cItems = 0;
pItemCol->get_Count(&cItems);
for (int i = 1; i <= cItems; i++)
{
// reinterpret_cast<IDispatch**> 指针强制类型转换
if (SUCCEEDED(pItemCol->Item (i, reinterpret_cast<IDispatch**>(&pContact))))
{
// grab properties
pContact->get_FirstName(&bstrFirstName);
pContact->get_LastName(&bstrLastName);
pContact->get_MobileTelephoneNumber(&bstrPhoneNumber);
// allocate a buffer for all the properties plus a comma, space. newline, and terminating null
bstrContactInfo = SysAllocStringByteLen(NULL, SysStringByteLen(bstrFirstName) +
SysStringByteLen(bstrLastName) +
SysStringByteLen(bstrPhoneNumber) +
(4*sizeof(OLECHAR)));
// copy the strings into one
_tcscpy(bstrContactInfo, bstrLastName);
_tcscat(bstrContactInfo, _T(", "));
_tcscat(bstrContactInfo, bstrFirstName);
_tcscat(bstrContactInfo, _T("\n"));
_tcscat(bstrContactInfo, bstrPhoneNumber);
DEBUGMSG(TRUE,(TEXT("%s\r\n"),bstrContactInfo));
}
}
pItemCol->Release();
pCurrFldr->Release();
return TRUE;
}
pCurrFldr->Release();
}
return FALSE;
}
void ShutdownPoom()
{
if (g_polApp)
{
g_polApp->Logoff();
g_polApp->Release();
}
CoUninitialize();
DEBUGMSG(TRUE,(TEXT("Release Dll\r\n")));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -