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. Adapting a DLL to VB.NET, using PINVOKE

Adapting a DLL to VB.NET, using PINVOKE

Scheduled Pinned Locked Moved Visual Basic
csharpcomhelpc++
22 Posts 2 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.
  • L Luc Pattyn

    Hi again, in normal situations, you don't need to go into the internals of events, i.e. I don't expect you would need Delegate.Combine at all. In normal circumstances, all the code you would need is what can be found in the MSDN example here[^]. There are three parts: 1. event declaration, with event keyword 2. event set-up, based on AddHandler 3. event processing, which looks like a regular method you have to provide. :)

    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


    If you want my opinion or comment, ask in a forum or on my profile page; I will not participate in frackin' Q&A


    H Offline
    H Offline
    Hrizip
    wrote on last edited by
    #21

    I am looking into it right now, hopefully I will be able to rewrite the functionality of this part of code using normal VB.net syntax as shown on MSDN. That is the only remaining error by the way, I have fixed all the other errors except for this one concerning events and delegates.

    1 Reply Last reply
    0
    • H Hrizip

      I am trying to dissasemble a .net dll via reflector, one that has been in use in our company for ages, as practice. My future task will be to produce similar dll-a that are com interoparabile and activex compliant. I am doing this in VB.net, and I have already been told that this is a big no-no, dlls of this sort are supposed to be made with C++ people say. I would guess that they are stating this because C++ uses pointers (which are heavily used in many DLLs when it comes to pointing to a pointer - i.e. memory location that holds particular relevant info). Be as it may, I wish to proceed building this dll in vb.net to see how far I can get before I am forced to switch to C++ or C#... I have already made a lot of fixes to the code, thus reducing the number of errors from over 120 to 30 which is, I would guess, a good start, but now I am facing several errors that are above my level of knowledge (I am a beginner after all) and I would like to get some information from people who are more experienced than me. * First problem I encountered is the following: (this is an excerpt of code dealing with events that happen on a SERIAL port).

      Public Custom Event OnCTS As OnCTS
      AddHandler(ByVal value As OnCTS)
      Me.OnCTS = DirectCast(Delegate.Combine(DirectCast(Me.OnCTS, Delegate), DirectCast(value, Delegate)), OnCTS)
      End AddHandler
      RemoveHandler(ByVal value As OnCTS)
      Me.OnCTS = DirectCast(Delegate.Remove(DirectCast(Me.OnCTS, Delegate), DirectCast(value, Delegate)), OnCTS)
      End RemoveHandler
      End Event

      This is what the reflector did for me, unfortunately the first "DELEGATE" keyword after DirectCast has an error attached to it: "expression expected". I have tried using "raiseevent" instead but if I use that, another piece of code later will not work. Currently I have this:

      Public Custom Event OnCTS As OnCTS
      AddHandler(ByVal value As OnCTS)

              End AddHandler
      
              RaiseEvent()
      
              End RaiseEvent
      
              RemoveHandler()
      
              End RemoveHandler
          End Event
      

      But I do not know the proper syntax for this nor where to begin. I have only recently started doing event driven code. * A similar error (DELEGATE keyword, "keyword does not name a type") happens in this line of code:

      Me.parent.Invoke(DirectCast(New EventHandler(AddressOf callback.ToMainThread), Delegate))

      * The third problem is in this line of code

      H Offline
      H Offline
      Hrizip
      wrote on last edited by
      #22

      Dim numRef As Byte*
      Fixed numRef = buffer

      I have this thing that puzzles me. :omg: I suppose that fixed means that garbage collector isnt allowed anywhere near the memory location to prevent accidental removal. That I can do in VB.net. :thumbsup: On the other hand I have no idea what Byte* is, seems to me its a pointer, what I do know from debugging is that it seems to retain only the first element in buffer (which is an array of 1023 I think, irrelevant at this point). Does the pointer point only to the first element? :confused: So if you store 1023 bytes in byte* it retains only the first byte? Please help ;) Added more info at 12:00 The next line of code is the following;

      flag2 = Win32.ReadFile(Me.m_handle, numRef, 50, (numBytesRead), AddressOf overlapped)

      numref in this case is taken from the line before and hence flag2 returns boolean true. Interesting thing is, in my patchwork code I use the following

      Dim flag2 As Boolean = False
      Dim numRef As Byte() = Nothing
      numBytesRead = Nothing
      numRef = buffer
      flag2 = False
      flag2 = Win32Serijski.ReadFile(Me.m_handle, numRef, 50, numBytesRead, overl)

      And in contrast to the original code, my flag2 ALWAYS returns TRUE, while in the original code it returns true only if theres NEW data in the buffer. :confused:

      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