Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. PInvoke issue

PInvoke issue

Scheduled Pinned Locked Moved Visual Basic
helpcsharpc++data-structures
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jimjo
    wrote on last edited by
    #1

    am porting a vb library to vb.net. The vb library has an external call to an unmanaged dll. Existing code: //External function declaration Private Declare Function Uncompress& Lib "COMPR.DLL" (ByVal SrcSt$, ByVal SrcLen&, Dest As Any, ByVal DestLen&) //Invocation of external function lReturn = Uncompress(sCompressedResult, Len(sCompressedResult), aResults(ARRAY_START), ByVal lNewLength) [where aResults is a double array. The COMPR.Uncompress function basically uncompress a string 'sCompressedResult' and fills the array aResults. The array is initialized before calling the external function] My understanding is that( Please correct me if I am wrong): a. The third parameter in declaration 'Dest as Any' means a parameter of variant type. b. At invocation, the first element of the double array is passed. i.e., a pointer to the first element in the double array is passed to the external function. c. The Uncompress function expands the compressed data, fills/replaces the double array with values. d. The changed values are available to the caller after the Uncompress function has returned. Now, I have to call the COMPR.Uncompress method from Vb.Net. >From browsing the net, I got a lot of information regarding this( Please correct me if I am wrong): a. We have to mark the parameter as InAttribute(), Out(). b. We should pin the object so that GC does not change address. c. We should pass a pointer TO THE FIRST OBJECT OF THE ARRAY to the native function. d. Array of type double is non-blittable and so we have to do the marshaling. This is the code I wrote: //External method declaration _ Public Shared Function UnCompress(ByVal compressedResult As String, ByVal length As Long, ByRef destinationArrayElement As Object, ByVal newLength As Long) As Long End Function //Invocation 'Pin the object Dim resultsHandle As GCHandle resultsHandle = GCHandle.Alloc(aResults(ARRAY_START), GCHandleType.Pinned) Dim resultsPointer As IntPtr = resultsHandle.AddrOfPinnedObject() 'Invoke returnValue = UnCompress(sCompressedResult, Len(sCompressedResult), resultsPointer, newLength) My problem is that I get the return value correctly, but the array does not get changed....I

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups