Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VS2010 DLL function
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
 

myApplication
 
Public Class callExternDll
  <dllimport("c:\mydll.dll")>
  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
 
MsgBox(showResult)
 
End Sub
 

I want to call the function so to receive "hello world"
Posted 15-Oct-12 6:35am
Edited 15-Oct-12 6:47am
Wes Aday94.3K
v2
Comments
Kuthuparakkal at 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 at 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 at 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)?
--SA
begi21 at 15-Oct-12 13:36pm
   
i dont know i just created it using Class Library and builded it!
Sergey Alexandrovich Kryukov at 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.
--SA
begi21 at 15-Oct-12 15:58pm
   
Yes theres is much to learn, i should visite a programming school
Sergey Alexandrovich Kryukov at 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.
--SA

1 solution

Rate this: bad
good
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:
http://en.wikipedia.org/wiki/.NET_assembly[^],
http://msdn.microsoft.com/en-us/library/ms973231.aspx[^].
 
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:
http://msdn.microsoft.com/en-us/library/aa446532.aspx[^].
 
If you need to learn P/Invoke, please see:
http://en.wikipedia.org/wiki/P/Invoke[^],
http://msdn.microsoft.com/library/en-us/vcmxspec/html/vcmg_PlatformInvocationServices.asp[^].
 
This CodeProject article can also be useful: Essential P/Invoke[^].
 
—SA
  Permalink  
Comments
begi21 at 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 at 15-Oct-12 14:07pm
   
Don't tell "I don't know", come to knowing it. I provided you the references. Read.
--SA

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 15 Oct 2012
Copyright © CodeProject, 1999-2014
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