473,659 Members | 3,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:="mi crovin", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True, _
CallingConventi on:=CallingConv ention.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_VIN IN, 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 4530
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("rlp olk.dll", EntryPoint:="mi crovin", _
SetLastError:=T rue, CharSet:=CharSe t.Ansi, _
ExactSpelling:= True, _
CallingConventi on:=CallingConv ention.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(2 55)
Dim T_VINOUT as new StringBuilder(1 08)
Polk.csub(T_VIN IN, T_VINOUT, 98)

I hope this helps,

Nick Hall
"John" <jo**********@a dp.com> wrote in message
news:f6******** *************** **@posting.goog le.com...
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:="mi crovin", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True, _
CallingConventi on:=CallingConv ention.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_VIN IN, 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("rlp olk.dll", EntryPoint:="mi crovin", _
SetLastError:=T rue, CharSet:=CharSe t.Ansi, _
ExactSpelling:= True, _
CallingConventi on:=CallingConv ention.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(2 55)
Dim T_VINOUT as new StringBuilder(1 08)
Polk.csub(T_VIN IN, T_VINOUT, 98)

I hope this helps,

Nick Hall
"John" <jo**********@a dp.com> wrote in message
news:f6******** *************** **@posting.goog le.com...
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:="mi crovin", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True, _
CallingConventi on:=CallingConv ention.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_VIN IN, 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
1926
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. This object reference is passed into another object create within the same
4
3387
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 function call funcRet()is made which returns the expected argument type for the function call by reference funcByRef(class A&); The only way to get around this probelm is to first call the funcRet(), assign its value to a variable and pass that...
5
10326
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 "Add Web Reference" for the same service the same function works appropriately. Here is the client proxy generated from WSDL.exe <System.Web.Services.Protocols.SoapDocumentMethodAttribute("capeconnect:AppSec:AppSecPortType#getApplicationUsers",
6
5578
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 object collection and stanrd using it it starts to fall apart. Clearly there is something about javascript's usage of passing "By ref" that i am not getting. i have had a look on the web and found some examples, but i cant see why my code does not...
6
1466
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 server stub. The client stub has the same functions defined, but they just connect to the server and ask it to call the desired functions. The server stub is a server listening for incoming requests and dispatching them to the appropriate functions...
51
4434
by: Kuku | last post by:
What is the difference between a reference and a pointer?
10
13645
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 function is also modified. Sometimes I wish to work with "copies", in that when I pass in an integer variable into a function, I want the function to be modifying a COPY, not the reference. Is this possible?
10
1624
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 need to say *($a) = 1 as in C or C++. Referencing must be coupled with dereferencing, and PHP is not doing the dereferencing, so why is it call referencing in the first place? (don't tell me PHP automatically dereference... as it will be really...
0
1105
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 times for each page load because of the way I structure my pages (sitehead.asp,sitefoot.asp,sidemain.asp, etc). Thus, i'm trying to compile them as a COM/DLL object and simply create an instance of the object in the global.asa and reference the...
275
12247
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
8428
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
8851
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
8627
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
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
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
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
1737
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.