Issue in calling VB6 native dll from VB.net Project RRS feed

  • Question

  • I have a vb6 project in which I use a dll library to do some tasks. For that, I add a module which declares all functions of that library such as:

    Declare Function myFunction Lib "abcdapi.dll" (ByVal hVar1 As Long, ByVal hVar2 As Long) As Long

    When I call this function (and many other similar) I'm able to do the work and correct Long pointer is returned. But when I try to do the same thing by VB.net (by importing the same library using dllimport and calling the same function), I get no result. although it does return some pointer but that doesn't produce correct result.

    Private Const ABCD As String = "abcdapi.dll"

    <DllImport(ABCD)> _
    Public Shared Function myFunction(ByVal hVar1 As IntPtr, ByVal hVar2 As IntPtr) As IntPtr
    End Function


    When I try to call the above function, it doesn't work. 

    I even tried creating a dll in my vb6 project using the function and try to use imports keyword to call that new dll but that doesn't work either.

    What could be the issue and how do I make it work.

    Thursday, January 12, 2012 4:13 AM

All replies

  • Hi Parashar,

    You could not use a const variable instead of using "abcdapi.dll" directly. It is a known limit.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    • Marked as answer by Paul Zhou Thursday, January 19, 2012 7:15 AM
    • Unmarked as answer by Rahul Parashar Monday, January 23, 2012 4:55 AM
    Monday, January 16, 2012 9:00 AM
  • Hi Paul, Thanks for your response. But even calling my dll directly doesn't solve my problem.

    Monday, January 23, 2012 4:56 AM
  • Hello Rahul,

    1. What are the IntPtrs that you pass as the parameters to myFunction() ?

    2. Note that memory addresses of objects in managed code must be blittable and must be pinned before they can be represented by IntPtrs.

    3. If possible, please show us your VB.NET code in which myFunction() is called.

    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/
    Monday, January 23, 2012 5:36 AM