J
James
I have a Dll written in C. And I want to Import that Dll into my C#
program and use a function in the Dll. In a previous newsgroup article
I saw that I may need to wrap the Dll in a C++ .NET class and then use
that in my C# application. But when I run my program I get an error
saying
System.IO.FileNotFoundException: File or assembly name "abc", or one
of its dependencies, was not found.
File name: "abc"
abc is my wrapper project class library.
here is my wrapper class is given below. The lib name is wdll.lib and
the header is dll.h.
#include "dll.h"
#pragma comment(lib, "wdll.lib")
namespace MyWrapper {
public __gc class Class1 {
public:
static void myfunc1(long JobNo)
{
_libmain(JobNo);
}
static char * myfunc2(void *vJobRec, short field, short
subfield)
{
return (GETJF_NAME( vJobRec ));
}
};
}
Here is the actual dll header file.
extern "C" {
void WINAPI _libmain ( long JobNo );
void * WINAPI _getjobfield ( void *vJobRec, short field, short
subfield );
};
......
and here is where I am calling it.
using MyWrapper;
unsafe
{
Class1.myfunc2(null,0,0);
}
It throws the exception here,
System.IO.FileNotFoundException: File or assembly name "abc", or one
of its dependencies, was not found.
File name: "abc"
________________________________________________
So then I tried to acces the Dll in a more traditional way , but would
result in the same error. Here is just a simple console application
that I did,
using System;
using System.Runtime.InteropServices;
using System.IO;
using System.Reflection;
using MyWrapper;
namespace test
{
class Class1
{
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("wdll.dll")]
public static extern IntPtr
_getjobfield([MarshalAs(UnmanagedType.LPStr)] string s, short i1,
short i2);
[STAThread]
static void Main(string[] args)
{
// Esure current directory is exe directory
Environment.CurrentDirectory = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location );
string dllPath = Path.GetFullPath(
@"C:\SoftwareDevelopment\testing\testing\test\test" );
LoadLibrary( dllPath );
Console.WriteLine( _getjobfield(null,0,0) );
}
}
}
But it throws the exception, Can any one help.
Thanks
program and use a function in the Dll. In a previous newsgroup article
I saw that I may need to wrap the Dll in a C++ .NET class and then use
that in my C# application. But when I run my program I get an error
saying
System.IO.FileNotFoundException: File or assembly name "abc", or one
of its dependencies, was not found.
File name: "abc"
abc is my wrapper project class library.
here is my wrapper class is given below. The lib name is wdll.lib and
the header is dll.h.
#include "dll.h"
#pragma comment(lib, "wdll.lib")
namespace MyWrapper {
public __gc class Class1 {
public:
static void myfunc1(long JobNo)
{
_libmain(JobNo);
}
static char * myfunc2(void *vJobRec, short field, short
subfield)
{
return (GETJF_NAME( vJobRec ));
}
};
}
Here is the actual dll header file.
extern "C" {
void WINAPI _libmain ( long JobNo );
void * WINAPI _getjobfield ( void *vJobRec, short field, short
subfield );
};
......
and here is where I am calling it.
using MyWrapper;
unsafe
{
Class1.myfunc2(null,0,0);
}
It throws the exception here,
System.IO.FileNotFoundException: File or assembly name "abc", or one
of its dependencies, was not found.
File name: "abc"
________________________________________________
So then I tried to acces the Dll in a more traditional way , but would
result in the same error. Here is just a simple console application
that I did,
using System;
using System.Runtime.InteropServices;
using System.IO;
using System.Reflection;
using MyWrapper;
namespace test
{
class Class1
{
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("wdll.dll")]
public static extern IntPtr
_getjobfield([MarshalAs(UnmanagedType.LPStr)] string s, short i1,
short i2);
[STAThread]
static void Main(string[] args)
{
// Esure current directory is exe directory
Environment.CurrentDirectory = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location );
string dllPath = Path.GetFullPath(
@"C:\SoftwareDevelopment\testing\testing\test\test" );
LoadLibrary( dllPath );
Console.WriteLine( _getjobfield(null,0,0) );
}
}
}
But it throws the exception, Can any one help.
Thanks