473,383 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

API declarations with fixed length string

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

Nov 21 '05 #1
3 3877
"Urs Eichmann" <ur***@online.nospam> 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/>
Nov 21 '05 #2
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...


Nov 21 '05 #3
> I would also use StringBuilder (Imports System.Text) Class

Thanks. It worked well with a Stringbuilder.

Urs
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Adrian Parker | last post by:
I'm using the code below in my project. When I print all of these fixed length string variables, one per line, they strings in questions do not properly pad with 0s. strQuantity prints as " ...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
2
by: MLH | last post by:
I have a form module that starts out something like this... Option Compare Database 'Use database order for string comparisons ..... Then there's a line like this in it... Public Const...
5
by: ywchan | last post by:
I would like to convert a string to a fixed length e.g. if fixed length = 10 'abc' -> ' abc' 'abcdefghijklm' -> 'abcdefghij' Is there any simple function in C# can perform this operation?...
3
by: Ken Kast | last post by:
I'm using VBFixedString to create fixed length strings. But I find that the string will merrily allow a string of greater length to be assigned to it. Is this the way things are supposed to work?...
5
by: David Garamond | last post by:
The MySQL manual recommends that we create a "fixed-length row" if possible, for speed (especially scanning speed). A fixed-length row is a row which is comprised of only fixed-length fields. A...
4
by: taskswap | last post by:
I'm converting an application that relies heavily on a binary network protocol. Within this protocol are a lot of byte arrays of character data, like: public unsafe struct MsgAddEntry {...
1
by: Rick Knospler | last post by:
I am trying to convert a vb6 project to vb.net. The conversion worked for the most part except for the fixed length strings and fixed length string arrays. Bascially the vb6 programmer stored all...
2
by: =?Utf-8?B?Z3Jva25yb2xs?= | last post by:
Is there a way that I can define a WebMethod with a parameter that is a fixed length string? I'm using VB.Net 2005 and would like to define a webmethod that will prevent the caller from passing a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.