** I forgot to ask one more thing, Just see the last few lines.

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) );

}
}
}

*******
******************************************************************************
And in the previous mail I for got ask one more thing

since _getjobfield returns a char pointer how can I read that value.

currently what I am trying to do is

unsafe
{
Class1.myfunc2(null,0,0);
}

but when i DO THIS

unsafe
{
char * p = Class1.myfunc2(null,0,0);
}

It say's can not convert sbyte* to char*.

The thing is that I am sending char* so I do not know where sbyte
comes from


But it throws the exception, Can any one help.

Thanks

Re: Dll Import problem by james_morris1232000

james_morris1232000
Mon Mar 01 00:04:24 CST 2004

Hi Stoitcho,

Thanks again for the info. Those were very good, had a look at those
articles. Actually the problem was with the function name. What
happened was when you called from C++ you needed to add a undersore
before the function name(I don't know why?). So I was looking at those
calling programs to get the function names, suddenly I realise my
mistake. Thanks again

Regards

James