embed pcap dll files into c# project created DLL


I am trying to create user defined function which uses class defined in pcapDotNet.Core.Dll file. My c# Code is as below:

using System;
using System.IO;
using System.Collections.Generic;
using PcapDotNet.Core;
using System.Linq;
using System.Runtime.InteropServices;
using RGiesecke.DllExport; //GANESH
using System.Runtime.InteropServices;//GANESH
using System.Reflection;

namespace ObtainingAdvancedInformationAboutInstalledDevices
    class Program1

        static void Main(string[] args)
            Program1 var1 = new Program1();

        public Program1()
            AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;

        static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
            String dllName = new AssemblyName(args.Name).Name + ".dll";
            var assem = Assembly.GetExecutingAssembly();
            String resourceName = assem.GetManifestResourceNames().FirstOrDefault(rn => rn.EndsWith(dllName));
            if (resourceName == null) return null; // Not found, maybe another handler will find it
            using (var stream = assem.GetManifestResourceStream(resourceName))
                Byte[] assemblyData = new Byte[stream.Length];
                stream.Read(assemblyData, 0, assemblyData.Length);
                return Assembly.Load(assemblyData);

        //**************************************USER DEFINED FUNCTIONS START*********************
        [DllExport("checkFunction", CallingConvention = CallingConvention.Cdecl)]//GANESH
        public static int checkFunction()

            Program1 worker1 = new Program1();
            return 0;

        void checkDevice()
            // Retrieve the interfaces list
            IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;
            Console.WriteLine(" inside checkDevice\n");

            // Scan the list printing every entry
            for (int i = 0; i != allDevices.Count(); ++i)


        // Print all the available information on the given interface
        private static void DevicePrint(IPacketDevice device)
            // Name

            // Description
            if (device.Description != null)
                Console.WriteLine("\tDescription: " + device.Description);

            // Loopback Address
            Console.WriteLine("\tLoopback: " +
                              (((device.Attributes & DeviceAttributes.Loopback) == DeviceAttributes.Loopback)
                                   ? "yes"
                                   : "no"));

            // IP addresses
            foreach (DeviceAddress address in device.Addresses)
                Console.WriteLine("\tAddress Family: " + address.Address.Family);

                if (address.Address != null)
                    Console.WriteLine(("\tAddress: " + address.Address));
                if (address.Netmask != null)
                    Console.WriteLine(("\tNetmask: " + address.Netmask));
                if (address.Broadcast != null)
                    Console.WriteLine(("\tBroadcast Address: " + address.Broadcast));
                if (address.Destination != null)
                    Console.WriteLine(("\tDestination Address: " + address.Destination));

My python code is as below:

class gooseDriver():
    """A class that creates windows form by importing IED.MainWindow()"""

    def __init__(self, ipAddress, port):

        self.hllDll = WinDLL (r"C:\WORK\IEC61850\gooseThread1\gooseThread1\bin\x64\Debug\gooseThread1.dll")       

        print("Goose Message Started\n")   

def main():
    IED = gooseDriver("", 102)
    print("GooseDriver is called\n")

if __name__ == '__main__':

when I tried to call checkFunction from python giving error as "OSError: [WinError -532462766] Windows Error 0xe0434352". This is because function is using LivePacketsDevice class from pcap files. I have embedded pcapDotNet.Core.Dll file while generating DLL as reference. Can anybody suggest what is solution for this issue please.

asked on Stack Overflow Aug 21, 2017 by Ganesh • edited Aug 28, 2017 by denfromufa

1 Answer


After lot of trial, it started working when i placed pcapDotNet DLL files into folder where Python interpreter exists. Dont know what is reason? can anybody know on this please.

answered on Stack Overflow Aug 29, 2017 by Ganesh

User contributions licensed under CC BY-SA 3.0