Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / July 2004

Tip: Looking for answers? Try searching our database.

Problem calling unmanaged API Functions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brent - 26 Jul 2004 17:11 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.