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 IntegerVC++ 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!

Need help converting parameters from vb4 example into .NET type
tvenhaus
Try this:
<[In](), Out()>
ByVal MsgArea() As CharGeorgeOu
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
howard dierking - MSFT
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 * passedmsg
_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.