Replace deprecated talloc_init calls with talloc_named
[jelmer/openchange.git] / doc / examples / mapi_sample1.c
1 #include <libmapi/libmapi.h>
2
3 #define   DEFAULT_PROFDB_PATH     "%s/.openchange/profiles.ldb"
4
5 int main(int argc, char *argv[])
6 {
7         TALLOC_CTX              *mem_ctx;
8         enum MAPISTATUS         retval;
9         struct mapi_session     *session = NULL;
10         char                    *profdb;
11         const char              *profname;
12
13         mem_ctx = talloc_named(NULL, 0, "mapi_sample1");
14
15         profdb = talloc_asprintf(mem_ctx, DEFAULT_PROFDB_PATH, getenv("HOME"));
16
17         retval = MAPIInitialize(profdb);
18         mapi_errstr("MAPIInitialize", GetLastError());
19         if (retval != MAPI_E_SUCCESS) return -1;
20
21         retval = GetDefaultProfile(&profname);
22         mapi_errstr("GetDefaultProfile", GetLastError());
23         if (retval != MAPI_E_SUCCESS) return -1;
24
25         retval = MapiLogonEx(&session, profname, NULL);
26         mapi_errstr("MapiLogonEx", GetLastError());
27         if (retval != MAPI_E_SUCCESS) return -1;
28
29         MAPIUninitialize();
30         talloc_free(mem_ctx);
31
32         return 0;
33 }