[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Trouble upgrading from VB6 to VB.net

Posted on 2006-05-18
5
Medium Priority
?
927 Views
Last Modified: 2012-06-22
I have some code that interfaces with a 3rd party dll and works fine in VB 6, but when I try to upgrade it to .net Im getting some errors.  This Dll receives several structures as parameters, and within these structures are several fixed lengthen strings, and Arrays.      I think passing these is the problem.  Here is the error Im getting when I call a function in the dll:

“Type could not be marshaled because the length of an embedded array instance does not match the declared length in the layout.”

I’ve include several lines that the upgrade wizard changed.
The original code was:

Private Type in_record
path_str As String * 80        
mstrUser_Code As String * 48
TraceFile As String * 80
End type

After .net did its upgrade this is the code produced.
Private Structure in_record
<VBFixedString(80), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=81)> Public path_str() As Char
       
'UPGRADE_WARNING: Fixed-length string size must fit in the buffer.
<VBFixedString(48), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=50)> Public mstrUser_Code() As Char
       
'UPGRADE_WARNING: Fixed-length string size must fit in the buffer.
 <VBFixedString(80), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=81)> Public TraceFile() As Char
End Structure

If just for kicks change these vars to just plan ol strings.  I get this error when the dll is called:
“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”

Any help would be appreciated, thanks.
0
Comment
Question by:huston8481
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 16714475
Try...

    Private Structure in_record
       <VBFixedString(80)> Public path_strAs String
       <VBFixedString(48)> Public mstrUser_Code As String
       <VBFixedString(80)> Public TraceFile As String
    End Structure

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16714476
I missed a space in that first line...

         <VBFixedString(80)> Public path_str As String
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 16714635
the reason for the problem is the where VB 6 allows FIXED LENGTH strings (Dim MyString as String * 80)

VB.NET DOES NOT allow Fixed length strings, except by using the <VBFixedString(80)>  attribute declaration, as noted by Idle_Mind

AW
0
 

Author Comment

by:huston8481
ID: 16731334
Thanks guys I will try out your suggestion and get back to you.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question