PC Review


Reply
Thread Tools Rate Thread

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

 
 
DotNetJunkies User
Guest
Posts: n/a
 
      9th Apr 2004
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.
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      10th Apr 2004
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


 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      10th Apr 2004
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$oS$(E-Mail Removed)...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP: Excel Interop objects and checking for nulls? JsjsLim Microsoft Excel Programming 4 10th Nov 2008 01:12 AM
Passing arrays from Excel (VBA) to C# uisng COM interop jlea Microsoft Excel Programming 0 26th Feb 2008 11:52 PM
LPVARIANT param returned from unmanaged dll (.net Interop) evadell@gmail.com Microsoft Dot NET Framework 1 28th Mar 2006 11:58 AM
LPVARIANT param returned from unmanaged dll (.net Interop) evadell@gmail.com Microsoft C# .NET 1 28th Mar 2006 11:58 AM
VB Com Interop with string arrays with NULLs =?Utf-8?B?UGF0cmljayBIb3Ju?= Microsoft Dot NET 0 31st Mar 2004 12:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:22 PM.