473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How can I call a vb.net dll from vb.net?

I have created the following com class in vb.net using VS 2010:

Expand|Select|Wrap|Line Numbers
  1. <ComClass(AgileApi.ClassId, AgileApi.InterfaceId, AgileApi.EventsId)> _
  2. Public Class AgileApi
  3.  
  4. #Region "COM GUIDs"
  5.     ' These  GUIDs provide the COM identity for this class 
  6.     ' and its COM interfaces. If you change them, existing 
  7.     ' clients will no longer be able to access the class.
  8.     Public Const ClassId As String = "38a4d038-7e0b-40f7-9299-4d7b18d5d25f"
  9.     Public Const InterfaceId As String = "aae5fd64-b9b2-497e-882c-006618d1679f"
  10.     Public Const EventsId As String = "fb928add-9053-46a7-b124-49183b1cea18"
  11. #End Region
  12.  
  13.     ' A creatable COM class must have a Public Sub New() 
  14.     ' with no parameters, otherwise, the class will not be 
  15.     ' registered in the COM registry and cannot be created 
  16.     ' via CreateObject.
  17.     Public Sub New()
  18.         MyBase.New()
  19.     End Sub
  20.  
  21.     Public Function callAgile(ByVal protocol As String, ByVal host As String, ByVal port As Integer, ByVal serviceName As String, ByVal methodName As String, ByVal parms As String()) As String
  22.         Dim xml As String
  23.  
  24.         Return xml
  25.     End Function
  26.  
  27. End Class
  28.  
Then I created a new project with a form to test it. Here's the form code:

Expand|Select|Wrap|Line Numbers
  1. Imports System.Runtime.InteropServices
  2. Public Class Form1
  3.  
  4.     <DllImportAttribute("AgileApi.dll", EntryPoint:="callAgile", SetLastError:=True, CharSet:=CharSet.Unicode, _
  5.          ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
  6.     Public Shared Function callAgile(ByVal protocol As String, ByVal host As String, ByVal port As Integer, ByVal serviceName As String, ByVal methodName As String, ByVal parms As String()) As String
  7.         'This should use the DLL
  8.     End Function
  9.  
  10.     Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
  11.         Dim protocol As String
  12.         protocol = "http"
  13.         Dim host As String
  14.         host = txtHostName.Text
  15.         Dim port As Integer
  16.         port = Val(txtPortNumber.Text)
  17.  
  18.         Dim serviceName As String
  19.         serviceName = txtServiceName.Text
  20.         Dim methodName As String
  21.         methodName = txtMethodName.Text
  22.         Dim parms(5) As String
  23.         parms(0) = txtParm0.Text
  24.         parms(1) = txtParm1.Text
  25.         parms(2) = txtParm2.Text
  26.         parms(3) = txtParm3.Text
  27.         parms(4) = txtParm4.Text
  28.  
  29.         Dim last As Integer
  30.         For ix As Integer = 4 To 0 Step -1
  31.             If parms(ix) = "" Then
  32.                 last = ix
  33.             End If
  34.         Next
  35.  
  36.         ReDim parms(last + 1)
  37.  
  38.         Dim xml As String
  39.         xml = callAgile(protocol, host, port, serviceName, methodName, parms)
  40.         txtXml.Text = xml
  41.     End Sub
  42. End Class
  43.  
But when I call my function, I get System.EntryPointNotFoundException

I've been googling for days with no results. I can't seem to find any kind of guide to telling me how to create a vb.net dll and call it from vb.net.

Thanks for your help.
Nov 23 '10 #1
6 2245
Joseph Martell
198 Expert 128KB
DLLs in .net are treated differently than in C++ and other programming languages.

When you create a class library project in VS (for either VB or C#) you are creating a DLL. In order to call/use that DLL in another project you have to add a reference to your new program.

Go to Project > Add Reference..., or right-click on the project that needs to use your DLL, and click "Add Reference...".

After a short wait you should see an Add Reference dialog box.

There are several tabs across the top but each of the components that is listed in a tab represents a DLL. If you expand the "Path" column in the .Net tab you will see the DLL location.

If your two projects are in the same solution, you should probably go to the Projects tab and add the project that you need.

If your dll project is NOT in the same solution as your project that needs to use the dll, then go to the Browse tab and find your compiled DLL from your DLL project. This will add the DLL as a reference to your solution.
Nov 27 '10 #2
I added the reference and am getting the same error.

If I delete the DLL, the error changes to something like dll not found, so the entry point error indicates that if found the DLL, but can't find the entry point.

Is there something i need to do when I create the DLL to define that method as the entry point?
Nov 29 '10 #3
Joseph Martell
198 Expert 128KB
What types of projects are you dealing with? From your code it looks like your second project is a Form application. You might check your solution to make sure you have your form application set up as your start up project. Your dll has no entry point defined so the .Net runtime would throw that error if you set the dll as the start up project.
Nov 30 '10 #4
I'm running the form in it's own project. The form runs fine. It's merely a tester to fill in the fields for my dll. I fill in the fields and then click the button and the call fails because it can't find the entry point of my dll.

Thanks for the help.
Nov 30 '10 #5
I found the following command. When I ran it against my DLL, I got:
Expand|Select|Wrap|Line Numbers
  1. C:\Documents and Settings\40860205\My Documents\Visual Studio 2010\Projects\Agil
  2. eApi\AgileApi\bin\Debug>"C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\du
  3. mpbin" -exports AgileApi.dll
  4. Microsoft (R) COFF/PE Dumper Version 10.00.30319.01
  5. Copyright (C) Microsoft Corporation.  All rights reserved.
  6.  
  7.  
  8. Dump of file AgileApi.dll
  9.  
  10. File Type: DLL
  11.  
  12.   Summary
  13.  
  14.         2000 .reloc
  15.         2000 .rsrc
  16.         2000 .sdata
  17.         4000 .text
Does this indicate there are no entry points? If so, how do I get an entry point generated into my dll?
Nov 30 '10 #6
Joseph Martell
198 Expert 128KB
I think that you did too thorough of a job of trying to user your dll in your application.

When I remove the following lines from your form project:

Expand|Select|Wrap|Line Numbers
  1.    <DllImportAttribute("AgileApi.dll", EntryPoint:="callAgile", SetLastError:=True, CharSet:=CharSet.Unicode, _
  2.          ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
  3.     Public Shared Function callAgile(ByVal protocol As String, ByVal host As String, ByVal port As Integer, ByVal serviceName As String, ByVal methodName As String, ByVal parms As String()) As String
  4.         'This should use the DLL
  5.     End Function
  6.  
and change the following lines in the form application:

Expand|Select|Wrap|Line Numbers
  1.         Dim myAgile As New DLLTest.AgileApi()
  2.         xml = myAgile.callAgile(protocol, host, port, serviceName, methodName, parms)
  3.  
My code works.

I named my test DLL application "DLLTest" which is why the namespace in the Dim statement is DLLTest. Yours will probably be AgileApi.

I am not entirely sure why you are having the problems that you are having. I would hazard to guess that it has to do with improperly "interop"ing your DLL or improperly importing your COM DLL. Either way, the COM interop classes that you are trying to use are not something that is very familiar to me so I have plumbed the depths of my knowledge at this point.
Dec 7 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
35
by: hasho | last post by:
Why is "call by address" faster than "call by value"?
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
4
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage...
5
by: Amaryllis | last post by:
I'm trying to call a CL which is located on our AS400 from a Windows application. I've tried to code it in different ways, but I seem to get the same error every time. Does anyone have any clue...
13
by: mitchellpal | last post by:
i am really having a hard time trying to differentiate the two..........i mean.....anyone got a better idea how each occurs?
13
by: shsingh | last post by:
I have a class A containing some map as data variables. I creat an object of class A on heap by allocatiing memory by using "malloc". This will return me the required memory but the object is not...
3
by: cberthu | last post by:
Hi all, Is it possible to have two connects in the same rexx script to different DB's? I have to get data form on DB (with specifics selects and filter out some values with RExx) and save the...
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.