Solved

Using vb6 dll in vb.net

Posted on 2009-05-08
11
652 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to just get time from a date 6 48
Code enhancement 4 32
How can I do Unit Testing with Session ? 1 23
Need to sort columns in DataGridView 4 36
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

761 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