473,789 Members | 2,785 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 3406
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 Interoperabilit y 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.AllocHG lobal(1024)

' call your API

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

Marshal.FreeHGl obal(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

"DotNetJunk ies User" <User@-NOSPAM-DotNetJunkies.c om> wrote in message
news:O$******** *****@tk2msftng p13.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 Interoperabilit y 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.AllocHG lobal(1024)

' call your API

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

Marshal.FreeHGl obal(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

"DotNetJunk ies User" <User@-NOSPAM-DotNetJunkies.c om> wrote in message
news:O$******** *****@tk2msftng p13.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
3939
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 "browse" it). So I expected that when I run this program, I get both c1.A and c2.A pointing to the same address, and changing c1.A means that also c2.A changes too. ----- BEGIN example CODE -----------
12
2578
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 problem is that even when it is configured to run under a certain identity through Web.config, the impersonation is not carried through to COM library. Consequently, the code in COM object runs under a local account and any code that needs to access...
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 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...
5
2143
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 recognize that the created array is the same as the declared interface argument. The C# function is expecting to receive a 2 dimensioned array and is declared like this: public object InteropFunc( string s1, object arValues ); What should the ASP...
8
2707
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 is the last argument (e.g., "out obj" in C#) that is returned corrupted. It should be an array of integers. In one simple test App this argument does return an array of integers reliably. In the actual App it returns one or two integer arrays but...
8
5587
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), but I'm looking to understand what scenario might prompt either setting (yes or no). Any clarity you can provide is much appreciated! Thanks kindly.
2
2705
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 a view making it easy to obtain all information for person x. Since a person can have more than one address I thought I could build an array holding a row for each address with each row also been an array to store the fields. The schema is a...
2
1760
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 into my C# code (using the marshaling and all that...). My Question is: Does a multiple data arrays is allocated when marshaling the data from the COM component to my C# component. I mean; Does an array is allocated in the COM side and another...
2
3796
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 that perfroms some work using the CUDA SDK (for programming the nVidia GPU). One of the first methods I wrote is simply to query information about the CUDA devices (video cards).
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10199
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7529
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
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 we have to send another system
2
3700
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.