PC Review


Reply
Thread Tools Rate Thread

DLLImport and Marshaling

 
 
John
Guest
Posts: n/a
 
      25th Oct 2004
Hi,

I have some code in VB6 that uses a dll with a callback function
(funceval1). I want to convert this to VB.Net but I can't get it to
work. When funceval1 is called the var parameter only contains 1 value
instead of two and the value makes no sense.
I hope someone can take the time and try and help me.


This how the prototypes look in VB6.

Declare Function loadnlp Lib "frontmip.dll" (ByVal PROBNAME As String,
ByVal numcols As Long,
ByVal numrows As Long,
ByVal objsen As Long,
obj() As Double,
rhs() As Double,
sense() As Byte,
matbeg() As Long,
matcnt() As Long,
matind() As Long,
matval() As Double,
var() As Double,
lb() As Double,
ub() As Double,
rngval() As Double,
ByVal nzspace As Long,
ByVal funceval As Long,
ByVal jacobian As Long) As Long

' Callback routine def
Function funceval1(lp As Long, ByVal numcols As Integer, ByVal numrows
As Integer, ByRef objval As Double, ByRef lhs() As Double, ByRef var()
As Double, ByVal varone As Integer, ByVal vartwo As Integer) As Long

' Call to loadnlp
lp = loadnlp(PROBNAME, 2, 2, 1, obj, rhs, sense, _
NullL, NullL, NullL, matval, x, lb, ub, NullD, 4, _
AddressOf funceval1, 0)


and this is what I've done so far in Vb.net


<DllImport("frontmip.dll", CharSet:=CharSet.Ansi)> _
Public Function loadnlp(ByVal probname As String,
ByVal numcols As Integer,
ByVal numrows As Integer,
ByVal objsen As Integer,
<MarshalAs(UnmanagedType.SafeArray)> ByRef DatoObj() As Double,
<MarshalAs(UnmanagedType.SafeArray)> ByRef rhs() As Double,
<MarshalAs(UnmanagedType.SafeArray)> ByRef sense() As Byte,
<MarshalAs(UnmanagedType.SafeArray)> ByRef matbeg() As Integer,
<MarshalAs(UnmanagedType.SafeArray)> ByRef matcnt() As Integer,
<MarshalAs(UnmanagedType.SafeArray)> ByRef matind() As Integer,
<MarshalAs(UnmanagedType.SafeArray)> ByRef matval() As Double,
<MarshalAs(UnmanagedType.SafeArray)> ByRef var() As Double,
<MarshalAs(UnmanagedType.SafeArray)> ByRef lb() As Double,
<MarshalAs(UnmanagedType.SafeArray)> ByRef ub() As Double,
<MarshalAs(UnmanagedType.SafeArray)> ByRef rngval() As Double,
ByVal nzspace As Integer,
ByVal funceval1 As Defunc,
ByVal jacobian As Integer) As Integer

End Function


Public Function funceval1(ByRef lp As Integer, ByVal numcols As Short,
ByVal numrows As Short, ByRef objval As Double,
<MarshalAs(UnmanagedType.SafeArray)> ByRef lhs() As Double,
<MarshalAs(UnmanagedType.SafeArray)> ByRef var() As Double, ByVal
varone As Short, ByVal vartwo As Short) As Integer

lp = loadnlp(PROBNAME, 2, 2, 1, obj, rhs, sense, NullL, NullL, NullL,
matval, x, lb, ub, NullD, 4, AddressOf funceval1, 0)


Thanks in advance!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What's the difference of [DllImport ....] with _declspec(dllimport) Ed Microsoft VC .NET 2 31st Jul 2007 02:31 AM
Marshaling Nikolay Petrov Microsoft Dot NET Framework 3 14th Feb 2005 05:57 PM
CLI Marshaling =?Utf-8?B?TmFkYXY=?= Microsoft C# .NET 1 17th May 2004 02:06 PM
What is Marshaling? VM Microsoft C# .NET 5 7th Mar 2004 11:18 PM
COM Marshaling Ash Microsoft Dot NET 0 23rd Oct 2003 06:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:40 PM.