Solved

Using vb6 dll in vb.net

Posted on 2009-05-08
11
633 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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now