473,555 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Call Visual C++ DLL using VB.NET

31 New Member
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 17010
Plater
7,872 Recognized Expert Expert
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
danishce
31 New Member
My code for calling Visual C DLL named "MYDll.dll" in vb.net is:

<System.Runtime .InteropService s.DllImport("My Dll.dll", _
SetLastError:=F alse)> _
Public Shared Function SayHello(ByVal T_VININ As String) As String
End Function

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) 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 Recognized Expert Expert
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
danishce
31 New Member
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("myd ll.dll", CallingConventi on:=CallingConv ention.StdCall) > _
Private Shared Function pckInitPack(ByV al 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 Recognized Expert Expert
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
danishce
31 New Member
Thanks all.its working
Jun 11 '07 #7
anishait
1 New Member
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 Recognized Expert Expert
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
atmajdesai
2 New Member
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

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

Similar topics

0
2289
by: Hubert Baumeister | last post by:
Fifth International Conference on eXtreme Programming and Agile Processes in Software Engineering XP2004 June 6-10, 2004, Garmisch-Partenkirchen, Germany http://www.xp2004.org/
0
6684
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J#...
12
2437
by: Gustavo L. Fabro | last post by:
Greetings! Getting straight to the point, here are the results of my experiment. I've included my comments and questions after them. The timing: (The total time means the sum of each line's drawing time. Time is measured in clock ticks (from QueryPerformanceCounter() API). The processor resolution (QueryPerformanceFrequency()) for my
4
3299
by: Cyde Weys | last post by:
I'm currently working on converting a simulator program from Visual Basic 6.0 to Visual C++ .NET. I've figured out most of the stuff, but there's still one thing I haven't gotten to and I've never really had to deal with it before. I'm programming a front-end for what is a compiled Fortran program. The VB source does the following to call...
3
2091
by: Tony Liu | last post by:
Dear All: I create a very simple DLL by using EVC to test the problem. (The platform I am working for those program is WinCE.NET) ******************************************************* The header looks like: #ifdef TESTDLL_EXPORTS #define TESTDLL_API __declspec(dllexport)
10
8183
by: Clint | last post by:
Hey all - I'm having a really confusing problem concerning a web service. Right now, I have an application that needs to call a web service that does nothing but return "true" (this will obviously change once the program's fully built to actually do something, but for testing, it works). The only code I added to the service is below:
10
24050
by: bienwell | last post by:
Hi, I have a question about file included in ASP.NET. I have a file that includes all the Sub functions (e.g FileFunct.vb). One of the functions in this file is : Sub TestFunct(ByVal strInput As String) return (strInput & " test") End Sub
34
2953
by: Srinu | last post by:
Hi all, Can we assign return value of a function to a global variable? As we know, main() will be the first function to be executed. but if the above is true, then we have a function call before main. Please help me calarifying this. The code may be of the form. int f(); int x = f();
7
3509
by: Saeed Amrollahi | last post by:
Dear All Hi I have learned when an object is big, I should pass the object using a reference or pointer to it rather than calling by value. In the following code, I don't gain cosiderable performance with call- by-reference vs. call-by-value. Indeed, the perforamnce is absolutely unconsiderable: #include <vector>
32
2076
by: Anna Smidt | last post by:
I am having an "ambiguous call to overloaded function" error again. This is the function: int nGetProfWidth (int ncols, unsigned ProfSpec) { if ((ProfSpec & PROF_2d) == 0) return ncols; return int(sqrt(ncols)); //HERE THE ERROR IS THROWN }
0
7622
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8060
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7588
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5452
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5171
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1159
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
865
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.