|
-
Apr 21st, 2005, 11:45 AM
#1
Thread Starter
New Member
DLLimport and Entrypoint not found problem
I made a simple dll written in vb6
VB Code:
Public Static Function TEST(ByVal x As Integer)
On Error GoTo error
MsgBox ("aaa")
Exit Function
error:
TEST = 0
End Function
I compiled and then made a c# project to use it
Code:
using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace teste
{
class NativeMethods
{
[SuppressUnmanagedCodeSecurityAttribute()]
[DllImport("C:\\TEST.dll")]
extern public static int TEST(int x);
}
class MainClass
{
[SecurityPermission(SecurityAction.Deny, Flags =
SecurityPermissionFlag.UnmanagedCode)]
public void CallUnmanagedCodeWithPermission()
{
try
{
NativeMethods.TEST(1);
MessageBox.Show("OK");
}
catch (SecurityException e)
{
MessageBox.Show("ERROR:" + e.Source + e.Message);
}
}
}
}
When i run the exe it gives me an error
Code:
An unhandled exception of type 'System.EntryPointNotFoundException' occurred in teste.exe
Additional information: Unable to find an entry point named TEST in DLL C:\TEST.dll.
Any ideas how to solve this .
Thanks
-
Apr 21st, 2005, 08:24 PM
#2
Sleep mode
Did you reference that dll in your proj ?? Doing so will make a wrapper class so it can interoperate with .NET . Right-click on the References item in the Solution Explorer then Add Reference . Then instantiate an obj of that class , call your function .
-
Apr 22nd, 2005, 08:42 AM
#3
Thread Starter
New Member
Re: DLLimport and Entrypoint not found problem
 Originally Posted by Pirate
Did you reference that dll in your proj ?? Doing so will make a wrapper class so it can interoperate with .NET . Right-click on the References item in the Solution Explorer then Add Reference . Then instantiate an obj of that class , call your function .
Yes I already did that.
The error about the entry point occurs after the instantiation of the object, when one of the functions inside the dll is called
-
Apr 22nd, 2005, 07:23 PM
#4
Sleep mode
Can you attach the dll file ? I will see if I can do something !
-
Apr 27th, 2005, 03:16 PM
#5
Lively Member
Re: DLLimport and Entrypoint not found problem
VB6 is not capable of creating a DLL the way you are trying to use it because it is not cabable of declaring function entry points. However, you can declare a class in VB6 and expose it to COM. Here is how to do it (as I remember it from so long ago.)
1. Make sure your VB6 code is in a class module. In the properties window, one of the properties should have a value named Public. Find that property (maybe it is called Instancing ??? ) and set its value to Public.
Keep in mind a VB6 Integer is a C# short, a VB6 Long is a C# int. These should match. Also the return type is not specified on 'Public Static Function Test', at the end of this line you should add 'As Long' or whatever you want the return type to be.
2. Make sure the VB6 DLL is referenced in C# (Project | Add Reference, select the COM tab, browse for your file and select it into the lower list, click OK)
3. In C#, declare a new instance of your VB6 class in code, (assume your VB6 project name is TestProj, your class is named MyTestClass)
Code:
//C# code
TestProj.MyTestClass localVar;
localVar.TEST(42);
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
|