Click here to Skip to main content
13,046,176 members (59,975 online)
Rate this:
Please Sign up or sign in to vote.
I already know how to import a dll into my project but by manually reference im receiving errors like "entry point was not found"

I created the dll file called myDll the class is called myFunctions and a function called showResult() As String just for example:

myDll.dll which is located on C:\ for example

Public Class myFunctions
  Public Function showResult() as string
  Return "HELLO WORLD"
  End Function
End Class


Public Class callExternDll
  Public Shared Function showResult() As String
  End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub

I want to call the function so to receive "hello world"
Posted 15-Oct-12 5:35am
Updated 15-Oct-12 5:47am
Wes Aday104.2K
Kuthuparakkal 15-Oct-12 11:41am
do you have Sub Main in your program ? like this :
' Allow easy reference to the System namespace classes.
Imports System

' This module houses the application's entry point.
Public Module modmain
' Main is the application's entry point.
Sub Main()
' Write text to the console.
Console.WriteLine ("Hello World using Visual Basic!")
End Sub
End Module
begi21 15-Oct-12 11:46am
No i havent because its a class library and not a module so i thought i dont have to write it, but as you can see above there is at least one Function which id called showResult() so this must be an entry point too or am i wrong? do i have to rename it into sub showResult???
Sergey Alexandrovich Kryukov 15-Oct-12 13:25pm
The question is: how about the first fragment, which you probably written to export? Is it written as native code, or CLI (using VB.NET)?
begi21 15-Oct-12 13:36pm
i dont know i just created it using Class Library and builded it!
Sergey Alexandrovich Kryukov 15-Oct-12 14:06pm
If you don't know what are you using and what is your platform, learn it first, before doing any programming. Or don't program at all, as it's useless. Know what you do.
begi21 15-Oct-12 15:58pm
Yes theres is much to learn, i should visite a programming school
Sergey Alexandrovich Kryukov 15-Oct-12 16:01pm
Well, you can school yourself, using books, articles and manuals, but it should really be a school, with a focus on fundamentals. I think this is what most decent developers did, and you can do, too.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Please see my comment to the question. If myFunctions.showResult is also in the CLI code, written in VB.NET, you don't need P/Invoke to use it. P/Invoke is only used to use unmanaged code in .NET (or other CLI) assembly. If both pieces are .NET assemblies, you simply reference one by another and use it directly:[^],[^].

If you use unmanaged code in a .NET assembly, you really need to use P/Invoke. One thing you should check up is using right entry point name, calling conventions (which should be the same between different versions of Basic), etc. When you have a DLL, you can see its exports using some binary dump tool like "dumpbin.exe". Please see:[^].

If you need to learn P/Invoke, please see:[^],[^].

This CodeProject article can also be useful: Essential P/Invoke[^].

begi21 15-Oct-12 14:01pm
Thank you for the reply but i even didnt know that i was using PInvoke i just found the codelines in google.
Yes my .dll i wrote is created in vbnet (VS2010) and it should be in managed code i reviewed and didnt found the options "CLI" or "Native"
i just created a project, selected Class Library and builded it and a .dll came out.
Now the problem is something else, because when i import the same dll onto my project(windows application) and then
Imports mydll.dll
dim abc as new mydll.dll
then the function on it immediately was displayed but when i try to load it while running without i have imported that mydll.dll before and i try to refer to it.
So if i import the dll before creating my app it works but by reference while running it sends errors forwards like PInvoke Restriction: cannot return variants
Please help if you have any idea,
Regards, Begi
Sergey Alexandrovich Kryukov 15-Oct-12 14:07pm
Don't tell "I don't know", come to knowing it. I provided you the references. Read.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 15 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100