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

C dll reference/call works in VB6, not working in VB.NET

I am trying to call a third party company's dll that I have no control
over. They tell me it was written in C. The declaration in VB6 is as
follows:

Private Declare Sub csub Lib "rlpolk.dll" (ByVal T_VININ As String, _
ByVal T_VINOUT As String, ByVal i_bypass As
Integer)

The T_VININ string is 25 characters and the T_VINOUT string is 108. I
have tried to convert the declaration to VB.NET with little success:

Class Polk
<DllImport("c:\rlpolk.dll", EntryPoint:="microvin", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function csub(ByVal T_VININ As String, _
ByVal T_VINOUT As String, ByVal i_byPass As Integer)
End Function
End Class

The call to the routine is:

Polk.csub(T_VININ, T_VINOUT, 98)

When I do this, I get the message that PInvoke cannot return a
Variant.

If I change it to a Sub, the call to the routine returns nothing.
T_VININ is the variable sent to the routine and T_VINOUT should be the
return string. (T_VININ is a VIN number and T_VINOUT is a 108
character explosion of the vin.)

I have tried many combinations including trying to Marshal the
strings, but all have failed. Please help. Thank you.

John Germani
Nov 20 '05 #1
2 4516
A couple of things immediately spring to mind: -

1. It definitely needs to be a Sub!
2. The original VB6 declaration causes the strings to be passed as ANSI
strings rather than Unicode strings (you couldn't directly pass strings as
Unicode using a Declare). Therefore I think the CharSet needs to be
Charset.Ansi.
3. As strings are immutable in VB.NET you should probably declare them As
StringBuilder instead of String. This will ensure that P/Invoke will copy
the data into StringBuilder objects once the call has completed.
4. i_ByPass was declared As Integer in the original, meaning it needs to be
declared As Short in VB.NET (Integer is now 32 bits rather than 16)
5. I notice there is no Alias in the VB6 declaration (which would be the
equivalent of the EntryPoint field). Was this an omission?

That being said I think your declaration needs to look something like the
following: -

Imports System.Text

Class Polk
<DllImport("rlpolk.dll", EntryPoint:="microvin", _
SetLastError:=True, CharSet:=CharSet.Ansi, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Sub csub(ByVal T_VININ As StringBuilder, _
ByVal T_VINOUT As StringBuilder, ByVal i_byPass As Short)
End Function
End Class

And call it like this: -

Dim T_VININ as new StringBuilder(255)
Dim T_VINOUT as new StringBuilder(108)
Polk.csub(T_VININ, T_VINOUT, 98)

I hope this helps,

Nick Hall
"John" <jo**********@adp.com> wrote in message
news:f6*************************@posting.google.co m...
I am trying to call a third party company's dll that I have no control
over. They tell me it was written in C. The declaration in VB6 is as
follows:

Private Declare Sub csub Lib "rlpolk.dll" (ByVal T_VININ As String, _
ByVal T_VINOUT As String, ByVal i_bypass As
Integer)

The T_VININ string is 25 characters and the T_VINOUT string is 108. I
have tried to convert the declaration to VB.NET with little success:

Class Polk
<DllImport("c:\rlpolk.dll", EntryPoint:="microvin", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function csub(ByVal T_VININ As String, _
ByVal T_VINOUT As String, ByVal i_byPass As Integer)
End Function
End Class

The call to the routine is:

Polk.csub(T_VININ, T_VINOUT, 98)

When I do this, I get the message that PInvoke cannot return a
Variant.

If I change it to a Sub, the call to the routine returns nothing.
T_VININ is the variable sent to the routine and T_VINOUT should be the
return string. (T_VININ is a VIN number and T_VINOUT is a 108
character explosion of the vin.)

I have tried many combinations including trying to Marshal the
strings, but all have failed. Please help. Thank you.

John Germani

Nov 20 '05 #2
A couple of things immediately spring to mind: -

1. It definitely needs to be a Sub!
2. The original VB6 declaration causes the strings to be passed as ANSI
strings rather than Unicode strings (you couldn't directly pass strings as
Unicode using a Declare). Therefore I think the CharSet needs to be
Charset.Ansi.
3. As strings are immutable in VB.NET you should probably declare them As
StringBuilder instead of String. This will ensure that P/Invoke will copy
the data into StringBuilder objects once the call has completed.
4. i_ByPass was declared As Integer in the original, meaning it needs to be
declared As Short in VB.NET (Integer is now 32 bits rather than 16)
5. I notice there is no Alias in the VB6 declaration (which would be the
equivalent of the EntryPoint field). Was this an omission?

That being said I think your declaration needs to look something like the
following: -

Imports System.Text

Class Polk
<DllImport("rlpolk.dll", EntryPoint:="microvin", _
SetLastError:=True, CharSet:=CharSet.Ansi, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Sub csub(ByVal T_VININ As StringBuilder, _
ByVal T_VINOUT As StringBuilder, ByVal i_byPass As Short)
End Function
End Class

And call it like this: -

Dim T_VININ as new StringBuilder(255)
Dim T_VINOUT as new StringBuilder(108)
Polk.csub(T_VININ, T_VINOUT, 98)

I hope this helps,

Nick Hall
"John" <jo**********@adp.com> wrote in message
news:f6*************************@posting.google.co m...
I am trying to call a third party company's dll that I have no control
over. They tell me it was written in C. The declaration in VB6 is as
follows:

Private Declare Sub csub Lib "rlpolk.dll" (ByVal T_VININ As String, _
ByVal T_VINOUT As String, ByVal i_bypass As
Integer)

The T_VININ string is 25 characters and the T_VINOUT string is 108. I
have tried to convert the declaration to VB.NET with little success:

Class Polk
<DllImport("c:\rlpolk.dll", EntryPoint:="microvin", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function csub(ByVal T_VININ As String, _
ByVal T_VINOUT As String, ByVal i_byPass As Integer)
End Function
End Class

The call to the routine is:

Polk.csub(T_VININ, T_VINOUT, 98)

When I do this, I get the message that PInvoke cannot return a
Variant.

If I change it to a Sub, the call to the routine returns nothing.
T_VININ is the variable sent to the routine and T_VINOUT should be the
return string. (T_VININ is a VIN number and T_VINOUT is a 108
character explosion of the vin.)

I have tried many combinations including trying to Marshal the
strings, but all have failed. Please help. Thank you.

John Germani

Nov 20 '05 #3

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

Similar topics

7
by: Nick Zdunic | last post by:
I have a remotable object running in my host application. The host starts up and creates the object. Within a method to start the remote object doing its thing it creates an object. ...
4
by: mangi03 | last post by:
Hi, I came acrosss g++ compile errors whenever I make a function call by reference and found out from the test program that compiler is treating the function argument differently when another...
5
by: Mike Logan | last post by:
I used WSDL.exe to generate a client side web proxy for a web service, called the web service, got the results but an array returned by the web service is not in the results. However if I use...
6
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
6
by: enjoying the view | last post by:
I am working on a school project, trying to build a simple RPC stub generator. The idea is that the generator takes a normal python file with functions defined in it and produces a client and...
51
by: Kuku | last post by:
What is the difference between a reference and a pointer?
10
by: Robert Dailey | last post by:
Hi, I noticed in Python all function parameters seem to be passed by reference. This means that when I modify the value of a variable of a function, the value of the variable externally from the...
10
by: Summercool | last post by:
so many places, including the book PHP in a Nutshell, p. 80, it says: $a =& $b # set $a to reference $b if $a reference $b, then while you can say $b =1, you can't really say $a = 1. you...
0
markrawlingson
by: markrawlingson | last post by:
Hello, So I've got a list of functions written in ASP Classic which I include into every page within my application(s). This file is getting quite big and in most scenarios needs to be called 4-5...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
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
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
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
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
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...

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.