#include<stdio.h>
//TODO: Change the path here if your Msxml.dll file is in a different location.
#import "c:\winnt\system32\msxml.dll"
using namespace MSXML;
//To use MSXML 6.0 import the dll msxml4.dll instead of msxml.dll as follows
// #import "c:\winnt\system32\msxml6.dll"
// using namespace MSXML2;
int main(int argc, char* argv[])
{
CoInitialize(NULL);
try
{
//TODO: Change the line below to reflect your server.
bstr_t yourServerName = "YourExchangeServername";
bstr_t sSourceUrl = "http://" + yourServerName +
"/public/TestFolder1/test.eml";
bstr_t sDestUrl = "http://" + yourServerName +
"/public/TestFolder2/test.eml";
bstr_t sMethod = "MOVE";
//TODO: Change the 2 lines below to reflect your user name and password.
_variant_t vUser = L"YourDomain\\Administrator";
_variant_t vPassword = L"password";
// To use MSXML 6.0 use the following declaration and creation of pXMLHttpReq
// IXMLHTTPRequestPtr pXMLHttpReq= NULL;
// HRESULT hr=pXMLHttpReq.CreateInstance("Msxml2.XMLHTTP.6.0");
MSXML::IXMLHttpRequest* pXMLHttpReq=NULL;
HRESULT hr = ::CoCreateInstance(__uuidof(XMLHTTPRequest),
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(IXMLHttpRequest),
(LPVOID*)&pXMLHttpReq);
if (S_OK != hr)
{
printf("XML Http Request pointer creation failed\n");
return 0;
}
// Call open function.
_variant_t vAsync = (bool)FALSE;
pXMLHttpReq->open(sMethod,
sSourceUrl,
vAsync,
vUser,
vPassword);
pXMLHttpReq->setRequestHeader((bstr_t)"Destination", sDestUrl);
// Send the request to set the search criteria.
pXMLHttpReq->send();
// OK, get response.
long lStatus;
pXMLHttpReq->get_status(&lStatus);
printf("\n~~~~~~~~\n%d\n", lStatus);
BSTR bstrResp;
pXMLHttpReq->get_statusText(&bstrResp);
printf("\n~~~~~~~~\n%s\n", (char*)(bstr_t)bstrResp);
_bstr_t bstrAllHeaders;
bstrAllHeaders = pXMLHttpReq->getAllResponseHeaders();
printf("\n~~~~~~~~\n%s\n", (char*)bstrAllHeaders);
BSTR bstrResponseText;
pXMLHttpReq->get_responseText(&bstrResponseText);
printf("\n~~~~~~~~\n%s\n", (char*)(bstr_t)bstrResponseText);
}
catch(_com_error &e)
{
printf("Error\a\a\n\tCode = %08lx\n"
"\tCode meaning = %s\tSource = %s\n\tDescription = %s\n",
e.Error(),
e.ErrorMessage(),
(char*)e.Source(),
(char*)e.Description() );
}
CoUninitialize();
return 0;
}