I have created the following com class in vb.net using VS 2010: -
<ComClass(AgileApi.ClassId, AgileApi.InterfaceId, AgileApi.EventsId)> _
-
Public Class AgileApi
-
-
#Region "COM GUIDs"
-
' These GUIDs provide the COM identity for this class
-
' and its COM interfaces. If you change them, existing
-
' clients will no longer be able to access the class.
-
Public Const ClassId As String = "38a4d038-7e0b-40f7-9299-4d7b18d5d25f"
-
Public Const InterfaceId As String = "aae5fd64-b9b2-497e-882c-006618d1679f"
-
Public Const EventsId As String = "fb928add-9053-46a7-b124-49183b1cea18"
-
#End Region
-
-
' A creatable COM class must have a Public Sub New()
-
' with no parameters, otherwise, the class will not be
-
' registered in the COM registry and cannot be created
-
' via CreateObject.
-
Public Sub New()
-
MyBase.New()
-
End Sub
-
-
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
-
Dim xml As String
-
-
Return xml
-
End Function
-
-
End Class
-
Then I created a new project with a form to test it. Here's the form code: -
Imports System.Runtime.InteropServices
-
Public Class Form1
-
-
<DllImportAttribute("AgileApi.dll", EntryPoint:="callAgile", SetLastError:=True, CharSet:=CharSet.Unicode, _
-
ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
-
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
-
'This should use the DLL
-
End Function
-
-
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
-
Dim protocol As String
-
protocol = "http"
-
Dim host As String
-
host = txtHostName.Text
-
Dim port As Integer
-
port = Val(txtPortNumber.Text)
-
-
Dim serviceName As String
-
serviceName = txtServiceName.Text
-
Dim methodName As String
-
methodName = txtMethodName.Text
-
Dim parms(5) As String
-
parms(0) = txtParm0.Text
-
parms(1) = txtParm1.Text
-
parms(2) = txtParm2.Text
-
parms(3) = txtParm3.Text
-
parms(4) = txtParm4.Text
-
-
Dim last As Integer
-
For ix As Integer = 4 To 0 Step -1
-
If parms(ix) = "" Then
-
last = ix
-
End If
-
Next
-
-
ReDim parms(last + 1)
-
-
Dim xml As String
-
xml = callAgile(protocol, host, port, serviceName, methodName, parms)
-
txtXml.Text = xml
-
End Sub
-
End Class
-
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.
6 2245
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.
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?
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.
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.
I found the following command. When I ran it against my DLL, I got: -
C:\Documents and Settings\40860205\My Documents\Visual Studio 2010\Projects\Agil
-
eApi\AgileApi\bin\Debug>"C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\du
-
mpbin" -exports AgileApi.dll
-
Microsoft (R) COFF/PE Dumper Version 10.00.30319.01
-
Copyright (C) Microsoft Corporation. All rights reserved.
-
-
-
Dump of file AgileApi.dll
-
-
File Type: DLL
-
-
Summary
-
-
2000 .reloc
-
2000 .rsrc
-
2000 .sdata
-
4000 .text
Does this indicate there are no entry points? If so, how do I get an entry point generated into my dll?
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: -
<DllImportAttribute("AgileApi.dll", EntryPoint:="callAgile", SetLastError:=True, CharSet:=CharSet.Unicode, _
-
ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
-
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
-
'This should use the DLL
-
End Function
-
and change the following lines in the form application: -
Dim myAgile As New DLLTest.AgileApi()
-
xml = myAgile.callAgile(protocol, host, port, serviceName, methodName, parms)
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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) .
|
by: hasho |
last post by:
Why is "call by address" faster than "call by value"?
|
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...
|
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...
|
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...
|
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?
|
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...
|
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...
|
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...
|
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?
...
|
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...
|
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...
|
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...
|
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$) {
}
...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |