473,395 Members | 1,863 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,395 software developers and data experts.

W32 Interop Advice Needed

I have an old Win32 Dll that want to pass a string back to my app
via one of the parameters (not the return value).

I am seeing one way to do this is to dereference a StringBuilder
instance. Is this possible in VB.NET?

Another possible way might be
<MarshalAs (UnmanagedType.VBByRefStr)>

Does anyone have any experience with this?

The documentation for the DLL includes a VB6 decleration
containing keyword 'ByVal' for the string parameter, so I assume
its not passing a BSTR, but rather an address for a null terminated
series of ASCII characters.

I cannot locate an example within the DLL's documentation to
verify that a string has to be presized within VB6 prior to calling
the DLL.

Any insight appreciated.

-John Slagle
-Denver, CO


Nov 20 '05 #1
3 1071
can't you simply use byref?

Public Declare Sub TheFuncation Lib "thedll.dll" (ByRef theString as
String)
dominique
"John Slagle" <jr***************@mindspring.com> wrote in message
news:um**************@TK2MSFTNGP11.phx.gbl...
I have an old Win32 Dll that want to pass a string back to my app
via one of the parameters (not the return value).

I am seeing one way to do this is to dereference a StringBuilder
instance. Is this possible in VB.NET?

Another possible way might be
<MarshalAs (UnmanagedType.VBByRefStr)>

Does anyone have any experience with this?

The documentation for the DLL includes a VB6 decleration
containing keyword 'ByVal' for the string parameter, so I assume
its not passing a BSTR, but rather an address for a null terminated
series of ASCII characters.

I cannot locate an example within the DLL's documentation to
verify that a string has to be presized within VB6 prior to calling
the DLL.

Any insight appreciated.

-John Slagle
-Denver, CO


Nov 20 '05 #2

"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:OR*************@TK2MSFTNGP12.phx.gbl...
can't you simply use byref?
I was stuck in a VB6 mindset. I kept taking out the ByVal and VS.NET kept
putting it back in.

Doing this:

Declare Function error4describe Lib _
"C4FOX.DLL" Alias "error4describeVB" ( _
ByVal c4%, _
ByVal errCode As Int16, _
ByVal extraInfo%, _
ByRef desc1$, _
<MarshalAs(UnmanagedType.LPStr)> ByRef desc2 As String, _
<MarshalAs(UnmanagedType.VBByRefStr)> ByVal desc3 As String _
) As Int16

I Get This (from IL dump):

int16 error4describe(
int32 c4,
int16 errCode,
int32 extraInfo,
string& marshal( ansi bstr) desc1,
string& marshal( lpstr) desc2,
string marshal( byvalstr) desc3)
cil managed preservesig

Originally, I didn't think the BStr was what I wanted ('BYVAL' in the VB6
declaration). But the 'VB' suffix in the Alias hints otherwise.

It does appear as though I can do whatever I need. I just have to
find the right combination.

Thanks.

Public Declare Sub TheFuncation Lib "thedll.dll" (ByRef theString as
String)
dominique
"John Slagle" <jr***************@mindspring.com> wrote in message
news:um**************@TK2MSFTNGP11.phx.gbl...
I have an old Win32 Dll that want to pass a string back to my app
via one of the parameters (not the return value).

Nov 20 '05 #3
On 2004-02-12, John Slagle <jr***************@mindspring.com> wrote:
I have an old Win32 Dll that want to pass a string back to my app
via one of the parameters (not the return value).

I am seeing one way to do this is to dereference a StringBuilder
instance. Is this possible in VB.NET?

Another possible way might be
<MarshalAs (UnmanagedType.VBByRefStr)>

Does anyone have any experience with this?

The documentation for the DLL includes a VB6 decleration
containing keyword 'ByVal' for the string parameter, so I assume
its not passing a BSTR, but rather an address for a null terminated
series of ASCII characters.

I cannot locate an example within the DLL's documentation to
verify that a string has to be presized within VB6 prior to calling
the DLL.

Any insight appreciated.

-John Slagle
-Denver, CO


Pass a System.Text.StringBuilder ByVal...

Dim sb As New StringBuilder(YourLengthHere)
YourFunction(sb)
Return sb.ToString()

HTH
--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
"Yes, it's the right planet, all right, " he said again.
"Right planet, wrong universe. "
Nov 20 '05 #4

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

Similar topics

0
by: keefah | last post by:
Hi, I'm writing a C# web app that uses Outlook to send email. I use a reference to the Microsoft Outlook 11.0 Object Library, but it's giving me problems. I tracked down some stuff on the Net...
0
by: lacour | last post by:
I can't seem to figure out the difference between adding a COM dll reference in VS2003 and by using TLBIMP. I have a COM dll that references another COM dll, and I want the syntax of my...
6
by: Sudha | last post by:
Hi All, I am trying to use COM DLL in my C#. I have added this DLL in referance and all interface are working fine. I have one issue in calling function decleared like: void...
0
by: Greg Bacon | last post by:
I have two C# projects: a production project and NUnit tests for it. I've recently added a test that causes a call into a registered COM component, and now the test fails with a TypeLoadException...
1
by: Jason Huang | last post by:
Hi, I have no problem in creating or modifying a word document in ASP.Net, using C#. However, I don't know how to export database in SQL 2000 or MSAccess to MSWord, given in the ASP.Net and C#...
8
by: Nadav | last post by:
Hi, Introduction: ********************* I am writing a mixed mode application I have a COM module and a .NET module that communicate with each other. The COM exposes a custom sink interface,...
1
by: Stephen Noronha | last post by:
Hi, I am trying a sample app to send an email from my app I am getting a "type not defined error" I have added "Office and Outlook" COM component but still I am getting this error... Please...
4
by: Uraza | last post by:
I am creating an application that is a COM class that will be accessed by that route. It doesn't seem to be being called when I try it. I have created the DLL in the IDE and it also creates the...
1
by: keanep | last post by:
Hi I'd appreciate some advice on how to access legacy C++/Win32 libraries from C#. We have a legacy Win32 application, mostly written in VC7.1, and we want to re-write the GUI and maybe some...
3
by: Gary | last post by:
I am getting the following errors. Retrieving the COM class factory for component with CLSID {0CD44B28-F861-11D0-9B45-006097B00E23} failed due to the following error: 80040154." The code that...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...

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.