PC Review


Reply
Thread Tools Rate Thread

API declarations with fixed length string

 
 
Urs Eichmann
Guest
Posts: n/a
 
      4th Apr 2005
Hello
I'm trying to convert the following VB6 code to VB.NET, but can't seem
to find the right API declaration. Note that the Buffer is an output
field which the API call will fill a value in.

VB6 Code:

[VB6]

Type JAG_STRING_40
Data As String * 40
End Type
Public Declare Function JagRead Lib "jagxapi.dll" (ByVal DataPath As
String, ByVal BufferLen As Integer, Buffer As Any, ReturnLen As Integer)
As Integer

Private Function ReadVariable() as String
Dim Lit01Val As JAG_STRING_40
JagRead("/j1/var01", 40, Lit01Val, jagReturnLength)
ReadVariable = RTrim$(Lit01Val.Data)
end Sub

I tried this declaration, but the returned buffer always seems to be empty:

[VB.NET]

Private Const BUFFER_LEN As Integer = 40

<StructLayout(LayoutKind.Sequential)> Private Structure FixLenBuffer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=BUFFER_LEN)>
Public Data As String

Public Sub New(ByVal vData As String)
Me.Data = LSet(vData, BUFFER_LEN)
End Sub

End Structure

Private Shared mBuffer As FixLenBuffer

Private Declare Ansi Function JagReadApi Lib "jagxapi.dll" Alias
"JagRead" (ByVal DataPath As String, ByVal BufferLen As Short, ByRef
Buffer As FixLenBuffer, ByRef ReturnLen As Short) As Short

Friend Shared Function JagRead(ByVal vVarName As String) As String

Dim retLen As Short
mBuffer = New FixLenBuffer("")
Dim ret As Short = JagReadApi("/j1/" + vVarName, BUFFER_LEN,
mBuffer, retLen)
Return Trim(Left(mBuffer.Data, retLen))

End Function



Any help would be greatly appreciated!

Urs

 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      4th Apr 2005
"Urs Eichmann" <(E-Mail Removed)> schrieb:
> I'm trying to convert the following VB6 code to VB.NET, but can't seem
> to find the right API declaration. Note that the Buffer is an output
> field which the API call will fill a value in.
>
> VB6 Code:
>
> [VB6]
>
> Type JAG_STRING_40
> Data As String * 40
> End Type
> Public Declare Function JagRead Lib "jagxapi.dll" (ByVal DataPath As
> String, ByVal BufferLen As Integer, Buffer As Any, ReturnLen As Integer)
> As Integer


Take a look at the 'VBFixedString' attribute.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
 
Reply With Quote
 
Crouchie1998
Guest
Posts: n/a
 
      4th Apr 2005
Are you looking for someone to totally re-write your finction/API
declaration? If so, attach the 'jagxapi.dll' please

I would also use StringBuilder (Imports System.Text) Class

Declare sb As New System.Text.StringBuilder...






 
Reply With Quote
 
Urs Eichmann
Guest
Posts: n/a
 
      4th Apr 2005
> I would also use StringBuilder (Imports System.Text) Class

Thanks. It worked well with a Stringbuilder.

Urs
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fixed Length String =?Utf-8?B?U2hhd24gQw==?= Microsoft Access Form Coding 5 6th Jun 2005 10:13 PM
String With fixed Length Agnes Microsoft VB .NET 2 3rd Apr 2005 04:45 PM
fixed length string =?Utf-8?B?YWxla20=?= Microsoft Excel Misc 2 25th Aug 2004 11:53 AM
How to get the fixed length of a fixed length string active Microsoft VB .NET 1 21st Nov 2003 09:43 PM
Re: Fixed length String Richard A. Lowe Microsoft C# .NET 0 6th Nov 2003 06:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:10 PM.