473,408 Members | 2,888 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,408 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 3364
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.