Need help converting parameters from vb4 example into .NET type

I am trying to get the following external call into a .dll to work in visual basic.net(2005). I have an example done in vb4 and from vc++6 but I am not sure how to convert parameters to vb.net. The details are:

Custom data types used below:

Type QAddress

Queue As Integer

Group As Integer

End Type

Type ShowBuffer

Version As Long

TransferStatus As Long

TransferSize As Long

reserved(7) As Long

Target As QAddress

OriginalTarget As QAddress

Source As QAddress

OriginalSource As QAddress

Delivery As Long

Priority As Long

Endian As Long

End Type

Global Const SHOW_BUFFER_LEN = 68

Type PSB

TypeOfPsb As Integer

CallDependent As Integer

DelPsbStatus As Long

MsgSeqNumber As MsgSeqNumberType

UmaPsbStatus As Long

PsbReserved(6) As Integer

End Type

VB4:

Declare Function pams_attach_q Lib "dmq.dll" (AttachMode As Long, QAttached As QAddress, QType As Long, ByVal QName As String, QNameLen As Long, NameSpaceList As Any, NameSpaceListLen As Long, Timeout As Long, NullArg1 As Any, NullArg2 As Any) As Long

Declare Function pams_get_msg Lib "dmq.dll" (MsgArea As Any, Priority As Byte, Source As QAddress, Class As Integer, MsgType As Integer, MsgAreaLen As Integer, LenData As Integer, SelFilter As Long, PSB As PSB, ShowBuff As ShowBuffer, ShowBuffLen As Long, LargeAreaLen As Long, LargeSize As Long, NullArg1 As Any) As Long

VB.NET: Is this correct

Declare Function pams_attach_q Lib "dmq.dll" (ByRef AttachMode As Integer, ByRef QAttached As QAddress, ByRef QType As Integer, ByVal QName As String, ByRef QNameLen As Integer, ByRef NameSpaceList As Object, ByRef NameSpaceListLen As Integer, ByRef Timeout As Integer, ByRef NullArg1 As Object, ByRef NullArg2 As Object) As Integer

Declare Function pams_get_msg Lib "dmq.dll" (ByRef MsgArea As Object, ByRef Priority As Byte, ByRef Source As QAddress, ByRef msgClass As Short, ByRef MsgType As Short, ByRef MsgAreaLen As Short, ByRef LenData As Short, ByRef SelFilter As Integer, ByRef PSB As PSB, ByRef ShowBuff As ShowBuffer, ByRef ShowBuffLen As Integer, ByRef LargeAreaLen As Integer, ByRef LargeSize As Integer, ByRef NullArg1 As Object) As Integer

VC++ 6 example:

pams_attach_q(&iAttachMode,adrQueue,&Type,szName,&iNameLen,(int32*)0,(int32*)0,(int32*)&iTimeout,(char*)0,(char*)0);

pams_get_msg(msg_area,&priority,&q_source,&dmq_class,&type,&msg_area_len,&len_data,(int32 *)0,&psb,(struct show_buffer *)0,(int32 *)0,(int32 *)0,(int32 *)0,(char *)0);

What are (int32*)0 and (char*)0 in vb

Do I need to use <MarshalAs> for any of the parameters

Thanks in advance for any help!



Answer this question

Need help converting parameters from vb4 example into .NET type

  • tvenhaus

    Try this:

    <[In](), Out()> ByVal MsgArea() As Char


  • GeorgeOu

    You'll need the MarshalAs attribute on the arrays in the structures. Something like:

    Public Structure ShowBuffer
    Public Version As Integer
    ...
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=7)> _
    Public reserved() As Integer
    End Structure



  • Squirrelz

     

    See this screenshot.>>

    http://i13.photobucket.com/albums/a272/u-might-want-this/Structure-ScreenShot.jpg

    '-------------------------START OF CODE-----------------------------

    Structure personalDetails

    <VBFixedString(4)> Public title As String

    Public firstName As String

    Public last_orSurname As String

    Public address1 As String

    Public address2 As String

    Public region As String

    Public post_ZipCode As String

    Public telNo As Decimal

    End Structure

    '------------------------------------------------------------------------------

     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim you As personalDetails

    you.title = "Mr"

    you.firstName = "Fred"

    you.last_orSurname = "Bloggs"

    you.address1 = "1 any Street"

    you.address2 = "DownTown"

    you.region = "Chicago"

    you.post_ZipCode = "54321"

    you.telNo = 5551234

    End Sub

    '-----------------------END OF CODE-----------------------------------

     

    P.S. The vbFixedString statement limits a string length to whatever you declare.

     

    Regards,

    S_DS.

     

     



  • Toby Buckley

    If you pass the string to the DLL, then ByVal As String should work with the Ansi keyword in the function declaration. If the DLL returns a string, then pass a StringBuilder with the initial capacity set large enough to contain the returned string.


  • howard dierking - MSFT

    The ByVal as string did not work without the ANSI for passing a string to the function, it resulted in a fatal error but adding the ANSI eliminated that. The problem is the string can still not be seen when dequeuing the message. The same thing goes for the return string from the DLL when using a Stringbuilder. Is there something in the managed/unmanaged transistion that is losing the address of the string. When sending or receiving the return status codes are successful but always with empty strings. Any other possibilites for the declare for msg_area parameter Or any other ideas
  • Pockey

    Thanks for the help.

    The remaining problem is with the "msg_Area" parameter passed to the pams_put_msg. It is specified as

    Argument Data Type Mechanism Prototype Access

    msg_area char reference char * passed

    msg_area is defined as:

    For buffer-style messaging, supplies the address of a memory region or a message

    pointer containing the message to be delivered to the target queue of the receiver

    program.

    I am not able to get the buffer declared correctly so that data buffer is passed and readable on the receiving end. The message goes through ok based on a return status and the other parameters can be logged and verified, but the buffer appears to be empty.

    I have tried declaring it as By Val msgArea as String, ByVal msgArea as Object, ByRef msgArea as String, ByVal msgArea as Object,

    <MarshalAs(UnmanagedType.LPTStr)> using both ByVal and ByRef as Sting and ByVal and ByRef as Object,

    <MarshalAs(UnmanagedType.AsAny)> using both ByVal and ByRef as Sting and ByVal and ByRef as Object,

    <MarshalAs(UnmanagedType.VBByRefStr)> using both ByVal and ByRef as Sting and ByVal and ByRef as Object, and adding the ansi in front of the declarations as well.

    The function call is to an unmanaged .dll file from the managed VB.NET world and I believe the definition and handling of strings crossing this boundary is where the probelm is coming from.

    Please respond with any ideas.


  • Need help converting parameters from vb4 example into .NET type