473,509 Members | 2,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3378
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
3897
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
2542
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
308
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
2122
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
2677
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
5544
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
2694
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
1749
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
3766
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
7234
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
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7344
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
7412
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
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5060
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...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.