Data mismatch when reading file through unmanaged code called from c#

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px; line-height:18px
<p style=" I have an unmanaged dll that contains a function to read a data from a file. I wrote a CLI wrapper for it.
<p style=" To test whether it is working, I wrote a simple CLI program calling the wrapper class and the data read method. It worked fine.
<p style=" I used that dll in a c# program but the data is not read properly. It reads but the data read is not proper.
<p style=" CLI function:
<pre style=" <code style=" <span style=" void<span style=" <span style=" FileReader<span style=" ::<span style=" ReadFile<span style=" ()<span style=" <br/><span style=" {<span style=" <br/><span style=" int<span style=" ret<span style=" ;<span style=" <br/>STRUCT head<span style=" ;<span style=" <br/>STRUCT1 <span style=" *<span style=" sqar<span style=" ;<span style=" <br/><br/>memset <span style=" (<span style=" <span style=" (<span style=" <span style=" void<span style=" <span style=" *<span style=" <span style=" )&<span style=" head<span style=" ,<span style=" <span style=" 0<span style=" ,<span style=" <span style=" sizeof<span style=" <span style=" (<span style=" STRUCT<span style=" )<span style=" <span style=" );<span style=" <br/>sqar <span style=" =<span style=" <span style=" (<span style=" STRUCT1 <span style=" *<span style=" <span style=" )<span style=" NULL<span style=" ;<span style=" <br/><br/>ret <span style=" =<span style=" <span style=" Read_func<span style=" (<span style=" <span style=" "somefile.someformat"<span style=" ,<span style=" <span style=" &<span style=" head<span style=" ,<span style=" <span style=" &<span style=" sqar <span style=" );<span style=" <br/><span style=" }<span style=" <br/>[/code][/code]
<p style=" CLI EXE:
<pre style=" <code style=" <span style=" int<span style=" main<span style=" (<span style=" array<span style=" <<span style=" System<span style=" ::<span style=" String<span style=" <span style=" ^><span style=" <span style=" ^<span style=" args<span style=" )<span style=" <br/><span style=" {<span style=" <br/><span style=" FileReader<span style=" reader<span style=" ;<span style=" <br/>reader<span style=" .<span style=" ReadFile<span style=" ();<span style=" <br/><span style=" Console<span style=" ::<span style=" WriteLine<span style=" (<span style=" L<span style=" "Hello World"<span style=" );<span style=" <br/><span style=" return<span style=" <span style=" 0<span style=" ;<span style=" <br/><span style=" }<span style=" <br/>[/code][/code]
<p style=" This works fine. When I debug, the code flows through and reads the data properly.
<p style=" C# code:
<pre style=" <code style=" <span style=" {<span style=" <br/> <span style=" FileReader<span style=" filereader<span style=" =<span style=" <span style=" new<span style=" <span style=" FileReader<span style=" <span style=" ();<span style=" <br/> filereader<span style=" .<span style=" ReadFile<span style=" ();<span style=" <br/><br/><span style=" }<span style=" <br/>[/code][/code]
<p style=" When I import the CLI dll in the C# project and access the code as above the data in not read properly.
<p style=" STRUCT has int as members and it is read properly.STRUCT1 has int, double and structure pointers as members which is not read properly. What could be possibly wrong?


View the full article
 
Back
Top