Click here to Skip to main content
15,912,329 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Help Me Pin
Henry Minute10-May-10 1:21
Henry Minute10-May-10 1:21 
QuestionMulty threading question Pin
Pasan1488-May-10 23:08
Pasan1488-May-10 23:08 
AnswerRe: Multy threading question Pin
Dimitri Witkowski9-May-10 0:01
Dimitri Witkowski9-May-10 0:01 
GeneralRe: Multy threading question Pin
Pasan1489-May-10 0:51
Pasan1489-May-10 0:51 
GeneralRe: Multy threading question Pin
Dimitri Witkowski9-May-10 1:29
Dimitri Witkowski9-May-10 1:29 
AnswerRe: Multy threading question Pin
Luc Pattyn9-May-10 1:59
sitebuilderLuc Pattyn9-May-10 1:59 
AnswerRe: Multy threading question Pin
Yosh_10-May-10 2:12
professionalYosh_10-May-10 2:12 
QuestionAdapting a DLL to VB.NET, using PINVOKE Pin
Hrizip8-May-10 8:44
Hrizip8-May-10 8:44 
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


Dim key As New RegKey(&H80000002)


&H80000002 - error code "constant expression not representable as UINT, here is the enumeration for the above mentioned constant.

Public Enum VasKeys  ' as uint32         Here I had to remark away the "as uint32"
        ' Fields
        ClassesRoot = &H80000000
        CurrentUser = &H80000001
        LocalMachine = &H80000002
        Users = &H80000003
    End Enum



* The fourth problem happens in this example of code:



 Dim bytes As Byte() = SerialParser.StringToByteArray(str)
flag2 = Win32Serijski.WriteFile(Me.m_handle, bytes, bytes.Length, (numBytesWritten), o)


Second line, 2nd parameter "bytes" states that: " Value of type '1-dimensional array of Byte' cannot be converted to 'Byte'. "

The pinvoke looks like this:
<DllImport("kernel32", EntryPoint:="WriteFile", SetLastError:=True)> _
    Private Shared Function WriteFile(ByVal handle As IntPtr, ByRef bytes As Byte, ByVal numBytesToWrite As Integer, ByRef numBytesWritten As Integer, ByRef overlapped As OVERLAPPED) As Integer
    End Function


* Next is the problem of casting (BR is BaudRate)

  Private BR As Integer = &H2580
   dcb.BaudRate = DirectCast(Me.BR, UInt32)
It says it cannot cast integer to UINT32


* The fifth problem is as follows

Win32Serijski.GetCommState(Me.m_handle, AddressOf dcb) where dcb is a structure, and addressof demands a method so it wont accept dcb

Here is my DCB structure

Public Structure DCB
        Public DCBlength As UInt32
        Public BaudRate As UInt32
        Public Flags As UInt32
        Public wReserved As UInt16
        Public XonLim As UInt16
        Public XoffLim As UInt16
        Public ByteSize As Byte
        Public Parity As Byte
        Public StopBits As Byte
        Public XonChar As Byte
        Public XoffChar As Byte
        Public ErrorChar As Byte
        Public EofChar As Byte
        Public EvtChar As Byte
        Public wReserved1 As UInt16
    End Structure


* Finally I am having problems with the callback wrapper

wrapper = New CallbackWrapper(Me) '{.DoOnCTS = True, .BoolData = Me.m_old_cts}

It will not accept the {} portion stating that Value of type 'Jebemtisvepospisku.Port' cannot be converted to 'Integer'.

This is my callback wrapper:

Friend Class CallbackWrapper
    ' Methods
    Friend Sub New(ByVal parent As Jebemtisvepospisku.Port)
        Me._parent = parent
    End Sub

    Friend Sub ChangeToMainThread(ByVal o As Object, ByVal ea As EventArgs)
        Me._parent.DoEvent(Me)
    End Sub


    ' Fields
    Friend BoolData As Boolean = False
    Friend DoOnCTS As Boolean = False
    Friend DoOnDCD As Boolean = False
    Friend DoOnDSR As Boolean = False
    Friend DoOnForceClose As Boolean = False
    Friend DoOnRead As Boolean = False
    Friend DoOnRI As Boolean = False
    Friend DoOnWritten As Boolean = False
    Friend IntData As Integer = 0
    Private _parent As Jebemtisvepospisku.Port = Nothing
    Friend StringData As String = Nothing
End Class


I have no idea why the value of my .port class turns out to be anything, it should not have a value yet the callback wrapper (which I copy pasted from another example) requires an integer. I was trying to handle threading, and this SHOULD in theory be used to switch between main thread and other threads , depending on which event occurs.


I wish to thank you for your help (if any, lol) in advance!
AnswerRe: enum, hex literals Pin
Luc Pattyn8-May-10 9:29
sitebuilderLuc Pattyn8-May-10 9:29 
GeneralRe: enum, hex literals Pin
Hrizip8-May-10 10:38
Hrizip8-May-10 10:38 
GeneralRe: enum, hex literals Pin
Hrizip8-May-10 22:10
Hrizip8-May-10 22:10 
GeneralRe: enum, hex literals Pin
Luc Pattyn9-May-10 2:02
sitebuilderLuc Pattyn9-May-10 2:02 
GeneralRe: enum, hex literals Pin
Hrizip9-May-10 2:36
Hrizip9-May-10 2:36 
AnswerRe: P/Invoke Pin
Luc Pattyn8-May-10 9:38
sitebuilderLuc Pattyn8-May-10 9:38 
GeneralRe: P/Invoke Pin
Hrizip8-May-10 10:42
Hrizip8-May-10 10:42 
GeneralRe: P/Invoke Pin
Luc Pattyn8-May-10 10:51
sitebuilderLuc Pattyn8-May-10 10:51 
GeneralRe: P/Invoke Pin
Hrizip8-May-10 10:56
Hrizip8-May-10 10:56 
AnswerRe: baudrate Pin
Luc Pattyn8-May-10 9:41
sitebuilderLuc Pattyn8-May-10 9:41 
GeneralRe: baudrate Pin
Hrizip8-May-10 22:11
Hrizip8-May-10 22:11 
AnswerRe: RegKey Pin
Luc Pattyn8-May-10 9:46
sitebuilderLuc Pattyn8-May-10 9:46 
GeneralRe: RegKey Pin
Hrizip8-May-10 22:11
Hrizip8-May-10 22:11 
AnswerRe: CallbackWrapper Pin
Luc Pattyn8-May-10 9:50
sitebuilderLuc Pattyn8-May-10 9:50 
AnswerRe: overall Pin
Luc Pattyn8-May-10 9:57
sitebuilderLuc Pattyn8-May-10 9:57 
GeneralRe: overall Pin
Hrizip8-May-10 10:52
Hrizip8-May-10 10:52 
GeneralRe: overall Pin
Luc Pattyn8-May-10 11:04
sitebuilderLuc Pattyn8-May-10 11:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.