예제 #1
0
        /// <summary>
        /// Converts the managed data to unmanaged data.
        /// </summary>
        /// <param name="managedObj">The managed object to be converted. </param>
        /// <returns>A pointer to the COM view of the managed object.</returns>
        public IntPtr MarshalManagedToNative(object managedObj)
        {
            string managedString  = managedObj as string;
            IntPtr pManagedString = MarshalUtils.StringToPtr(managedString);

            return(pManagedString);
        }
예제 #2
0
        /// <summary>
        /// Converts the managed <see cref="listenerSettings"/>
        /// (<seealso cref="ListenerSettings"/>) to the native <see cref="AGDnsApi.ag_listener_settings"/> object
        /// </summary>
        /// <param name="listenerSettings"><see cref="ListenerSettings"/> instance to convert</param>
        /// <param name="allocatedPointers">List of pointers, which were allocated.
        /// Pointers, which will be referred to a newly allocated memory
        /// (within the process of marshaling the string to the pointer)
        /// will be added to this list.
        /// If this list is not specified (null),
        /// a new created pointer will not be added anywhere</param>
        /// The resulting pointer (<seealso cref="IntPtr"/>) must be freed
        /// with <see cref="MarshalUtils.SafeFreeHGlobal(IntPtr)"/>>
        /// <returns>An instance of <see cref="AGDnsApi.ag_listener_settings"/></returns>
        private static AGDnsApi.ag_listener_settings ToNativeObject(
            ListenerSettings listenerSettings,
            Queue <IntPtr> allocatedPointers)
        {
            ushort port    = (ushort)listenerSettings.EndPoint.Port;
            IntPtr address = MarshalUtils.StringToPtr(
                listenerSettings.EndPoint.Address.ToString(),
                allocatedPointers);

            AGDnsApi.ag_listener_settings listenerSettingsC = new AGDnsApi.ag_listener_settings
            {
                address = address,
                port    = port
            };

            MarshalUtils.CopyPropertiesToFields(listenerSettings, ref listenerSettingsC);
            return(listenerSettingsC);
        }
예제 #3
0
 public static AGDnsApi.ag_dns_stamp ToNativeObject(
     DnsStamp dnsStamp,
     Queue <IntPtr> allocatedPointers)
 {
     MarshalUtils.ag_buffer publicKeyC = MarshalUtils.BytesToAgBuffer(dnsStamp.PublicKey);
     MarshalUtils.ag_list   hashesC    = MarshalUtils.ListToAgList(
         dnsStamp.Hashes,
         (x, y) => MarshalUtils.BytesToAgBuffer(x),
         allocatedPointers);
     AGDnsApi.ag_dns_stamp dnsStampС = new AGDnsApi.ag_dns_stamp
     {
         ProtoType         = dnsStamp.ProtoType,
         ServerAddress     = MarshalUtils.StringToPtr(dnsStamp.ServerAddress),
         ProviderName      = MarshalUtils.StringToPtr(dnsStamp.ProviderName),
         DoHPath           = MarshalUtils.StringToPtr(dnsStamp.DoHPath),
         server_public_key = publicKeyC,
         hashes            = hashesC,
         Properties        = dnsStamp.Properties
     };
     return(dnsStampС);
 }