Solved

Using vb6 dll in vb.net

Posted on 2009-05-08
11
655 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 86

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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

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 86

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 86

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 86

Expert Comment

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

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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