471,571 Members | 1,261 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Call Visual C++ DLL using VB.NET

I getting error on calling DLL that was made in VC++ 6 from my vb.net application . i am right clicking on the project in Solution explorer, and trying to add a reference. In the reference window,
under the browse tab, i try to add a reference to my dll. I have also copied that dll into the project directory.
But when i select the dll and click on ok i get a message box saying"A reference to the dll could not be added.
Make sure the file is accessible, and it is a valid assembly or COM component"

I think the dll is native dll.Then how i use pinvoke to access the functions
in it.The dll was made in VC++ 6.0.The name of the DLL is MyDll.dll and its function name is SayHello() which returns the string value.
Any help.
Jun 6 '07 #1
9 16807
Plater
7,872 Expert 4TB
Did you make the function COMvisible?
In the .def file for your .dll project, do you have things like:
Expand|Select|Wrap|Line Numbers
  1. EXPORTS
  2.     ; Explicit exports can go here
  3.     DllCanUnloadNow     PRIVATE
  4.     DllGetClassObject   PRIVATE
  5.     DllRegisterServer   PRIVATE
  6.     DllUnregisterServer PRIVATE
  7.     SayHello
  8.  
I could only ever get MFC c++ .dll files to work, which stinks because i only had a few tiny functions but the mfc made it over a 1meg.
Jun 6 '07 #2
My code for calling Visual C DLL named "MYDll.dll" in vb.net is:

<System.Runtime.InteropServices.DllImport("MyDll.d ll", _
SetLastError:=False)> _
Public Shared Function SayHello(ByVal T_VININ As String) As String
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim tes As String
tes = SayHello("Hello World")
End Sub

however when i compile the code i am getting error :
"Unable to find an entry point name SayHello in DLL MyDll.dll"

how can i resolve this?
Jun 7 '07 #3
Plater
7,872 Expert 4TB
however when i compile the code i am getting error :
"Unable to find an entry point name SayHello in DLL MyDll.dll"
how can i resolve this?
Again, go to your DLL project and re-compile it making sure you have something like:
Expand|Select|Wrap|Line Numbers
  1. EXPORTS
  2.     ; Explicit exports can go here
  3.     DllCanUnloadNow     PRIVATE
  4.     DllGetClassObject   PRIVATE
  5.     DllRegisterServer   PRIVATE
  6.     DllUnregisterServer PRIVATE
  7.     SayHello
  8.  
So that there is an entry point called SayHello in your function. It can't find an entry point because the dll was probably created without one.
Jun 7 '07 #4
Yes it works. but how i pass vb.net buffer array to visual C pointer variable.I want to set the value of m_buffer variable which pass value to dll pointer variable buffer but it gives me the NullException error.(object reference not set to an instance of an object).my code is:

Imports System.Runtime.InteropServices
Dim m_buffer(1024) As Byte

<DllImport("mydll.dll", CallingConvention:=CallingConvention.StdCall)> _
Private Shared Function pckInitPack(ByVal idcode As Integer, ByRef buffer() As Byte) As Byte()
End Function

//form_load
pckInitPack(100, m_buffer)


if i use byval it set m_buffer value to zero.please guide me.
Thanks
Jun 8 '07 #5
Plater
7,872 Expert 4TB
I am unsure if you can correctly pass pointers like that without marking things as "UNSAFE". And I have never gotten unsafe/pointers to work for me, maybe one of the other people can weigh in on this?
Jun 11 '07 #6
Thanks all.its working
Jun 11 '07 #7
i have designed a frontend in .NET(using c#)(GUI application).My problem is in calling the vc++ functions from .net.
When i click the buttons(GUI application) the correspondinf vc++ functions
must be invoked.
Any help plzzz.
Feb 10 '08 #8
Plater
7,872 Expert 4TB
Import your VC++ library functions that you need.
Create your event handlers and have them call the vc++ functions.

Not a brainscratcher there.
Feb 11 '08 #9
Thanks all.its working
Hi

I am having same problem so help me out what you did to solve the problem
Mar 3 '08 #10

Post your reply

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

Similar topics

reply views Thread by Hubert Baumeister | last post: by
10 posts views Thread by bienwell | last post: by
34 posts views Thread by Srinu | last post: by
7 posts views Thread by Saeed Amrollahi | last post: by
32 posts views Thread by Anna Smidt | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

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.