pEp_utility.h
author Markus Schaber <markus@pep-security.net>
Tue, 03 May 2016 20:15:26 +0200
changeset 71 8d19e1c194f0
parent 41 c55eaabd5ea6
child 74 f2531096699e
permissions -rw-r--r--
Fix com server registration via /Regserver
vb@8
     1
#pragma once
vb@8
     2
vb@8
     3
#include "stdafx.h"
vb@8
     4
#include "pEpComServerAdapter_i.h"
vb@8
     5
#include "utf8_helper.h"
vb@8
     6
vb@8
     7
using namespace std;
vb@8
     8
vb@10
     9
namespace pEp {
vb@10
    10
    namespace utility {
vb@8
    11
vb@10
    12
        struct pEp_identity_cpp {
vb@10
    13
            string address;
vb@10
    14
            string fpr;
vb@10
    15
            string user_id;
vb@10
    16
            string username;
vb@10
    17
            pEp_comm_type comm_type;
vb@10
    18
            string lang;
vb@10
    19
            bool me;
vb@8
    20
vb@10
    21
            pEp_identity_cpp(
vb@10
    22
                string _address = string(),
vb@10
    23
                string _fpr = string(),
vb@10
    24
                string _user_id = string(),
vb@10
    25
                string _username = string(),
vb@10
    26
                pEp_comm_type _comm_type = pEp_ct_unknown,
vb@10
    27
                string _lang = string()
vb@10
    28
                ) : address(_address), fpr(_fpr), user_id(_user_id), username(_username), comm_type(_comm_type), lang(_lang), me(false)
vb@10
    29
            { }
vb@8
    30
vb@10
    31
            pEp_identity_cpp(const ::pEp_identity *_ident);
vb@10
    32
            pEp_identity_cpp(const pEp_identity_s *_ident);
vb@8
    33
vb@10
    34
            pEp_identity * to_pEp_identity();
vb@10
    35
            pEp_identity_s * to_pEp_identity_s();
vb@10
    36
        };
vb@8
    37
vb@10
    38
        void copy_identity(pEp_identity_s * ident_s, const pEp_identity * ident);
vb@10
    39
        ::pEp_identity *new_identity(const pEp_identity_s * ident);
vb@8
    40
vb@39
    41
        static LPTYPELIB pTypelib = NULL;
vb@39
    42
vb@13
    43
        template< class UDType > static IRecordInfo *getRecordInfo()
vb@13
    44
        {
vb@13
    45
            LPTYPEINFO pTypeInfo = NULL;
vb@13
    46
            LPSAFEARRAY psaUDType = NULL;
vb@13
    47
            IRecordInfo* pRecInfo = NULL;
vb@13
    48
vb@13
    49
            // Fetch the IRecordInfo interface describing the UDT
vb@39
    50
            if (pTypelib == NULL)
vb@39
    51
                LoadRegTypeLib(LIBID_pEpCOMServerAdapterLib, 1, 0, GetUserDefaultLCID(), &pTypelib);
vb@13
    52
vb@39
    53
            assert(pTypelib);
vb@39
    54
vb@41
    55
            GUID guid = __uuidof(UDType);
vb@41
    56
            HRESULT hr = pTypelib->GetTypeInfoOfGuid(guid, &pTypeInfo);
vb@13
    57
            assert(SUCCEEDED(hr) && pTypeInfo);
vb@13
    58
            hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecInfo);
vb@13
    59
            assert(SUCCEEDED(hr) && pRecInfo);
vb@13
    60
            pTypeInfo->Release();
vb@13
    61
vb@13
    62
            return pRecInfo;
vb@13
    63
        }
vb@13
    64
vb@13
    65
        template< class UDType > LPSAFEARRAY newSafeArray(ULONG cElements)
vb@13
    66
        {
vb@13
    67
            IRecordInfo *pRecInfo = getRecordInfo< UDType >();
vb@13
    68
            SAFEARRAYBOUND rgbounds = { cElements, 0 };
vb@13
    69
            LPSAFEARRAY psaUDType = SafeArrayCreateEx(VT_RECORD, 1, &rgbounds, pRecInfo);
vb@13
    70
            pRecInfo->Release();
vb@13
    71
            assert(psaUDType);
vb@13
    72
vb@13
    73
            return psaUDType;
vb@13
    74
        }
vb@13
    75
vb@33
    76
        ::message * text_message_to_C(text_message *msg);
vb@37
    77
        void text_message_from_C(text_message *msg2, ::message *msg);
vb@8
    78
    }
vb@8
    79
}