I got a C ++ dll that should be integrated into a C # project.
I think I found the right way to do this, but the dll call gives me this error: System.BadImageFormatException: An attempt was made to load a program with the wrong format. (Exception from HRESULT: 0x8007000B)
This is the function in the dll:
extern long FAR PASCAL convert (LPSTR filename);
And this is the code I use in C #
namespace Test{
public partial class Form1 : Form
{
[DllImport("convert.dll", SetLastError = true)]
static extern Int32 convert([MarshalAs(UnmanagedType.LPStr)] string filename);
private void button1_Click(object sender, EventArgs e)
{
string filename = "testfile.txt";
StreamWriter sw = new StreamWriter(filename);
sw.WriteLine("line1");
sw.WriteLine("line2");
sw.Close();
Int32 ret = 0;
try
{
ret = convert(filename);
Console.WriteLine("Result of DLL: {0}", ret.ToString());
}
catch (Exception ex)
{
lbl.Text = ex.ToString();
}
}
}}
Any ideas on how to do this?
Thanks a lot Frank
source
share