|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Structures for Visual Basic.NET |
« View previous topic :: View next topic » |
Author |
Message
|
Forrest |
Posted: Tue Nov 05, 2002 8:13 pm Post subject: Structures for Visual Basic.NET |
|
|
Newbie
Joined: 05 Nov 2002 Posts: 2 Location: Boulder, CO
|
Problem: I was recieving Reason Code 2044 and 2026 errors when I tried to use various CMQB.bas files in the new Visual Studio.NET.
Solution:
Visual Basic.net doesn't handle declarations the same way VB 6.0 did. Also, the Structure ID is a character array and I had some trouble defining a character array that mq.dll would accept. Here's what I did...
For a character array (used in Structure IDs and Dynamic Q Names) try the following:
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=4)> Public StrucId() As Char 'Structure identifier'
************************************************************
Differences:
1. The marshalas statement contains .ByValArray vs the normal ByValTStr
2. The variable name is followed by () to denote an array
3. The type is Char vs String or String.Char...
************************************************************
and then when you set the variable, try this:
Struc.StrucId = MQOD_STRUC_ID.ToCharArray
************************************************************
Differences:
1. The variable is followed by .ToCharArray to populate the .StrucID object with an array as defined above.
************************************************************
Another Example: for Dynamic Queue Name I used:
Struc.DynamicQName = ("AMQ.*" & Space(43)).ToCharArray
Finally, try using New String(Chr(0), 4) on the other variables that are declared as strings, which do not have values defined (i.e. instead of = "" )
(** The 4 denotes the size of the string and should be changed depending on the variable in the structure that you are using **)
[/b] _________________ -Forrest Smith
MQSeries Analyst
IBM Global Services - SDC West |
|
Back to top |
|
 |
tnse |
Posted: Wed Nov 06, 2002 5:38 am Post subject: |
|
|
Newbie
Joined: 25 Oct 2002 Posts: 5
|
Because I had the same problem with the 'descriptors' giving reason codes 2044 or 2026, I tried your solution but got following message:
An unhandled exception of type 'System.ArgumentException' occurred in amqsgetb.exe
Additional information: Type could not be marshaled because the length of an embedded array instance does not match the declared length in the layout.
Debugging located the following statement giving the problem:
MQOPEN(gHcon, od, O_options, gHobj, CompCode, Reason)
Any suggestions ??
For your information:
Structure MQOD
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=4)> Public StrucId() As Char 'Structure identifier'
Dim Version As Integer 'Structure version number'
Dim ObjectType As Integer 'Object type'
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=4 > Public ObjectName() As Char 'Object name'
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=4 > Public ObjectQMgrName() As Char 'Object queue manager name'
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=4 > Public DynamicQName() As Char 'Dynamic queue name'
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=12)> Public AlternateUserId() As Char 'Alternate user identifier'
Dim RecsPresent As Integer 'Number of object records present'
Dim KnownDestCount As Integer 'Number of local queues opened successfully'
Dim UnknownDestCount As Integer 'Number of remote queues opened successfully'
Dim InvalidDestCount As Integer 'Number of queues that failed to open'
Dim ObjectRecOffset As Integer 'Offset of first object record from start of MQOD'
Dim ResponseRecOffset As Integer 'Offset of first response record from start of MQOD'
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=4)> Public ObjectRecPtr() As Char 'Address of first object record'
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=4)> Public ResponseRecPtr() As Char 'Address of first response record'
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=40)> Public AlternateSecurityId() As Char 'Alternate security identifier'
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=4 > Public ResolvedQName() As Char 'Resolved queue name'
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=4 > Public ResolvedQMgrName() As Char 'Resolved queue manager name'
End Structure |
|
Back to top |
|
 |
Forrest |
Posted: Wed Nov 06, 2002 5:05 pm Post subject: MQOD Object Descriptor in VB.NET Sample Code |
|
|
Newbie
Joined: 05 Nov 2002 Posts: 2 Location: Boulder, CO
|
I have seen that error too... Here's my code for the object descriptor...
Keep in mind:
* The character arrays are only used in the MQOD in the structure identifier and the Dynamic Queue Name. The rest are strings.
*There is a StructLayout command that I found to make the structure work. I'm not sure if it's necessary (I haven't played with it yet), but I know that I use it and it works...
Sample Code for MQOD:
<StructLayout(LayoutKind.Sequential, Size:=MQOD_CURRENT_LENGTH, Pack:=1)> Structure MQOD
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=4)> Public StrucId() As Char 'Structure identifier'
Dim Version As System.Int32 'Structure version number'
Dim ObjectType As System.Int32 'Object type'
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=48)> Public ObjectName As String 'Object name'
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=48)> Public ObjectQMgrName As String 'Object queue manager name'
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=48)> Public DynamicQName() As Char 'Dynamic queue name'
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=12)> Public AlternateUserId As String 'Alternate user identifier'
Dim RecsPresent As System.Int32 'Number of object records present'
Dim KnownDestCount As System.Int32 'Number of local queues opened successfully'
Dim UnknownDestCount As System.Int32 'Number of remote queues opened successfully'
Dim InvalidDestCount As System.Int32 'Number of queues that failed to open'
Dim ObjectRecOffset As System.Int32 'Offset of first object record from start of MQOD'
Dim ResponseRecOffset As System.Int32 'Offset of first response record from start of MQOD'
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=4)> Public ObjectRecPtr As String 'Address of first object record'
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=4)> Public ResponseRecPtr As String 'Address of first response record'
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=40)> Public AlternateSecurityId As String 'Alternate security identifier'
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=48)> Public ResolvedQName As String 'Resolved queue name'
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=48)> Public ResolvedQMgrName As String 'Resolved queue manager name'
End Structure _________________ -Forrest Smith
MQSeries Analyst
IBM Global Services - SDC West |
|
Back to top |
|
 |
tnse |
Posted: Thu Nov 07, 2002 1:46 am Post subject: |
|
|
Newbie
Joined: 25 Oct 2002 Posts: 5
|
Thanks !!
I finally succeeded in getting the example program 'amqsgetb' running.
For this I had to change the structures MQGMO, MQMD and MQOD with your modifications, but the important thing is that I can start using VB.NET for accessing queues.
By the way, I did not use 'StructLayout' but it seems still to work.
Regards,
Edwin |
|
Back to top |
|
 |
SHG |
Posted: Tue Jan 21, 2003 10:44 pm Post subject: |
|
|
Newbie
Joined: 21 Jan 2003 Posts: 2
|
Would you mine to provide some example, couse I've got the same message:
An unhandled exception of type 'System.ArgumentException' occurred in amqsgetb.exe
Additional information: Type could not be marshaled because the length of an embedded array instance does not match the declared length in the layout.
or 2004 error
Thanks,
Nick |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|