Hi guys,
Here is my problem:
I have a C DLL function I need to ccall from VB.Net.
long PBFNProcess(void *Reserved1, void *Reserved2, void *Reserved3, void
*Reserved4, void *Reserved5, void *Reserved6, void Reserved7, void
*Reserved8, void *Reserved9)
These are all optional pointers to structures. The structures I'm sending
are long so I will give just a sample.
typedef struct PBFNProcessDataDefinition { char cVersion[VERSION_LEN]; char
cApiId[APIID_LEN]; char * cFirm; short sFirmLen; char * cUrb; short sUrbLen)
PBFNProcessDataDef, *pPBFNProcessDataDef;
I made a VB.Net structure like below
<StructLayout(LayoutKind.Sequential)> Public Class PBFNProcessDataDefinition
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=VERSION_LEN)> Public cVersion
As String '** Version of structure *'*
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=APIID_LEN)> Public cApiId As
String '** Structure ID = APDS or HRTN *'*
Public cFirm As String '** Firm name *'*
Public sFirmLen As Int16 '** Length override *'*
Public cUrb As String '** Urbanization name *'*
Public sUrbLen As Int16 '** Length override *'*
I then declared the function as below
<DllImport("pbfn.dll", CharSet:=CharSet.Ansi)> Public Shared Function
PBFNProcess(<[In](), Out(), MarshalAs(UnmanagedType.LPStruct)> ByVal input
As PBFNProcessDataDefinition, <[In](), Out(),
MarshalAs(UnmanagedType.LPStruct)> ByVal output As
PBFNProcessDataDefinition, ByVal O1 As Object, ByVal O2 As Object, ByVal O3
As Object, ByVal O4 As Object, ByVal O5 As Object, ByVal O6 As Object, ByVal
O7 As Object) As Int32
End Function
Here is the call (one of many versions)
dim input as new PBFNProcessDataDefinition
dim output as new PBFNProcessDataDefinition
'set up input structure is done here then the call is made
RC = PBFNProcess(input, output, New Object, New Object, New Object, New
Object, New Object, New Object, New Object)
The first two params are the only ones I'm concerned with.
I get 'Object Reference not set to an instance of an object' when this is
called.
Can you guys help me out? There is no help from the DLL originators.
thanks,
Brent
BMermuys - 26 Jul 2004 18:23 GMT
> Hi guys,
> Here is my problem:
[quoted text clipped - 13 lines]
>
> I made a VB.Net structure like below
<StructLayout(LayoutKind.Sequential,CharSet:=CharSet.Ansi)> _
Public Class PBFNProcessDataDefinition
> <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=VERSION_LEN)> Public cVersion
> As String '** Version of structure *'*
[quoted text clipped - 11 lines]
>
> I then declared the function as below
<DllImport("pbfn.dll")>
Public Shared Function PBFNProcess(
<[In](), Out()> ByVal input As PBFNProcessDataDefinition,
<[In](), Out()> ByVal output As PBFNProcessDataDefinition,
<[In](), Out(),MarshalAs(UnmanagedType.AsAny)> ByVal O1 As Object,
<[In](), Out(),MarshalAs(UnmanagedType.AsAny)> ByVal O2 As Object,
<[In](), Out(),MarshalAs(UnmanagedType.AsAny)> ByVal O3 As Object,
<[In](), Out(),MarshalAs(UnmanagedType.AsAny)> ByVal O4 As Object,
<[In](), Out(),MarshalAs(UnmanagedType.AsAny)> ByVal O5 As Object,
<[In](), Out(),MarshalAs(UnmanagedType.AsAny)> ByVal O6 As Object,
<[In](), Out(),MarshalAs(UnmanagedType.AsAny)> ByVal O7 As Object) As
Int32
End Function
Drop the LPStruct for the first two parameters.
> Here is the call (one of many versions)
>
[quoted text clipped - 6 lines]
> RC = PBFNProcess(input, output, New Object, New Object, New Object, New
> Object, New Object, New Object, New Object)
Make sure input/output are instantiated objects.
RC = PBFNProcess(input, output, Nothing, nothing, nothing, ..., )
HTH,
greetings
> The first two params are the only ones I'm concerned with.
>
[quoted text clipped - 6 lines]
>
> Brent