By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,962 Members | 1,967 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,962 IT Pros & Developers. It's quick & easy.

How can I call a dll from

P: n/a
I have created the following com class in using VS 2010:

Expand|Select|Wrap|Line Numbers
  1. <ComClass(AgileApi.ClassId, AgileApi.InterfaceId, AgileApi.EventsId)> _
  2. Public Class AgileApi
  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
  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
  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
  24.         Return xml
  25.     End Function
  27. End Class
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
  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
  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)
  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
  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
  36.         ReDim parms(last + 1)
  38.         Dim xml As String
  39.         xml = callAgile(protocol, host, port, serviceName, methodName, parms)
  40.         txtXml.Text = xml
  41.     End Sub
  42. 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 dll and call it from

Thanks for your help.
Nov 23 '10 #1
Share this Question
Share on Google+
6 Replies

Joseph Martell
Expert 100+
P: 196
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

P: 3
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
Expert 100+
P: 196
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

P: 3
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

P: 3
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.
  8. Dump of file AgileApi.dll
  10. File Type: DLL
  12.   Summary
  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
Expert 100+
P: 196
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
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)
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

Post your reply

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