472,378 Members | 1,299 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Com interop: arrays with NULLS truncating when returned to vb.net

I am calling a VB6 dll from a vb.net windows application that returns an array of strings. My issue is it seems to truncate after a NULL character. For Example VB 6 is returning a string with the HEX value of 4E 31 00 00 01 00 20 20 20 20 20 00 00 00 20 20 20 31 32 30. But when it gets back to Vb.net all I have is 4E 31 or N1. Now I can return the same string as a return value of a function and I get it all.

Please Help,

Patrick Horn

---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
Nov 20 '05 #1
4 3275
Hi,

The showing of a string stops when there is a 00 byte in it.
However, normaly it is there in its full lenght and you can extract the
values by looping throught that string,

I hope this helps?

Cor
Nov 20 '05 #2
Hi,

The showing of a string stops when there is a 00 byte in it.
However, normaly it is there in its full lenght and you can extract the
values by looping throught that string,

I hope this helps?

Cor
Nov 20 '05 #3
Patrick,
In addition to Cor's comments relating to the display of strings in .NET
with embedded NULL chars.

I'm not sure if the following is your problem or not, as the following in in
relation to calling a Win32 API, not a COM object per se (VB6 would be
calling a COM object).

See Adam Nathan's book ".NET and COM - The Complete Interoperability Guide"
by SAMS press for details.

Basically because of the way the Interop Marshaler works strings marshaled
from unmanaged code to managed code are terminated at the NULL char.

To "return" your null embedded string (from an API) you can use a
System.IntPtr.

Dim ptr As System.IntPtr
ptr = Marshal.AllocHGlobal(1024)

' call your API

Dim s As String
s = Marshal.PtrToSTringAnsi(ptr, length)

Marshal.FreeHGlobal(ptr)

Where the 1024 is the maximum size of string that can be returned & length
is the actual length of the string returned, its best if length was returned
by the API.

Can you change the VB6 DLL to be an Array of Bytes or Shorts (16 bit
integers) instead of a String?

Note Adam's book covers the interop marshaler in great detail, another
section may have insite into your problem.

Hope this helps
Jay

"DotNetJunkies User" <User@-NOSPAM-DotNetJunkies.com> wrote in message
news:O$*************@tk2msftngp13.phx.gbl...
I am calling a VB6 dll from a vb.net windows application that returns an array of strings. My issue is it seems to truncate after a NULL character.
For Example VB 6 is returning a string with the HEX value of 4E 31 00 00 01
00 20 20 20 20 20 00 00 00 20 20 20 31 32 30. But when it gets back to
Vb.net all I have is 4E 31 or N1. Now I can return the same string as a
return value of a function and I get it all.
Please Help,

Patrick Horn

---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup

engine supports Post Alerts, Ratings, and Searching.
Nov 20 '05 #4
Patrick,
In addition to Cor's comments relating to the display of strings in .NET
with embedded NULL chars.

I'm not sure if the following is your problem or not, as the following in in
relation to calling a Win32 API, not a COM object per se (VB6 would be
calling a COM object).

See Adam Nathan's book ".NET and COM - The Complete Interoperability Guide"
by SAMS press for details.

Basically because of the way the Interop Marshaler works strings marshaled
from unmanaged code to managed code are terminated at the NULL char.

To "return" your null embedded string (from an API) you can use a
System.IntPtr.

Dim ptr As System.IntPtr
ptr = Marshal.AllocHGlobal(1024)

' call your API

Dim s As String
s = Marshal.PtrToSTringAnsi(ptr, length)

Marshal.FreeHGlobal(ptr)

Where the 1024 is the maximum size of string that can be returned & length
is the actual length of the string returned, its best if length was returned
by the API.

Can you change the VB6 DLL to be an Array of Bytes or Shorts (16 bit
integers) instead of a String?

Note Adam's book covers the interop marshaler in great detail, another
section may have insite into your problem.

Hope this helps
Jay

"DotNetJunkies User" <User@-NOSPAM-DotNetJunkies.com> wrote in message
news:O$*************@tk2msftngp13.phx.gbl...
I am calling a VB6 dll from a vb.net windows application that returns an array of strings. My issue is it seems to truncate after a NULL character.
For Example VB 6 is returning a string with the HEX value of 4E 31 00 00 01
00 20 20 20 20 20 00 00 00 20 20 20 31 32 30. But when it gets back to
Vb.net all I have is 4E 31 or N1. Now I can return the same string as a
return value of a function and I get it all.
Please Help,

Patrick Horn

---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup

engine supports Post Alerts, Ratings, and Searching.
Nov 20 '05 #5

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

Similar topics

21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
12
by: Anil Krishnamurthy | last post by:
We have an ASP.NET application that uses COM objects through Interop. The web application requires access to network and database resources and hence, needs to impersonate a domain account. The...
4
by: DotNetJunkies User | last post by:
I am calling a VB6 dll from a vb.net windows application that returns an array of strings. My issue is it seems to truncate after a NULL character. For Example VB 6 is returning a string with the...
5
by: Richard Lewis Haggard | last post by:
I am trying to create multi-dimensioned arrays in conventional ASP pages and pass these arrays as arguments to functions that are in a C# interop assembly. ASP complains because it doesn't...
8
by: John Olbert | last post by:
Subject: Problems with Interop in C# We are having problems using Interop with a Vb6 ActiveX Dll in C# code in Net2 using Vs2005. Below are the signatures of the method that is the problem. It...
8
by: shira | last post by:
I have done a fair bit of searching, but haven't yet been able to find an explanation as to why one would set "ignore nulls" to "yes" when creating an index. I understand what it does (I think),...
2
by: MarkD | last post by:
Hi All, I have a system that stores information about a person, name addresses and so on and I would like to return a single row for each person in an SQL statement. This is so it can be placed in...
2
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using a COM DLL in my C# application (a single process). This COM DLL generates a data array, and by using the interop DLL (generated by VS/TlbImp.exe), I'm getting this array to a safe Array...
2
by: Fredo | last post by:
First of all, I apologize for cross-posting. I posted this on the framework.interop group as well, but haven't received a response yet, so I thought I'd try here... I'm trying to write an app...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.