473,569 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DLL function works from VB6 and not from VB.NET - HELP!

Hello,

We are currently using a user DLL that when working in VB 6.0 has a user
defined type as a parameter.

Now we are trying to use the same DLL from a vb.net application and are
having some problems getting it to work and we don't know why. Basically
the function is accepting the parameters, and then returning an error and
never performing the update.

Below you will find both the VB6 dll function and user defined type
definition, followed by the VB.NET (2003 version) dll function and structure
definition that we are using. Unfortunately I do not have the source code to
the DLL, so I don't know how the fields are defined in there.

Can someone tell me what may be defined incorrectly, or how I can figure out
why the call is not working? Also, I have tried every type of
UnmanagedType.< string type> in the definitions within the structure (i.e.
LPSTR, etc)

One of these should work, shouldn't they? What else could be happening?

Any help would be appreciated!

Jim

==== Begin VB 6 dll function and type definition ===
Declare Function AddSalesOrderLi neItem Lib "MAXORDR2.D LL" (ByVal OH As Long,
Soedet As SOEDetItem) As Integer

Type SODetail
ORDNUM28 As String * 6 ' String
LINNUM28 As String * 2 ' String
DELNUM28 As String * 2 ' String
STATUS28 As String * 1 ' String
CUSTID28 As String * 7 ' String
PRTNUM28 As String * 15 ' String
EDILIN28 As String * 6 ' String
TAXABL28 As String * 1 ' String
GLXREF28 As String * 32 ' String
CURDUE28 As Long ' Btrieve Date
FILL0128 As String * 2 ' String
ORGDUE28 As Long ' Btrieve Date
FILL0228 As String * 2 ' String
CUSDUE28 As Long ' Btrieve Date
FILL0328 As String * 2 ' String
SHPDTE28 As Long ' Btrieve Date
FILL0428 As String * 2 ' String
SLSUOM28 As String * 2 ' String
REFRNC28 As String * 25 ' String
PRICE28 As Double ' IEEE Float
ORGQTY28 As Double ' IEEE Float
CURQTY28 As Double ' IEEE Float
BCKQTY28 As Double ' IEEE Float
SHPQTY28 As Double ' IEEE Float
CURSHP28 As Double ' IEEE Float
DUEQTY28 As Double ' IEEE Float
INVQTY28 As Double ' IEEE Float
DISC28 As Single ' IEEE Float
STYPE28 As String * 2 ' String
PRNT28 As String * 1 ' String
AKPRNT28 As String * 1 ' String
STK28 As String * 8 ' String
COCFLG28 As String * 3 ' String
FORCUR28 As Double ' IEEE Float
HSTAT28 As String * 1 ' String
SLSREP28 As String * 7 ' String
COMMIS28 As Single ' IEEE Float
DRPSHP28 As String * 10 ' String
QUMQTY28 As Single ' IEEE Float
TAXCDE128 As String * 7 ' String
TAX128 As Double ' IEEE Float
TAXCDE228 As String * 7 ' String
TAX228 As Double ' IEEE Float
TAXCDE328 As String * 7 ' String
TAX328 As Double ' IEEE Float
MCOMP28 As String * 3 ' String
MSITE28 As String * 3 ' String
UDFKEY28 As String * 15 ' String
UDFREF28 As String * 25 ' String
DEXPFLG28 As String * 1 ' String (adChar)
FILLER28 As String * 24 ' String
End Type
====== END VB 6 Type definition
====== Begin VB.NET DLL function and Structure Definition =======
Declare Function AddSalesOrderLi neItem Lib "MAXORDR2.D LL" (ByVal OH As
Int32, ByRef Soedet As SOEDetItem) As Short

<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Ansi)> _
Public Structure SOEDetItem
<MarshalAs(Unma nagedType.LPStr , SizeConst:=6)> Public ORDNUM As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public LINNUM As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public DelNum As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public STATUS As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public CUSTID As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=15)> Public PRTNUM As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=6)> Public EDILIN As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public TAXABL As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=32)> Public GLXREF As
String
Public CURDUE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL01 As
String
Public ORGDUE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL02 As
String
Public CUSDUE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL03 As
String
Public SHPDTE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL04 As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public SLSUOM As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=25)> Public REFRNC As
String
Public PRICE As Double
Public ORGQTY As Double
Public CURQTY As Double
Public BCKQTY As Double
Public SHPQTY As Double
Public CURSHP As Double
Public DUEQTY As Double
Public INVQTY As Double
Public DISC As Single
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public STYPE As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public PRNT As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public AKPRNT As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=8)> Public STK As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=3)> Public COCFLG As
String
Public FORCUR As Double
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public HSTAT As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public SLSREP As
String
Public COMMIS As Single
<MarshalAs(Unma nagedType.LPStr , SizeConst:=10)> Public DRPSHP As
String
Public QUMQTY As Single
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public TAXCDE1 As
String
Public TAX1 As Double '# TAX AMOUNT 1
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public TAXCDE2 As
String
Public TAX2 As Double
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public TAXCDE3 As
String
Public TAX3 As Double '$ TAX AMOUNT 3
<MarshalAs(Unma nagedType.LPStr , SizeConst:=3)> Public MCOMP As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=3)> Public MSITE As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=15)> Public UDFKEY As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=25)> Public UDFREF As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public DEXPFLG As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=25)> Public FILLER As
String
End Structure
==== End vb.net struct definition ======
Nov 20 '05 #1
18 3341
James,
Can someone tell me what may be defined incorrectly, or how I can figure out
why the call is not working? Also, I have tried every type of
UnmanagedType. <string type> in the definitions within the structure (i.e.
LPSTR, etc)


Including ByValTStr? That's the one you should use.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #2
Matthias,

Yes I tried that one too...

Jim

"Mattias Sjögren" <ma************ ********@mvps.o rg> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
James,
Can someone tell me what may be defined incorrectly, or how I can figure outwhy the call is not working? Also, I have tried every type of
UnmanagedType. <string type> in the definitions within the structure (i.e.
LPSTR, etc)


Including ByValTStr? That's the one you should use.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 20 '05 #3
Have you tried declaring the type members as StringBuilder instead of
String? Also, when you do this get rid of the UnmanagedType.L PStr.

HTH
Brian W
"James Radke" <jr*****@wi.rr. com> wrote in message
news:e3******** ********@TK2MSF TNGP12.phx.gbl. ..
Hello,

We are currently using a user DLL that when working in VB 6.0 has a user
defined type as a parameter.

Now we are trying to use the same DLL from a vb.net application and are
having some problems getting it to work and we don't know why. Basically
the function is accepting the parameters, and then returning an error and
never performing the update.

Below you will find both the VB6 dll function and user defined type
definition, followed by the VB.NET (2003 version) dll function and structure definition that we are using. Unfortunately I do not have the source code to the DLL, so I don't know how the fields are defined in there.

Can someone tell me what may be defined incorrectly, or how I can figure out why the call is not working? Also, I have tried every type of
UnmanagedType.< string type> in the definitions within the structure (i.e.
LPSTR, etc)

One of these should work, shouldn't they? What else could be happening?

Any help would be appreciated!

Jim

==== Begin VB 6 dll function and type definition ===
Declare Function AddSalesOrderLi neItem Lib "MAXORDR2.D LL" (ByVal OH As Long, Soedet As SOEDetItem) As Integer

Type SODetail
ORDNUM28 As String * 6 ' String
LINNUM28 As String * 2 ' String
DELNUM28 As String * 2 ' String
STATUS28 As String * 1 ' String
CUSTID28 As String * 7 ' String
PRTNUM28 As String * 15 ' String
EDILIN28 As String * 6 ' String
TAXABL28 As String * 1 ' String
GLXREF28 As String * 32 ' String
CURDUE28 As Long ' Btrieve Date
FILL0128 As String * 2 ' String
ORGDUE28 As Long ' Btrieve Date
FILL0228 As String * 2 ' String
CUSDUE28 As Long ' Btrieve Date
FILL0328 As String * 2 ' String
SHPDTE28 As Long ' Btrieve Date
FILL0428 As String * 2 ' String
SLSUOM28 As String * 2 ' String
REFRNC28 As String * 25 ' String
PRICE28 As Double ' IEEE Float
ORGQTY28 As Double ' IEEE Float
CURQTY28 As Double ' IEEE Float
BCKQTY28 As Double ' IEEE Float
SHPQTY28 As Double ' IEEE Float
CURSHP28 As Double ' IEEE Float
DUEQTY28 As Double ' IEEE Float
INVQTY28 As Double ' IEEE Float
DISC28 As Single ' IEEE Float
STYPE28 As String * 2 ' String
PRNT28 As String * 1 ' String
AKPRNT28 As String * 1 ' String
STK28 As String * 8 ' String
COCFLG28 As String * 3 ' String
FORCUR28 As Double ' IEEE Float
HSTAT28 As String * 1 ' String
SLSREP28 As String * 7 ' String
COMMIS28 As Single ' IEEE Float
DRPSHP28 As String * 10 ' String
QUMQTY28 As Single ' IEEE Float
TAXCDE128 As String * 7 ' String
TAX128 As Double ' IEEE Float
TAXCDE228 As String * 7 ' String
TAX228 As Double ' IEEE Float
TAXCDE328 As String * 7 ' String
TAX328 As Double ' IEEE Float
MCOMP28 As String * 3 ' String
MSITE28 As String * 3 ' String
UDFKEY28 As String * 15 ' String
UDFREF28 As String * 25 ' String
DEXPFLG28 As String * 1 ' String (adChar)
FILLER28 As String * 24 ' String
End Type
====== END VB 6 Type definition
====== Begin VB.NET DLL function and Structure Definition =======
Declare Function AddSalesOrderLi neItem Lib "MAXORDR2.D LL" (ByVal OH As
Int32, ByRef Soedet As SOEDetItem) As Short

<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Ansi)> _
Public Structure SOEDetItem
<MarshalAs(Unma nagedType.LPStr , SizeConst:=6)> Public ORDNUM As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public LINNUM As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public DelNum As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public STATUS As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public CUSTID As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=15)> Public PRTNUM As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=6)> Public EDILIN As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public TAXABL As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=32)> Public GLXREF As
String
Public CURDUE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL01 As
String
Public ORGDUE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL02 As
String
Public CUSDUE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL03 As
String
Public SHPDTE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL04 As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public SLSUOM As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=25)> Public REFRNC As
String
Public PRICE As Double
Public ORGQTY As Double
Public CURQTY As Double
Public BCKQTY As Double
Public SHPQTY As Double
Public CURSHP As Double
Public DUEQTY As Double
Public INVQTY As Double
Public DISC As Single
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public STYPE As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public PRNT As String <MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public AKPRNT As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=8)> Public STK As String <MarshalAs(Unma nagedType.LPStr , SizeConst:=3)> Public COCFLG As
String
Public FORCUR As Double
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public HSTAT As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public SLSREP As
String
Public COMMIS As Single
<MarshalAs(Unma nagedType.LPStr , SizeConst:=10)> Public DRPSHP As
String
Public QUMQTY As Single
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public TAXCDE1 As
String
Public TAX1 As Double '# TAX AMOUNT 1
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public TAXCDE2 As
String
Public TAX2 As Double
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public TAXCDE3 As
String
Public TAX3 As Double '$ TAX AMOUNT 3
<MarshalAs(Unma nagedType.LPStr , SizeConst:=3)> Public MCOMP As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=3)> Public MSITE As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=15)> Public UDFKEY As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=25)> Public UDFREF As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public DEXPFLG As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=25)> Public FILLER As
String
End Structure
==== End vb.net struct definition ======

Nov 20 '05 #4
James,

What if you add

Pack:=4

to the StructLayout attribute?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #5
Brian,

You can't use a stringbuilder class within a structure statement; or at
least I haven't been able to find a way....

Jim

"Brian W" <brianw@gold_de ath_2_spam_rush .com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Have you tried declaring the type members as StringBuilder instead of
String? Also, when you do this get rid of the UnmanagedType.L PStr.

HTH
Brian W
"James Radke" <jr*****@wi.rr. com> wrote in message
news:e3******** ********@TK2MSF TNGP12.phx.gbl. ..
Hello,

We are currently using a user DLL that when working in VB 6.0 has a user
defined type as a parameter.

Now we are trying to use the same DLL from a vb.net application and are
having some problems getting it to work and we don't know why. Basically the function is accepting the parameters, and then returning an error and never performing the update.

Below you will find both the VB6 dll function and user defined type
definition, followed by the VB.NET (2003 version) dll function and structure
definition that we are using. Unfortunately I do not have the source code to
the DLL, so I don't know how the fields are defined in there.

Can someone tell me what may be defined incorrectly, or how I can figure

out
why the call is not working? Also, I have tried every type of
UnmanagedType.< string type> in the definitions within the structure

(i.e. LPSTR, etc)

One of these should work, shouldn't they? What else could be happening?

Any help would be appreciated!

Jim

==== Begin VB 6 dll function and type definition ===
Declare Function AddSalesOrderLi neItem Lib "MAXORDR2.D LL" (ByVal OH As

Long,
Soedet As SOEDetItem) As Integer

Type SODetail
ORDNUM28 As String * 6 ' String
LINNUM28 As String * 2 ' String
DELNUM28 As String * 2 ' String
STATUS28 As String * 1 ' String
CUSTID28 As String * 7 ' String
PRTNUM28 As String * 15 ' String
EDILIN28 As String * 6 ' String
TAXABL28 As String * 1 ' String
GLXREF28 As String * 32 ' String
CURDUE28 As Long ' Btrieve Date
FILL0128 As String * 2 ' String
ORGDUE28 As Long ' Btrieve Date
FILL0228 As String * 2 ' String
CUSDUE28 As Long ' Btrieve Date
FILL0328 As String * 2 ' String
SHPDTE28 As Long ' Btrieve Date
FILL0428 As String * 2 ' String
SLSUOM28 As String * 2 ' String
REFRNC28 As String * 25 ' String
PRICE28 As Double ' IEEE Float
ORGQTY28 As Double ' IEEE Float
CURQTY28 As Double ' IEEE Float
BCKQTY28 As Double ' IEEE Float
SHPQTY28 As Double ' IEEE Float
CURSHP28 As Double ' IEEE Float
DUEQTY28 As Double ' IEEE Float
INVQTY28 As Double ' IEEE Float
DISC28 As Single ' IEEE Float
STYPE28 As String * 2 ' String
PRNT28 As String * 1 ' String
AKPRNT28 As String * 1 ' String
STK28 As String * 8 ' String
COCFLG28 As String * 3 ' String
FORCUR28 As Double ' IEEE Float
HSTAT28 As String * 1 ' String
SLSREP28 As String * 7 ' String
COMMIS28 As Single ' IEEE Float
DRPSHP28 As String * 10 ' String
QUMQTY28 As Single ' IEEE Float
TAXCDE128 As String * 7 ' String
TAX128 As Double ' IEEE Float
TAXCDE228 As String * 7 ' String
TAX228 As Double ' IEEE Float
TAXCDE328 As String * 7 ' String
TAX328 As Double ' IEEE Float
MCOMP28 As String * 3 ' String
MSITE28 As String * 3 ' String
UDFKEY28 As String * 15 ' String
UDFREF28 As String * 25 ' String
DEXPFLG28 As String * 1 ' String (adChar)
FILLER28 As String * 24 ' String
End Type
====== END VB 6 Type definition
====== Begin VB.NET DLL function and Structure Definition =======
Declare Function AddSalesOrderLi neItem Lib "MAXORDR2.D LL" (ByVal OH As Int32, ByRef Soedet As SOEDetItem) As Short

<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Ansi)> _
Public Structure SOEDetItem
<MarshalAs(Unma nagedType.LPStr , SizeConst:=6)> Public ORDNUM As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public LINNUM As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public DelNum As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public STATUS As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public CUSTID As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=15)> Public PRTNUM As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=6)> Public EDILIN As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public TAXABL As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=32)> Public GLXREF As
String
Public CURDUE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL01 As
String
Public ORGDUE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL02 As
String
Public CUSDUE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL03 As
String
Public SHPDTE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL04 As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public SLSUOM As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=25)> Public REFRNC As
String
Public PRICE As Double
Public ORGQTY As Double
Public CURQTY As Double
Public BCKQTY As Double
Public SHPQTY As Double
Public CURSHP As Double
Public DUEQTY As Double
Public INVQTY As Double
Public DISC As Single
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public STYPE As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public PRNT As

String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public AKPRNT As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=8)> Public STK As

String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=3)> Public COCFLG As
String
Public FORCUR As Double
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public HSTAT As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public SLSREP As
String
Public COMMIS As Single
<MarshalAs(Unma nagedType.LPStr , SizeConst:=10)> Public DRPSHP As
String
Public QUMQTY As Single
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public TAXCDE1 As
String
Public TAX1 As Double '# TAX AMOUNT 1
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public TAXCDE2 As
String
Public TAX2 As Double
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public TAXCDE3 As
String
Public TAX3 As Double '$ TAX AMOUNT 3
<MarshalAs(Unma nagedType.LPStr , SizeConst:=3)> Public MCOMP As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=3)> Public MSITE As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=15)> Public UDFKEY As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=25)> Public UDFREF As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public DEXPFLG As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=25)> Public FILLER As
String
End Structure
==== End vb.net struct definition ======


Nov 20 '05 #6
Matthias,

Where do I add that?

Jim

"Mattias Sjögren" <ma************ ********@mvps.o rg> wrote in message
news:ea******** ******@TK2MSFTN GP10.phx.gbl...
James,

What if you add

Pack:=4

to the StructLayout attribute?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 20 '05 #7
Where do I add that?


Change

<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Ansi)>

to

<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Ansi, Pack:=4)>

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #8
Check out this topic in help and see if it helps your situation

Structure may require marshalling attributes to be passed as an argument in
this Declare statement
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003 JUL.1033/vbcon/html/vbup1050.htm

"James Radke" <jr*****@wi.rr. com> wrote in message
news:uk******** ******@tk2msftn gp13.phx.gbl...
Brian,

You can't use a stringbuilder class within a structure statement; or at
least I haven't been able to find a way....

Jim

"Brian W" <brianw@gold_de ath_2_spam_rush .com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Have you tried declaring the type members as StringBuilder instead of
String? Also, when you do this get rid of the UnmanagedType.L PStr.

HTH
Brian W
"James Radke" <jr*****@wi.rr. com> wrote in message
news:e3******** ********@TK2MSF TNGP12.phx.gbl. ..
Hello,

We are currently using a user DLL that when working in VB 6.0 has a user defined type as a parameter.

Now we are trying to use the same DLL from a vb.net application and are having some problems getting it to work and we don't know why. Basically the function is accepting the parameters, and then returning an error and never performing the update.

Below you will find both the VB6 dll function and user defined type
definition, followed by the VB.NET (2003 version) dll function and structure
definition that we are using. Unfortunately I do not have the source code
to
the DLL, so I don't know how the fields are defined in there.

Can someone tell me what may be defined incorrectly, or how I can figure
out
why the call is not working? Also, I have tried every type of
UnmanagedType.< string type> in the definitions within the structure

(i.e. LPSTR, etc)

One of these should work, shouldn't they? What else could be
happening?
Any help would be appreciated!

Jim

==== Begin VB 6 dll function and type definition ===
Declare Function AddSalesOrderLi neItem Lib "MAXORDR2.D LL" (ByVal OH As

Long,
Soedet As SOEDetItem) As Integer

Type SODetail
ORDNUM28 As String * 6 ' String
LINNUM28 As String * 2 ' String
DELNUM28 As String * 2 ' String
STATUS28 As String * 1 ' String
CUSTID28 As String * 7 ' String
PRTNUM28 As String * 15 ' String
EDILIN28 As String * 6 ' String
TAXABL28 As String * 1 ' String
GLXREF28 As String * 32 ' String
CURDUE28 As Long ' Btrieve Date
FILL0128 As String * 2 ' String
ORGDUE28 As Long ' Btrieve Date
FILL0228 As String * 2 ' String
CUSDUE28 As Long ' Btrieve Date
FILL0328 As String * 2 ' String
SHPDTE28 As Long ' Btrieve Date
FILL0428 As String * 2 ' String
SLSUOM28 As String * 2 ' String
REFRNC28 As String * 25 ' String
PRICE28 As Double ' IEEE Float
ORGQTY28 As Double ' IEEE Float
CURQTY28 As Double ' IEEE Float
BCKQTY28 As Double ' IEEE Float
SHPQTY28 As Double ' IEEE Float
CURSHP28 As Double ' IEEE Float
DUEQTY28 As Double ' IEEE Float
INVQTY28 As Double ' IEEE Float
DISC28 As Single ' IEEE Float
STYPE28 As String * 2 ' String
PRNT28 As String * 1 ' String
AKPRNT28 As String * 1 ' String
STK28 As String * 8 ' String
COCFLG28 As String * 3 ' String
FORCUR28 As Double ' IEEE Float
HSTAT28 As String * 1 ' String
SLSREP28 As String * 7 ' String
COMMIS28 As Single ' IEEE Float
DRPSHP28 As String * 10 ' String
QUMQTY28 As Single ' IEEE Float
TAXCDE128 As String * 7 ' String
TAX128 As Double ' IEEE Float
TAXCDE228 As String * 7 ' String
TAX228 As Double ' IEEE Float
TAXCDE328 As String * 7 ' String
TAX328 As Double ' IEEE Float
MCOMP28 As String * 3 ' String
MSITE28 As String * 3 ' String
UDFKEY28 As String * 15 ' String
UDFREF28 As String * 25 ' String
DEXPFLG28 As String * 1 ' String (adChar)
FILLER28 As String * 24 ' String
End Type
====== END VB 6 Type definition
====== Begin VB.NET DLL function and Structure Definition =======
Declare Function AddSalesOrderLi neItem Lib "MAXORDR2.D LL" (ByVal OH As Int32, ByRef Soedet As SOEDetItem) As Short

<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Ansi)> _
Public Structure SOEDetItem
<MarshalAs(Unma nagedType.LPStr , SizeConst:=6)> Public ORDNUM

As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public LINNUM As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public DelNum As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public STATUS As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public CUSTID As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=15)> Public PRTNUM As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=6)> Public EDILIN As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public TAXABL As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=32)> Public GLXREF As String
Public CURDUE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL01 As String
Public ORGDUE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL02 As String
Public CUSDUE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL03 As String
Public SHPDTE As Int32
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public FILL04 As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public SLSUOM As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=25)> Public REFRNC As String
Public PRICE As Double
Public ORGQTY As Double
Public CURQTY As Double
Public BCKQTY As Double
Public SHPQTY As Double
Public CURSHP As Double
Public DUEQTY As Double
Public INVQTY As Double
Public DISC As Single
<MarshalAs(Unma nagedType.LPStr , SizeConst:=2)> Public STYPE As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public PRNT As

String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public AKPRNT As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=8)> Public STK As

String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=3)> Public COCFLG As String
Public FORCUR As Double
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public HSTAT As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public SLSREP As String
Public COMMIS As Single
<MarshalAs(Unma nagedType.LPStr , SizeConst:=10)> Public DRPSHP As String
Public QUMQTY As Single
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public TAXCDE1 As String
Public TAX1 As Double '# TAX AMOUNT 1
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public TAXCDE2 As String
Public TAX2 As Double
<MarshalAs(Unma nagedType.LPStr , SizeConst:=7)> Public TAXCDE3 As String
Public TAX3 As Double '$ TAX AMOUNT 3
<MarshalAs(Unma nagedType.LPStr , SizeConst:=3)> Public MCOMP As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=3)> Public MSITE As
String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=15)> Public UDFKEY As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=25)> Public UDFREF As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=1)> Public DEXPFLG As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=25)> Public FILLER As String
End Structure
==== End vb.net struct definition ======



Nov 20 '05 #9
Matthias,

Nope.. That does not correct the issue either. It's strange because when I
use the ByValTStr, it gives me a 'duplicate record added' message.. but when
I use LPStr it successfully completes, yet the record is never added.....

Any other suggestions?

Jim

"Mattias Sjögren" <ma************ ********@mvps.o rg> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Where do I add that?


Change

<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Ansi)>

to

<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Ansi, Pack:=4)>

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 20 '05 #10

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

Similar topics

10
7497
by: R.G. Vervoort | last post by:
I am using a javafunction (onclick in select) in which i am calling a function in php (thats why i send this to both php and javascript newsgroups). in the onclick i call the function "Place_Selected" with the value from the select (naam_keuze.value) in the function the value becomes the $zoek_id and searches in the database for the...
8
1665
by: Abby Lee | last post by:
My function works but there has got to be a way to make a for loop to handle this...but I can't get a for loop to work. You can tell, I'm not very good at this...help. "myvalue" is the number of miles the person enters "myitem" is the row...there are seven rows where they can list expenses. "myvalue" * .375 = amount to be reimbursed All...
2
9786
by: Chuck Martin | last post by:
I am having a most frustrating problem that references, web searches, and other resources are no help so far in solving. Basically, I'm trying to design a pop-up window to be called with a funciton in a link. that function can have parameters for URL and window name passed to it. This works peachy in Firefox (1.0). With IE 6 (6.0.29) on two...
39
6499
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. When it completes, it can call a success, or a failure function. The names of these success, or failure functions will differ, and I'd like to know...
3
4783
by: Janross | last post by:
I'm having trouble with a query that's prohibitively slow. On my free-standing office computer it's fine (well, 2-4 seconds), but on the client's network, it takes at least 5 minutes to run. Obviously not workable! I know where the problem is, I just don't know how to fix it. The query calls a function, and I assume it gets slow because...
0
1825
by: Michael L | last post by:
Hi Guys(I apologize for the lengty post - Im trying to explain it as best i can) I've been cracking my head on this one for the past 24+ hours and i have tried creating the function in ten different ways and none of the versions i've made works exactly as it should. I have an array called $PageArray which contains a sorted list of all...
7
3561
by: Schmidty | last post by:
Okay...I have another 'newbie' question; I have a function that loads a page and the action is $_SERVER; In the form that is in a function(method?) within a class a variable is passed back to a mysqli connection and database and updates the database. The problem is that when the page is reloaded it does not show the updated information...
17
8079
by: DanielJohnson | last post by:
how to use the combination function in python ? For example 9 choose 2 (written as 9C2) = 9!/7!*2!=36 Please help, I couldnt find the function through help.
20
2201
by: MikeC | last post by:
Folks, I've been playing with C programs for 25 years (not professionally - self-taught), and although I've used function pointers before, I've never got my head around them enough to be able to think my way through what I want to do now. I don't know why - I'm fine with most other aspects of the language, but my brain goes numb when I'm...
0
7700
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...
0
7614
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...
0
7924
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. ...
0
7974
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...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
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
0
938
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...

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.