Can anyone show me an example of connecting to the Postal AMS zip4_w32.dll Using C#
-
Tuesday, August 07, 2012 6:39 PM
Can anyone show me an example of connecting to the Postal AMS zip4_w32.dll Using C# or (VB.NET)
I'm been given an assignment to re-write a 15+ year old VB6 interface to the US Postal Service Address Management System (AMS) zip4_w32.dll. I've run into numerous errors accessing unsafe memory, marshalling problems and mis-matched structures. A working example of one or two function calls (z4opencfgSTD or z4adrinq) would really be very helpful.
Thanks
Dale
All Replies
-
Wednesday, August 08, 2012 9:01 AM
Please check these two links:
Unable to get z4opencfgSTD() method working on USPS AMS (Address matching system) to work under web/vb.net Interop project. Please help :http://social.msdn.microsoft.com/Forums/pl/vbinterop/thread/242b74a8-045d-4ffd-b6db-74506f93d95c
pInvoke question (return type char*) :http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/df6ba613-43e7-4194-a687-15120e92ecf7/
No code, No fact.
-
Wednesday, August 08, 2012 5:07 PM
Thanks for the response. I implemented the code from the first link and got the following error:
Cannot marshal 'parameter #1': Invalid managed/unmanaged type combination (this value type must be paired with Struct).
The second link was useful in general, but did not give me any answers to my error. The dll that I am trying to interface with (zip4_w32.dll) is put out by the U.S. Postal Service. Talking to "customer support" is not likely. In fairness to them, the source code that the DLL is derived from is compiled for Windows, Sun UNIX, AIX and LINUX. Their knowledge of .NET is minimal to non-existance. I have read numerous pages from the Web on this subject, but have found none with an anwswer.
I created an equivalent C# program which produces the same error. Thanks for any additional guidance. My code is as follows:
Imports System.IO
Imports System.Data.SqlClient
Imports System.Globalization
Imports ADODB
Imports System.Security.Permissions
Imports System.Net
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Runtime.ConstrainedExecutionPublic Class AddressLookup1
Dim rAMS As New AddressMatchingSystem.cAMS
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure CONFIG_PARM
<MarshalAs(UnmanagedType.LPStr)> Public address1 As String
<MarshalAs(UnmanagedType.LPStr)> Public addrindex As String
<MarshalAs(UnmanagedType.LPStr)> Public cdrom As String
<MarshalAs(UnmanagedType.LPStr)> Public citystate As String
<MarshalAs(UnmanagedType.LPStr)> Public crossref As String
<MarshalAs(UnmanagedType.LPStr)> Public system As String
<MarshalAs(UnmanagedType.LPStr)> Public elot As String
<MarshalAs(UnmanagedType.LPStr)> Public elotindex As String
<MarshalAs(UnmanagedType.LPStr)> Public llkpath As String
<MarshalAs(UnmanagedType.LPStr)> Public ewspath As String
<MarshalAs(UnmanagedType.LPStr)> Public dpvpath As String
<MarshalAs(UnmanagedType.LPStr)> Public fnsnpath As String
<MarshalAs(UnmanagedType.LPStr, SizeConst:=124)> Public rsvd As String
End Structure<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure Z4OPEN_PARM
<MarshalAs(UnmanagedType.LPStr, SizeConst:=50)> Public rsvd1 As String
<MarshalAs(UnmanagedType.I4)> Public status As Integer
<MarshalAs(UnmanagedType.LPStr)> Public fname As String
<MarshalAs(UnmanagedType.Struct)> Public config As CONFIG_PARM
<MarshalAs(UnmanagedType.LPStr, SizeConst:=1)> Public ewsflag As String
<MarshalAs(UnmanagedType.LPStr, SizeConst:=1)> Public elotflag As String
<MarshalAs(UnmanagedType.LPStr, SizeConst:=1)> Public llkflag As String
<MarshalAs(UnmanagedType.LPStr, SizeConst:=1)> Public dpvflag As String
<MarshalAs(UnmanagedType.LPStr, SizeConst:=1)> Public systemflag As String
<MarshalAs(UnmanagedType.LPStr, SizeConst:=511)> Public rsvd2 As String
End StructureDim openparm As New Z4OPEN_PARM
Dim configparm As New CONFIG_PARMPrivate Sub AddressLookup1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
<DllImport("zip4_w32.dll", CallingConvention:=CallingConvention.StdCall, EntryPoint:="z4opencfgSTD", ExactSpelling:=False), ReliabilityContract(Consistency.WillNotCorruptState, Cer.None)> _
Public Shared Function z4opencfgSTD(<[In](), Out()> <MarshalAs(UnmanagedType.LPStruct)> ByRef parm As Z4OPEN_PARM) As Integer
End FunctionPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim intRet As Integer = z4opencfgSTDVB()
txtErrorMessage.Text = intRet.ToString
End Sub
Public Shared Function z4opencfgSTDVB()
Dim objz4open_parm As New Z4OPEN_PARM()
' my code
Dim address1 As String = "c:\inetpub\amsdata"
Dim addrindex As String = "c:\inetpub\amsdata"
Dim citystate As String = "c:\inetpub\amsdata"
Dim crossref As String = "c:\inetpub\amsdata"
Dim fnsnpath As String = "c:\inetpub\amsdata"
Dim elot As String = "c:\inetpub\amsdata"
Dim elotindex As String = "c:\inetpub\amsdata"
Dim llkpath As String = "c:\inetpub\amsdata"
Dim dpvpath As String = "c:\inetpub\amsdata"
Dim systempath As String = "c:\inetpub\amsdata"
Dim ewspath As String = ""
Dim rsvd_string As New StringBuilder
Dim rsvd As String = ""
rsvd.PadLeft(124)
Dim rsvd1 As String = ""
rsvd1.PadLeft(50)
Dim rsvd2 As String = ""
rsvd2.PadLeft(511)
Dim cdrom As String = ""
Dim fname As String = ""objz4open_parm.config.address1 = address1
objz4open_parm.config.addrindex = addrindex
objz4open_parm.config.cdrom = cdrom
objz4open_parm.config.citystate = citystate
objz4open_parm.config.crossref = crossref
objz4open_parm.config.system = systempath
objz4open_parm.config.elot = elot
objz4open_parm.config.elotindex = elotindex
objz4open_parm.config.llkpath = llkpath
objz4open_parm.config.dpvpath = dpvpath
objz4open_parm.config.fnsnpath = fnsnpath
'end of my codeobjz4open_parm.status = 2
objz4open_parm.dpvflag = "Y"
objz4open_parm.elotflag = "Y"
objz4open_parm.ewsflag = "N"
objz4open_parm.fname = fname
objz4open_parm.llkflag = "Y"
objz4open_parm.systemflag = "Y"rsvd.PadLeft(124)
rsvd1.PadLeft(50)
rsvd2.PadLeft(511)Dim iz4opencfgSTDReturn As Integer
iz4opencfgSTDReturn = z4opencfgSTD(objz4open_parm)
Return iz4opencfgSTDReturn
End FunctionEnd Class
Dale W Scott
-
Wednesday, August 08, 2012 5:17 PM
I'd marshal the strings with a sizeconst as ByValTStr, not LPStr.
Don't you have the orginal structure declaration somewhere? Or the VB6 pendant? If the latter works we can translate it.
Armin
-
Wednesday, August 08, 2012 7:36 PM
Thanks Armin for your interest in solving this problem. Changing from LPStr to ByValTStr yielded the same error.
I have included the VB6 interfaces, the VB6 types and the C++ structures. Any help you could lend would be appreciated.
' VB6 Interfaces
'ZIP4_W32 procedures from Win32 API
Private Declare Function z4opencfgSTD Lib "zip4_W32.DLL" (ByRef parm As Any) As Integer 'open the retrieval engine
Private Declare Function z4verSTD Lib "zip4_W32.DLL" (ByRef parm As Any) As Integer 'Get the version
Private Declare Function z4geterrorSTD Lib "zip4_W32.DLL" (ByRef parm As Any) As Integer 'Get the version
Private Declare Function z4getenvSTD Lib "zip4_W32.DLL" (ByRef parm As Any) As Integer 'Get the version
Private Declare Function z4openSTD Lib "zip4_W32.DLL" () As Integer 'open the retrieval engine
Private Declare Function z4LLkGetKey Lib "zip4_W32.DLL" () As Integer 'open the retrieval engine
Private Declare Function z4closeSTD Lib "zip4_W32.DLL" () As Integer 'close the retrieval engine
Private Declare Function z4adrinqSTD Lib "zip4_W32.DLL" (ByRef parm As Any) As Integer 'address inquiry
Private Declare Function z4scrollSTD Lib "zip4_W32.DLL" (ByRef parm As Any) As Integer 'address inquiry
Private Declare Function z4adrstdSTD Lib "zip4_W32.DLL" (ByRef parm As Any, ByVal nIndex As Integer) As Integer 'address sort key generation
Private Declare Function z4adrkeySTD Lib "zip4_W32.DLL" (ByRef parm As Any) As Integer 'address sort key generation
Private Declare Function z4adrnxtSTD Lib "zip4_W32.DLL" (ByRef parm As Any) As Integer
Private Declare Function z4DpvGetLastErrorCodeSTD Lib "zip4_W32.DLL" () As Long 'DPV error
Private Declare Function z4DpvGetLastErrorMsgSTD Lib "zip4_W32.DLL" () As String 'DPV error
Private Declare Function z4DpvGetKeySTD Lib "zip4_W32.DLL" () As String 'DPV error' VB6 Types
Private Type ZIP4_PARM
'****************Input Data**********************************************
'relver As Long 'release version
relver As String * 4 'release version
iadl1 As String * 51 'Input address one
iadl2 As String * 51 'Input firm
ictyi As String * 51 'Input City
istai As String * 3 'Input State
izipc As String * 11 'Input zip
iprurb As String * 29 'Input Puerto Rican Urbanization name
iadl3 As String * 51 'Input address two
iddpv11 As String * 13 'input value for direct DPV
rsvd1 As String * 85 'Reserved for future use
'***************Returned Data********************************************
dadl3 As String * 51 'Normalize Output street address 2
dadl1 As String * 51 'Normalize Output street address 1
dadl2 As String * 51 'Normalized Output firm name
dlast As String * 51 'Normalized city/state/zip+4
dprurb As String * 29 'Normalized Puerto Rican urbanization name
dctys As String * 29 'main post office City
dstas As String * 3 'main post office State
dctya As String * 29 'Normalized Output City
abcty As String * 14 'Standard city abbreviation
dstaa As String * 3 'Normalized output State
zipc As String * 6 '5 digit ZIP code
addon As String * 5 '4 digit add-on code
dpbc As String * 4 '2 digit delivery pint barcode adn 1 digit check digit
cris As String * 5 '4 digit carrier toute code
county As String * 4 '3 digit county code
respn As Integer 'Number of returned Code (short)
'respn As String * 2 'Number of returned Code
retcc As Byte 'Return Code
adrkey(11) As Byte 'Address key (for indexing)
auto_zone_ind As String * 1 'Carrier Route Rate Sort Indicator (Y or N)
LotNum As String * 5 'LOT number
LotCode As String * 1 'LOT Ascending/Descending Flag
Llk_rc As String * 3 'LACS link return code
Llk_ind As String * 1 'LACS link indicator
Misc As String * 129 'line for unused input data
rsvd2 As String * 20 'reserved for future use
'***************Parsed Input Data****************************************
ppnum As String * 11 'Primary House number
psnum As String * 9 'Secondary suite/unit number
prote As String * 4 'Rural Route Number
punit As String * 5 'Unit type STE for Suite
ppre1 As String * 3 'First or left pre-direction
ppre2 As String * 3 'second or right pre-direction
psuf1 As String * 5 'First or left suffix
psuf2 As String * 5 'Second or right suffix
ppst1 As String * 3 'First or left post-direction
ppst2 As String * 3 'Second or right Post-direction
ppnam As String * 29 'Street Name
mpnum As String * 11 'Matched Primary street number
msnum As String * 9 'Matched secondary Suite/Unit number
pmb As String * 4 'PMB Unit Designator
pmbnum As String * 9 'PMB Number
mlevl As String * 1 'reserved use
footnotes As String * 33 'New footnote string that has the footnote letter and # as A#B#
stelnkfoot As String * 4 'suite link footnote
punit2 As String * 5 'second or right Secondary Unit
psnum2 As String * 9 'second or right Secondary Number
rsvd3 As String * 10 'Reserve for future use
footnote As ZIP4_FOOT 'Footnotes (old structure)
stack(10 - 1) As ADDR_REC 'The record stack
rsvd4 As String * 194 'Reserve for future use
End TypePrivate Type ENV_PARM
configfile As String * 301 'Contains the full path of the ZADRFLE.DAT file
address1 As String * 301 'Contains the full path of the ZADRFLE.DAT file
addrindex As String * 301 'Contains the full path of the ZADRFLE.NDX file
cdrom As String * 301 'Contains the drive letter of the CD-ROM drive that
'contains the ZIP+4/carrier route datamay be blank
citystate As String * 301 'Contains the full path of the following files:
'CTYSTATE.DAT -CTYSTATE.NDX
'ZIP5FLE.DAT -ZIP5FLE.NDX
crossref As String * 301 'Contains the full path of the ZXREFDTL.DAT file
system As String * 301 'Contains the full path of the Z4CXLOG.DAT file
elot As String * 301 'Contains the full path of the ltrvfle.dat file
elotindex As String * 301 'Contains the full path of the ltrvfle.ndx file
llkpath As String * 301 'Contains the full path of the lacs file
ewspath As String * 301 'Contains the full path of the ews file
fnsnpath As String * 301 'Contains the full path of the fnsn files
stelnkpath As String * 301 'Added 8/8/2011
abrstpath As String * 301 'Added 8/8/2011
'rsvd As String * 300 'reserved use (old config)
rsvd As String * 1208 'changed to 1208
stelnkflag As String * 1 'added
abrstflag As String * 1 'added
ewsflag As String * 1 'pushed down
elotflag As String * 1
llkflag As String * 1
dpvflag As String * 1
End TypePrivate Type CONFIG_PARM
'address1 As String 'Contains the full path of the ZADRFLE.DAT file
'addrindex As String 'Contains the full path of the ZADRFLE.NDX file
'cdrom As String 'Contains the drive letter of the CD-ROM drive that
'contains the ZIP+4/carrier route datamay be blank
'citystate As String 'Contains the full path of the following files:
'CTYSTATE.DAT -CTYSTATE.NDX
'ZIP5FLE.DAT -ZIP5FLE.NDX
'crossref As String 'Contains the full path of the ZXREFDTL.DAT file
'system As String 'Contains the full path of the Z4CXLOG.DAT file
'elot As String 'Contains the full path of the ltrvfle.dat file
'elotindex As String 'Contains the full path of the ltrvfle.ndx file
'llkpath As String 'Contains the full path of the lacs file
'ewspath As String 'Contains the full path of the ews file
'dpvpath As String 'Contains the full path of the dpv files
'fnsnpath As String 'Contains the full path of the fnsn files
'stelnkpath As String 'Added
'abrstpath As String 'Added
address1 As Long 'Contains the full path of the ZADRFLE.DAT file
addrindex As Long 'Contains the full path of the ZADRFLE.NDX file
cdrom As Long 'Contains the drive letter of the CD-ROM drive that
'contains the ZIP+4/carrier route datamay be blank
citystate As Long 'Contains the full path of the following files:
'CTYSTATE.DAT -CTYSTATE.NDX
'ZIP5FLE.DAT -ZIP5FLE.NDX
crossref As Long 'Contains the full path of the ZXREFDTL.DAT file
system As Long 'Contains the full path of the Z4CXLOG.DAT file
elot As Long 'Contains the full path of the ltrvfle.dat file
elotindex As Long 'Contains the full path of the ltrvfle.ndx file
llkpath As Long 'Contains the full path of the lacs file
ewspath As Long 'Contains the full path of the ews file
dpvpath As Long 'Contains the full path of the dpv files
fnsnpath As Long 'Contains the full path of the fnsn files
stelnkpath As Long 'Added
abrstpath As Long 'Added
'rsvd As String * 124 'Old
rsvd As String * 116 'Changed
End TypePrivate Type Z4OPEN_PARM
rsvd1 As String * 50 'reserved for future use
Status As Byte '1 - Used value pointed to by fname
'2 - Used values in CONFIG_PARM
'9 - No values found. Searched for z4config.dat
Status1 As Byte 'Holder for Short variable in C
'fname As String 'pointer to a NULL terminated string that
fnameptr As Long 'pointer to a NULL terminated string that
'contains the full path and filename for a
'custom config file. If fname contains a
'leading space or NULL then it is ignored and
'the CONFIG_PARM is evaluated for path names
config As CONFIG_PARM 'Contains the path names for the config file
ewsflag As String * 1 'Y Enables ews else Disable ews
elotflag As String * 1 'Y Enables eLOT else Disable eLOT
llkflag As String * 1 'usage discontinued
dpvflag As String * 1 'usage discontinued
systemflag As String * 1 'set to Y to deactivate generation of security file
rtsw As String * 16 'Added 8/8/2011
dpvtypeflag As String * 1 'Added
stelnkflag As String * 1 'Added
abrstflag As String * 1 'Added
rsvd2 As String * 492 'changed 8/8/2011
'rsvd2 As String * 511 'reserved for future use (old)
End Type
The above types were derived from the following C++ structures:for type Z4_PARM
typedef struct
{
/*********input data*****************/
char rsvd0[4]; /* reserve fore future use */
char iadl1[50+1]; /* input delivery address */
char iadl2[50+1]; /* input firm name */
char ictyi[50+1]; /* input city */
char istai[2+1]; /* input state */
char izipc[10+1]; /* input ZIP+4 code */
char iprurb[28+1]; /* input urbanization name */
char iad13[50+1]; /* input second address line */
char iddpv11[12+1]; /* reserved for future use */
char rsvd1[85]; /* reserved for future use */
/**********returned data ************/
char dadl3[50+1]; /* standardized 2nd delivery address*/
char dadl1[50+1]; /* standardized delivery address */
char dadl2[50+1]; /* standardized firm name */
char dlast[50+1]; /* standardized city/state/zip */
char dprurb[28+1]; /* output PR urbanization name */
char dctys[28+1]; /* main post office city */
char dstas[2+1]; /* main post office state */
char dctya[28+1]; /* standardized city */
char abcty[13+1]; /* standardized city abbreviation */
char dstaa[2+1]; /* standardized state */
char zipc[5+1]; /* 5-digit zip code */
char addon[4+1]; /* ZIP+4 addon code */
char dpbc[3+1]; /* delivery point bar code */
char cris[4+1]; /* carrier route */
char county[3+1]; /* FIPS county code */
short respn; /* number of returned responses */
char retcc; /* return code */
char adrkey[12]; /* address key (for indexing) */
char auto_zone_ind; /* A, B, C or D */
char elot_num[4+1]; /* eLOT Number */
char elot_code; /* eLOT Ascending/Descending Flag */
char llk_rc[2+1]; /* LACS Link Return Code */
char llk_ind; /* LACS Link Indicator */
char misc[128+1]; /* line for unused input data */
char rsvd2[20]; /* Reserved for Future Use */
/********* parsed input data*********/
char ppnum[10+1]; /* Primary Number */
char psnum[8+1]; /* Secondary Number */
char prote[3+1]; /* Rural Route Number */
char punit[4+1]; /* Secondary Number Unit */
char ppre1[2+1]; /* First or Left Pre-direction */
char ppre2[2+1]; /* Second or Right Pre-direction */
char psuf1[4+1]; /* First or Left Suffix */
char psuf2[4+1]; /* Second or Right Suffix */
char ppst1[2+1]; /* First or Left Post-direction */
char ppst2[2+1]; /* Second or Right Post-direction */
char ppnam[28+1]; /* Primary Name */
char mpnum[10+1]; /* Matched primary number. */
char msnum[8+1]; /* Matched secondary number */
char pmb[3+1]; /* PMB Unit Designator */
char pmbnum[8+1]; /* PMB Number */
char mlevl; /* Reserved Use */
char footnotes[32+1]; /* Reserved for Future Use */
char stelnkfoot[3+1]; /* suite link footnote */
char punit2[4+1]; /* second or right Secondary Unit */
char psnum2[8+1]; /* second or right secondary number */
char rsvd3[10]; /* Reserved for future use */
struct { /*************** footnotes***********/
char a; /* zip corrected */
char b; /* city/state corrected */
char c; /* invalid city/state/zip */
char d; /* no zip assigned */
char e; /* ZIP assigned for mult response */
char f; /* no zip available */
char g; /* part of firm moved to address */
char h; /* secondary number missing */
char i; /* insufficient/incorrect data */
char j; /* dual input */
char k; /* reserved for future use” */
char l; /* del addr component add/del/chg */
char m; /* street name spelling changed */
char n; /* delivery addr was standardized */
char o; /* multi break tie with lowest +4 */
char p; /* better delivery addr exists */
char q; /* Unique ZIP Code */
char r; /* no match caused by EWS */
char s; /* invalid secondary number */
char t; /* magnet street */
char u; /* unofficial PO name */
char v; /* unverifiable city/state */
char w; /* small town default */
char x; /* unique ZIP Code generated */
char y; /* Military Match */
char z; /* ZIP Move Match */
char f0; /* reserved for future use */
char f1; /* reserved for future use */
char f2; /* reserved for future use */
char f3; /* reserved for future use */
char f4; /* reserved for future use */
char f5; /* reserved for future use */
} foot;
ADDR_REC stack[10]; /************record stack************/
char rsvd4[194]; /* reserved for future use */
} ZIP4_PARM;for type CONFIG_PARM
typedef struct
{
char *address1; /*Contains the full path of the ZADRFLE.DAT file */
char *addrindex; /*Contains the full path of the ZADRFLE.NDX file */
char *cdrom; /*Contains the drive letter of the CD-ROM drive that*/
/*contains the ZIP+4/carrier route data;may be blank*/
char *citystate; /*Contains the full path of the following files: */
/*CTYSTATE.DAT - CTYSTATE.NDX */
/*ZIP5FILE.DAT - ZIP5FLE.NDX */
char *crossref; /*Contains the full path of the ZXREFDTL.DAT file */
char *system; /*Contains the full path of the Z4CXLOG.DAT file */
char *elot; /*Contains the full path of the ELTRVFLE.DAT file */
char *elotindex; /*Contains the full path of the ELTRVFLE.ND file */
char *llkpath; /*Contains the full path of the LACS Link files */
char *ewspath; /*Contains the full path of the EWS.TXT file */
char *dpvpath /*Contains the full path of the dpv files */
char *fnsnpath; /*Contains the full path of the fnsn.* files */
char* stelnkpath; /* Path to the suite link files */
char* abrstpath; /* Path to the abbreviated street name files */
char rsvd[116]; /* reserved for future use */
}CONFIG_PARM;
for type Z4OPEN_PARMtypedef struct
{
char rsvd1[50];
short status;
char* fname;
CONFIG_PARM config;
char ewsflag;
char elotflag;
char llkflag;
char dpvflag;
char systemflag;
char rtsw[16];
char dpvtypeflag;
char stelnkflag;
char abrstflag;
char rsvd2[492];
}Z4OPEN_PARM;Dale W Scott
-
Wednesday, August 08, 2012 7:49 PMI'm at it....
Armin
-
Wednesday, August 08, 2012 8:11 PM
I've only translated the two structures you've posted in your first message, not also ZIP4_PARM. It's pretty long.
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _ Public Structure CONFIG_PARM <MarshalAs(UnmanagedType.LPStr)> Public address1 As String <MarshalAs(UnmanagedType.LPStr)> Public addrindex As String <MarshalAs(UnmanagedType.LPStr)> Public cdrom As String <MarshalAs(UnmanagedType.LPStr)> Public citystate As String <MarshalAs(UnmanagedType.LPStr)> Public crossref As String <MarshalAs(UnmanagedType.LPStr)> Public system As String <MarshalAs(UnmanagedType.LPStr)> Public elot As String <MarshalAs(UnmanagedType.LPStr)> Public elotindex As String <MarshalAs(UnmanagedType.LPStr)> Public llkpath As String <MarshalAs(UnmanagedType.LPStr)> Public ewspath As String <MarshalAs(UnmanagedType.LPStr)> Public dpvpath As String <MarshalAs(UnmanagedType.LPStr)> Public fnsnpath As String <MarshalAs(UnmanagedType.LPStr)> Public stelnkpath As String <MarshalAs(UnmanagedType.LPStr)> Public abrstpath As String <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=116)> Public rsvd As String End Structure <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _ Public Structure Z4OPEN_PARM <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> Public rsvd1 As String Public status As Short <MarshalAs(UnmanagedType.LPStr)> Public fname As String Public config As CONFIG_PARM Public ewsflag As Char Public elotflag As Char Public llkflag As Char Public dpvflag As Char Public systemflag As Char <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> Public rtsw As String Public dpvtypeflag As Char Public stelnkflag As Char Public abrstflag As Char <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=492)> Public rsvd2 As String End Structure- Where you used assignments like
objz4open_parm.dpvflag = "Y"
you have to change it to a char literal, i.e. "Y"c (with the c suffix).
- I think you can even remove <MarshalAs(UnmanagedType.LPStr)> because it will be marshalled as a pointer to an ANSI string anyway due to the Charset parameter of the structlayout attribute. First try it with it, and if everything works, without it.
- I don't see the C declaration of z4opencfgSTD, but according to the VB6 code, the VB6 return type is Integer, which is Short in VB.Net. Maybe you have to change this later, too.(Sorry for strange formatting of this message; this editor is sometimes running crazy...)
Armin
- Marked As Answer by Dale W Scott Thursday, August 09, 2012 8:32 PM
-
Thursday, August 09, 2012 7:28 PM
Armin,
I changed the program to use your structure, but got the same error
Cannot marshal 'parameter #1': Invalid managed/unmanaged type combination (this value type must be paired with Struct).
Thanks
Dale
Dale W Scott
-
Thursday, August 09, 2012 7:53 PM
Try removing all attributes from z4opencfgSTD parameter declaration. I guess that's the one you're calling.Armin
- Marked As Answer by Dale W Scott Thursday, August 09, 2012 8:33 PM

