Monday, January 4, 2010

VB.Net?

QUESTION

We have a use primarily Microsoft architecture and program in VB.net and C# (preferably VB.net).  Your VB callable DLL seems like a good fit for our needs, however I would like to know if you could provide a .Net framework code example that calls your DLLs.

ANSWER

We have an uneasy relationship with VB.Net because we never took the step of making our DLLs registered. However, some of our customers do call our VB-callable DLL as unmanaged code in the VB.Net environment. The sample code we give out is this:

-----------------------------------

REM-----------------------------------------------------------------
REM VB .NET programmers: (Jan-2004)
REM-----------------------------------------------------------------
REM You will want to implicitly allocate storage for the strings you
REM pass to our DLL functions, like this: VerStr = Space(80)
REM You will also probably want to use DllImport and specify the
REM character coding as ANSI
REM-----------------------------------------------------------------
REM
Option Explicit

Private Declare Function mhicd Lib "mhicdvb.dll" (ByVal which As String, _
ByVal file As String, ByVal code As String, ByVal retval As String, _
ByVal length As Integer) As Integer
Private Declare Function mhdllver Lib "mhdrgvb.dll" (ByVal Buf As String, _
ByVal BufLen As Integer) As Integer
Private Declare Function mhdrg Lib "mhdrgvb.dll" (drg As Integer, _
ByVal DRGVersion As String, ByVal MasksPath As String, ByVal DischStat As String, _
ByVal PtAge As String, ByVal PtGender As String, ByVal DXList As String, _
ByVal ProcList As String) As Integer
Private Declare Sub mherrdesc Lib "mhdrgvb.dll" (ByVal Buffer As String, _
ByVal length As Integer)
Private Declare Sub mhinfo Lib "mhdrgvb.dll" (drg As Integer, _
ByVal DRGVersion As String, ByVal MasksPath As String, mdc As Integer, _
weight As Double, los As Double, ByVal Desc As String, ByVal DescLen As Integer)
Private Declare Function mhcodeused Lib "mhdrgvb.dll" (ByVal which _
As String, ByVal codeindex As Integer) As Integer
Private Declare Function mhdrgver Lib "mhdrgvb.dll" (ByVal MPath As String, _
ByVal Buf As String, ByVal BufLen As Integer) As Integer

Private Sub AssignDRG()
Dim ErrMsg As String * 256
Dim ReturnCode As Integer
Dim drg As Integer, mdc As Integer
Dim Desc As String * 80
Dim weight As Double, los As Double
Dim masksdir As String
Dim myver As String, mydstat As String, myage As String, mysex As String
Dim mydxbuf As String * 80
Dim mypxbuf As String * 80
Dim tempStr As String
Dim N As Integer, needcomma As Integer

'Loop through controls, getting their current values
masksdir = Command
myver = Me!ver
mydstat = Left$(Me!dstat, 1)
myage = Me!age
mysex = Left$(Me!sex, 1)

'make string out of the diagnoses codes
tempStr = ""
needcomma = 0
For N = 0 To 9
If Len(Me!dx(N)) > 0 Then
If needcomma <> 0 Then
tempStr = tempStr & ","
End If
needcomma = 1
tempStr = tempStr & Me!dx(N)
End If
Next N
mydxbuf = tempStr

'make string out of the procedure codes
tempStr = ""
needcomma = 0
For N = 0 To 14
If Len(Me!proc(N)) > 0 Then
If needcomma <> 0 Then
tempStr = tempStr & ","
End If
needcomma = 1
tempStr = tempStr & Me!proc(N)
End If
Next N
mypxbuf = tempStr

'call the M+H grouper with what you got
Me!results = ""
ReturnCode = mhdrg(drg, myver, masksdir, mydstat, myage, mysex, mydxbuf, mypxbuf)
If ReturnCode <> 0 Then 'drg assignment failed, alas!
Call mherrdesc(ErrMsg, 70) 'tell user about failure
Me!results = "DRG Assignment FAILED: " & ErrMsg
Else 'drg assignment worked, hurray!
'get the particulars of this DRG from M+H dll
Call mhinfo(drg, myver, masksdir, mdc, weight, los, Desc, 80)
Me!results = "DRG: " & drg & " " & Desc
Me!info = "MDC: " & mdc & " Weight: " & weight & " Mean LOS: " & los & " Version: " & myver
'which dxes were used?
For N = 0 To 9
If mhcodeused("d", N) Then
Me.dx(N).FontBold = True
Else
Me.dx(N).FontBold = False
End If
Next N
'which procs were used?
For N = 0 To 14
If mhcodeused("p", N) Then
Me.proc(N).FontBold = True
Else
Me.proc(N).FontBold = False
End If
Next N
End If

End Sub

Private Sub Form_Load()
Dim VerStr As String * 80, MaxVer As Integer, MPath As String
Dim DRGVers As String * 81, N As Integer, I As Integer

'expect the masks directory as a command line argument
If Command = "" Then
MsgBox (Me.Caption & " " & Chr(10) & Chr(10) & _
"Required command line argument 'Masks Directory' is missing" & Chr(10) & _
"(This is the path to the directory with DRG Masks files and the ICD9 file")
End
End If
MPath = Command

'get the DLL version
MaxVer = mhdllver(VerStr, 79)
Me.Caption = Me.Caption & " " & VerStr

'get the supported DRG versions
N = mhdrgver(MPath, DRGVers, 81) ' deal with error, if any
I = 1
Do While N <> 0
Me.ver.AddItem (Mid$(DRGVers, I, 2))
If I = 1 Then
Me.ver.Text = Mid$(DRGVers, I, 2)
End If
N = N - 1
I = I + 2
Loop
'initialize sex list
Me.sex.AddItem "1 Male"
Me.sex.AddItem "2 Female"

'initialize discharge status list
Me.dstat.AddItem "0 Unknown"
Me.dstat.AddItem "1 Home"
Me.dstat.AddItem "2 Other Hosp"
Me.dstat.AddItem "3 SNF"
Me.dstat.AddItem "4 ICF"
Me.dstat.AddItem "5 Other Inst"
Me.dstat.AddItem "6 Home Care"
Me.dstat.AddItem "7 AMA"
Me.dstat.AddItem "8 Expired"
End Sub

Private Sub dx_Change(index As Integer)
Dim retval As String * 24

Call mhicd("d", Command & "/icd9.tab", Me.dx(index).Text, retval, 23)
Me.ddesc(index).Caption = retval
End Sub

Private Sub proc_Change(index As Integer)
Dim retval As String * 24

Call mhicd("p", Command & "/icd9.tab", Me.proc(index).Text, retval, 23)
Me.pdesc(index).Caption = retval
End Sub

-----------------------------------

No comments:

Post a Comment