|
-
March 7th, 2003, 11:19 AM
#1
How do you use a "C" dll from within a C# app?
Does anyone know how I can use a dll written in "C" from within a C# application? I have gotten as far as building a C# app and then importing the dll. However, when I call the function, I get an error saying that the dll cannot be loaded.:
// sample code follows
[DllImport("MyDll.dll")]
public static extern int DllFunction();
:
:
public static int Main()
{
DllFunction(); // I get a message that the dll cannot be loaded
}
Thanks for any help (and sample code)!!
-Tom
-
March 7th, 2003, 01:43 PM
#2
plz. check that dll is in path !!!
Paresh
-
March 7th, 2003, 02:05 PM
#3
Yes, it's in the path..
-
March 7th, 2003, 02:51 PM
#4
does it have functions as exported !!! in .def file. which type of dll is that.
is it a COM dll or a simple MFC/NONMFC dll.
-
March 7th, 2003, 04:48 PM
#5
It's a non-MFC dll (since it was written in "C")..
-
March 7th, 2003, 04:54 PM
#6
i think it should have the function exported list, make a NON-MFC dll in VC++ which exposes the function and then compile it to dll.
maybe pure C dll is conflicting one.
Paresh
-
March 8th, 2003, 06:59 AM
#7
If DLL cannot be loaded then dll is not a valid DLL or it is not in current directory or any directory listed in path env. variable...
Try to write whole path to the dll file in DllImport attribute.
If the prog fails again then try to make C/C++ prog and use LoadLibrary API function directly to load that DLL.
If the LoadLibrary loads the DLL successfully, post it here. We will look for problem again.
If the LoadLibrary fails then post here the error code returned by GetLastError() function call...
martin
-
March 8th, 2003, 09:00 AM
#8
Thanks, everyone.
I'll let you know what I find out.
Tom
-
March 10th, 2003, 04:51 PM
#9
sure will wait for your answer.
thankx
Paresh
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|