Solved

Using vb6 dll in vb.net

Posted on 2009-05-08
11
643 Views
Last Modified: 2013-11-26
I have a dll (xxx.dll) that was written for  use with vb6. I don't have the source for it, and the publisher doesn't want to touch it.

I am able to access this fine from vb6. I tried to add it to a vb.net program, but when I try to add the reference to it (Add Reference -> Browse) I get:

"A reference to c:\windows\system32\xxx.dll could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component."

I also tried to register the dll with regsvr32 and got an error about "DllRegisterServer entry point was not found"

An example of how this dll is used in the vb6 program is:

Public Declare Sub SetDataFeedhwnd Lib "XXX.DLL" (ByVal hwnd As Long)

I really do need to get this to work, and I'm pretty much a beginner at vb.net.
0
Comment
Question by:1_21gigawatts
  • 5
  • 4
  • 2
11 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24336928
Try putting the DLL in the same folder as your .Net EXE with one of the following declarations:

    Public Declare Sub SetDataFeedhwnd Lib "XXX.DLL" (ByVal handle As IntPtr)
    Public Declare Sub SetDataFeedhwnd Lib "XXX.DLL" (ByVal handle As Integer)

0
 

Expert Comment

by:lovelimetostitos
ID: 24337544
Have you used tlbexp.exe to create the COM DLL? If not, export it using tlbexp and use the DLL that is generated as the output.

Following is an article on how to do it. It uses C# but it should be pretty much the same in VB.Net.
http://www.developer.com/net/csharp/article.php/1501271

0
 

Expert Comment

by:lovelimetostitos
ID: 24337558
I'm sorry. I should have said tblimp.exe.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:1_21gigawatts
ID: 24340185
OK, I got this partly working by making a new module with this line in it (which gets one function to work)

  Public Declare Sub SetDataFeedhwnd Lib "XXX.DLL" (ByVal hwnd As Long)

Now, I'm in to the next function in the dll, which is:

  Public Declare Function SETUPDATA Lib "XXX.DLL" (ByVal Ticker As String, ByVal description As String, ByVal BarInt As Single, ByVal NumColumns As Long, ByVal Category As String, ByVal FirstDateAvailable As Double) As Long

The compiler doesn't complain about the declaration, but when I call it with

  i = SETUPDATA(Ticker, Description, BarInterval, 3, Category, Today.ToOADate)

I get an error about "Attempted to read or write protected memory..."

There's GOT to be an easy way to do this.

0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 24340287
In general, a LONG in VB6 should be accessed with an Integer (or IntPtr for hWnds) in VB.Net.

Is there a max length on the strings being passed in?  If so, you can try creating a StringBuilder instead, set its capacity to that length, and pass that in place of the Strings.  Change the declaration to accept a System.Text.StringBuilder instead of String.
0
 

Author Comment

by:1_21gigawatts
ID: 24340538
OK, I replaced the declaration with this:

   Public Declare Function NSTSETUPDATA Lib "NSTFEED.DLL" ( _
    ByVal Ticker As System.Text.StringBuilder, _
    ByVal description As System.Text.StringBuilder, _
    ByVal BarInt As Single, _
    ByVal NumColumns As Long, _
    ByVal Category As System.Text.StringBuilder, _
    ByVal FirstDateAvailable As Double _
    ) As Long


and the calling code with this:

        Dim Temp As Integer
        Dim Ticker As New System.Text.StringBuilder()
        Dim Description As New System.Text.StringBuilder()
        Dim BarInterval As Double
        Dim Category As New System.Text.StringBuilder()
        Dim StartDate As Double


                Ticker.Append("EUR/USD")
                Description.Append("Euro/Dollar")
                BarInterval = 0
                Category.Append("Stock")
                StartDate = Today.ToOADate


                Temp = NSTSETUPDATA(Ticker, Description, BarInterval, 3, Category, Today.ToOADate)

And I'm still getting the same error.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24340578
Are all of the values only passed IN?...and not modified by the DLL?...or are some of them supposed to be "ByRef"?
0
 

Author Comment

by:1_21gigawatts
ID: 24340744
No, This is the way it was set up in the vb6 program:

Public Declare Function NSTSETUPDATA Lib "NSTFEED.DLL" (ByVal Ticker As String, ByVal description As String, ByVal BarInt As Single, ByVal NumColumns As Long, ByVal Category As String, ByVal FirstDateAvailable As Double) As Long

0
 

Author Closing Comment

by:1_21gigawatts
ID: 31579461
Changing longs to ints pretty much did the trick. The stringbuilder thing (though I spent way too long chasing it) was unneccessary in this case.
0
 

Author Comment

by:1_21gigawatts
ID: 24344929
So, I beat it into submission. Mostly, all I had to do was change longs to ints, and tweak up the way dates and times are converted. It's all working now. Woo Hoo!
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24345045
Glad ya finally solved it!...  =)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question