Reputation: 391
I'm trying to import DLL files into my project, I already tried 'Add reference' and it didn't work:
'a reference to *.dll could not be added. please make sure that the file is accessible, and that it is a valid assembly or com component'
I tried to register the dll using 'regsvr32' and it didn't work:
'the module *.dll was loaded but the entry-point DllRegisterServer was not found'
finally I used DllImport, (I'm currently testing with libclamav.dll)
lImport("libclamav.dll")]
public static extern int cl_scanfile(String path);
private void button1_Click(object sender, EventArgs e)
{
string path="e:\\scan\\111.jpg";
int n;
n = cl_scanfile(path);
}
but I have an error on execution:
'An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)'
Any suggestions??
Upvotes: 0
Views: 769
Reputation: 911
It sounds like you want to p/Invoke methods in an unmanaged DLL. You should have a read through the Platform Invoke Tutorial provided by Microsoft and see if that helps.
If you're getting that incorrect format exception, this is possibly because your .NET application is targeting 'Any CPU' but the DLL you're trying to load is 32 bit DLL (and you're on a 64 bit machine). If this is the case, you might want to set the 'Platform Target' of your .NET application to 'x86' and see if that helps.
To successfully p/Invoke, you also need to have the DLL you're calling into (and all of its dependencies) in the search path somewhere. The easiest way to ensure this is to copy the DLL and all of the dependencies into the bin\Debug or bin\Release folder of your .NET application and see if that helps.
Upvotes: 1