-1

The order of operation of my program is (Create file through dll call -> Read created file)

But it doesn't work.

After calling dll, the ReadAllLine function does not work and enters an infinite wait state. The cpu used is also 0.

How do I run a function and read a file?

[DllImport("Pcap_Parsing.dll", EntryPoint = "DEC_Parsing", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]

string FilePath = "file~~~/~~~/~~~.pcap"
string[] FileLines;

public static extern void DEC_Parsing(string fn);

Parsing(FilePath); //file create test.ini
FileLines = System.IO.File.ReadAllLines(~~~~path/test.ini); //When this function is executed, the cpu usage becomes 0 and it is in an infinite wait state. 
  • Never heard of that DLL. Tried googling it to no avail. Do you have a link to maybe some API documentation for the Pcap_Parsing.dll? Also, shouldn't the [DllImport()] line be just above the `public static extern void DEC_Pparsing(string fn);`? The string FilePath and string[] FileLines seems off / weird to me. In theory, if the Pcap_Parsing.dll is written correctly, it should open the file, read / write the contents, and then close the file releasing it. If you are getting stuck at ReadAllLines, maybe there is still a file lock? – B.O.B. Apr 22 '21 at 05:41
  • Also, don't know anything about Pcap, but File.ReadAllLines can throw numerous / various exceptions. Do you have it in a try catch block and it's not throwing any exceptions? Usually if there is a file lock and you try to call File.ReadAllLines, it should throw an exception (can't remember if that's immediate or there is a timeout, but it definitely shouldn't just sit there and wait). – B.O.B. Apr 22 '21 at 05:44
  • The dll is what I made. FILE CLOSE is done in DLL. The exception is not thrown and cannot be handled. – dbtjd0555navercom Apr 22 '21 at 07:08

1 Answers1

0

pcap files aren't a text file I think it is hard to use a method reads lines to string[]. try this without parsing it might work as all files saved on the devices are binaries.

    [DllImport("Pcap_Parsing.dll", EntryPoint = "DEC_Parsing", ExactSpelling = 
    true, CallingConvention = CallingConvention.Cdecl)]

    string FilePath = "file~~~/~~~/~~~.pcap"
    string[] FileLines;
    
    public static extern void DEC_Parsing(string fn)
    {
        var FileLines = System.IO.File.ReadAllBytes(filePath);

        string fileDecode = Encoding.ASCII.GetString(FileLines);
    } 
EL Khayar
  • 11
  • 4