Results 1 to 5 of 5

Thread: DLLimport and Entrypoint not found problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    10

    DLLimport and Entrypoint not found problem

    I made a simple dll written in vb6

    VB Code:
    1. Public Static Function TEST(ByVal x As Integer)
    2.  
    3. On Error GoTo error
    4.  
    5.     MsgBox ("aaa")
    6.     Exit Function
    7.    
    8. error:
    9.    TEST = 0
    10. 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

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 .

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    10

    Re: DLLimport and Entrypoint not found problem

    Quote 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

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Can you attach the dll file ? I will see if I can do something !

  5. #5
    Lively Member
    Join Date
    Feb 2005
    Posts
    84

    Lightbulb 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
  •  



Click Here to Expand Forum to Full Width