[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Calling VB DLL from ruby code

Medha Kulkarni

9/5/2006 3:31:00 PM

I am facing a problem while calling a VB DLL (for which I do not have a
source code, just know the function signatures which DLL exposes) from a
ruby code.
DLL Function signature is as follows:

Public Declare Function GetContentsStream Lib
"C:\VisualCsource\SLStrucStorageContents\Debug\SSGetContents.dll" _
'(arg1 As Byte, _
' ByVal lElements As Long, _
' ByVal sStreamName As String) As Long
Following is the explanation given by DLL author regarding argument
types & how that DLL should be called:


lLen = GetContentsStream(arrayObj(0), UBound(arrayObj), sStreamName)


Parameter1: arrayObj is an array of Bytes. We pass the the first
element of the
array by Reference, arrayObj (0), which really means we are passing the
address of the
start of the array.
Parameter2: Ubound (arrayObj) is the length of the array.
Parameter3: Stream name of type string.

I have written following code to call this dll:

require â??Win32APIâ??
getdllfun = Win32API.new('C:\WINDOWS\system32\SSGetContents.dll',
â??GetContentsStream", ['P','L','P'], 'L')
sStreamName = "CONTENTS"
arrayObj=New Array
## arrayObj stores some binary bitmap data
val=getdllfun.Call
(GetContentsStream.Call, arrObj.pack(â??C*â?),arrObj.size,sStreamName)
puts "\n value: " + val.to_s


When I execute this code, I get following error while executing function
getdllgun.Call:

storeLOBData.rb:211: in `fgetContentsStream': uninitialized constant
GetContentsS
tream (NameError)

May be there is a problem with argument types which I am specifying
i.e. ['P','L','P'] & argument which I am passing to DLL.
Any help regarding mapping VB parameter types to Ruby would be really
appreciated.

Thanks and Regards,
Medha.


--
Posted via http://www.ruby-....

3 Answers

Arnaud Bergeron

9/5/2006 4:33:00 PM

0

On 9/5/06, Medha Kulkarni <medha_19@yahoo.com> wrote:
> I am facing a problem while calling a VB DLL (for which I do not have a
> source code, just know the function signatures which DLL exposes) from a
> ruby code.
> DLL Function signature is as follows:
>
> Public Declare Function GetContentsStream Lib
> "C:\VisualCsource\SLStrucStorageContents\Debug\SSGetContents.dll" _
> '(arg1 As Byte, _
> ' ByVal lElements As Long, _
> ' ByVal sStreamName As String) As Long
> Following is the explanation given by DLL author regarding argument
> types & how that DLL should be called:
>
>
> lLen = GetContentsStream(arrayObj(0), UBound(arrayObj), sStreamName)
>
>
> Parameter1: arrayObj is an array of Bytes. We pass the the first
> element of the
> array by Reference, arrayObj (0), which really means we are passing the
> address of the
> start of the array.
> Parameter2: Ubound (arrayObj) is the length of the array.
> Parameter3: Stream name of type string.
>
> I have written following code to call this dll:
>
> require 'Win32API'
> getdllfun = Win32API.new('C:\WINDOWS\system32\SSGetContents.dll',
> "GetContentsStream", ['P','L','P'], 'L')
> sStreamName = "CONTENTS"
> arrayObj=New Array
> ## arrayObj stores some binary bitmap data
> val=getdllfun.Call
> (GetContentsStream.Call, arrObj.pack("C*"),arrObj.size,sStreamName)
> puts "\n value: " + val.to_s
>
>
> When I execute this code, I get following error while executing function
> getdllgun.Call:
>
> storeLOBData.rb:211: in `fgetContentsStream': uninitialized constant
> GetContentsS
> tream (NameError)
>
> May be there is a problem with argument types which I am specifying
> i.e. ['P','L','P'] & argument which I am passing to DLL.
> Any help regarding mapping VB parameter types to Ruby would be really
> appreciated.
>
> Thanks and Regards,
> Medha.

[disclaimer] I am not an expert on the Win32 API [/disclaimer]

Your problem does not look like an argument problem. It is ruby
telling you that the constant 'GetContentsStream' does not exist. I
wonder what it is doing there. Perhaps you meant:

val = getdllfun.Call(arrObj.pack("C*"),arrObj.size,sStreamName)

Reading error messages can help you. Don't jump to conclusions.

> --
> Posted via http://www.ruby-....
>

Per Jessen

11/12/2008 9:21:00 PM

0

Hi

Besides what Susan suggest, you can turn off screenupdating, as it
will speed up your macro:

Sub formatsheets()
Application.ScreenUpdating = False
For i = 1 To numSheets1
dFormatKeyMeasures1 sheetNames1:=sheetNames1(i - 1),
sheetTitles1:=sheetTitles1(i - 1)
Next i
Application.ScreenUpdating = True
End Sub

Regards,
Per

On 12 Nov., 21:45, Susan <bogenex...@aol.com> wrote:
> big macro!  every time you select, you're slowing things down.
> instead of
>
>     rows("1:3").Select
>     With Selection.Font
>         .Bold = True
>         .Name = "TimesNewRoman"
>     End With
>     rows("1:1").Select
>     Selection.Font.Size = 14
>     rows("2:3").Select
>     Selection.Font.Size = 12
>
> try:
>
> rows("1:3").Font.Bold = True
> rows("1:3").Font.Name = "TimesNewRoman"
> rows("1:1").Font.Size = 14
> rows("2:3").Font.Size = 12
>
> i've just replaced 9 VBA commands with 4 - less than half.  doing
> things like that will definitely speed up your code.  but as i said,
> it is a large code & may always take quite a bit of time.
> hope this helps
> :)
> susan
>
> On Nov 12, 3:32 pm, mtzc <michael.t.c...@gmail.com> wrote:
>
>
>
> > Hi,
>
> > I have a macro that formats 30 worksheets, which takes a long time to
> > run and significantly slows my computer. It would be greatly
> > appreciated if anyone could point out which parts are causing the
> > delay and need to be optimized. Thanks!
>
> > Sub formatsheets()
> > For i = 1 To numSheets1
> >         dFormatKeyMeasures1 sheetNames1:=sheetNames1(i - 1),
> > sheetTitles1:=sheetTitles1(i - 1)
> >     Next i
> > End Sub
>
> > Private Function dFormatKeyMeasures1(ByVal sheetNames1 As String,
> > ByVal sheetTitles1 As String)
>
> > Sheets(sheetNames1).Select
>
> > 'Add and format titles
> >     ActiveSheet.Range("d1").FormulaR1C1 = "Profitability Report of
> > Clients"
> >     Range("d2").FormulaR1C1 = "Key Measures by Client (" &
> > sheetTitles1 & ")"
> >     Range("d3").FormulaR1C1 = "(C$ " & Period & " Information ending "
> > & ReportingDate & ")"
> >     rows("1:3").Select
> >     With Selection.Font
> >         .Bold = True
> >         .Name = "TimesNewRoman"
> >     End With
> >     rows("1:1").Select
> >     Selection.Font.Size = 14
> >     rows("2:3").Select
> >     Selection.Font.Size = 12
>
> > 'Format report cells
> >     Sheets(sheetNames1).Range("A6:AG1000").Select
> >     With Selection
> >         .WrapText = False
> >         .HorizontalAlignment = xlLeft
> >         .Style = "Comma"
> >         .NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""??_);_(@_)"
> >     End With
> >     Range("H6:J1000").Select
> >     With Selection
> >         .NumberFormat = "#,##0.000"
> >     End With
>
> >  'Format total lines
> >         Dim j As Integer
> >         j = WorksheetFunction.CountIf(Sheets(sheetNames1).Columns(1),
> > "zimpaired")
> >         If j >= 1 Then
> >         Range("D5").End(xlDown).Offset(3, 0).Select
> >         ActiveCell.FormulaR1C1 = "Impaired Loans"
> >         With ActiveCell
> >             .Font.Bold = True
> >             .HorizontalAlignment = xlLeft
> >         End With
> >         End If
>
> >         Range("K5").End(xlDown).Offset(2, 0).Select
> >         With Selection
> >             .Borders(xlEdgeTop).LineStyle = xlContinuous
> >             .Borders(xlEdgeBottom).LineStyle = xlContinuous
> >         End With
> >         ActiveCell.Copy
> >         Range(ActiveCell, Cells(ActiveCell.Row, 33)).PasteSpecial
> > xlPasteFormats
>
> >         j = WorksheetFunction.CountIf(Sheets(sheetNames1).Columns(1),
> > "zimpaired") - 1
> >             If j >= 1 Then
> >             ActiveSheet.Range("K65536").End(xlUp).Offset(-2, 0).Select
> >              With Selection
> >             .Borders(xlEdgeTop).LineStyle = xlContinuous
> >             .Borders(xlEdgeBottom).LineStyle = xlContinuous
> >             End With
> >             ActiveCell.Copy
> >             Range(ActiveCell, Cells(ActiveCell.Row, 33)).PasteSpecial
> > xlPasteFormats
> >             ActiveSheet.Range("K65536").End(xlUp).Select
> >              With Selection
> >             .Borders(xlEdgeTop).LineStyle = xlContinuous
> >             .Borders(xlEdgeBottom).LineStyle = xlContinuous
> >             .Borders(xlEdgeBottom).LineStyle = xlDouble
> >             .Borders(xlEdgeBottom).Weight = xlThick
> >             End With
> >             ActiveCell.Copy
> >             Range(ActiveCell, Cells(ActiveCell.Row, 33)).PasteSpecial
> > xlPasteFormats
> >             ElseIf j = 0 Then
> >             ActiveSheet.Range("K65536").End(xlUp).Select
> >              With Selection
> >             .Borders(xlEdgeTop).LineStyle = xlContinuous
> >             .Borders(xlEdgeBottom).LineStyle = xlContinuous
> >             .Borders(xlEdgeBottom).LineStyle = xlDouble
> >             .Borders(xlEdgeBottom).Weight = xlThick
> >             End With
> >             ActiveCell.Copy
> >             Range(ActiveCell, Cells(ActiveCell.Row, 33)).PasteSpecial
> > xlPasteFormats
> >             End If
>
> >     'Adjust column sizes and hide irrelevant columns
> >     Columns("A:A").Select
> >     Columns("A:A").ColumnWidth = 10
> >     Columns("B:B").ColumnWidth = 10
> >     Columns("C:C").EntireColumn.AutoFit
> >     Columns("D:D").ColumnWidth = 55
> >     Columns("E:E").ColumnWidth = 4
> >     Columns("F:F").ColumnWidth = 5.5
> >     Columns("G:G").ColumnWidth = 6
> >     Columns("H:I").ColumnWidth = 6.5
> >     Columns("J:J").ColumnWidth = 8.5
> >     Columns("E:J").HorizontalAlignment = xlCenter
> >     Columns("K:O").ColumnWidth = 14
> >     Columns("P:Q").ColumnWidth = 13
> >     Columns("R:R").ColumnWidth = 10.5
> >     Columns("S:S").ColumnWidth = 8
> >     Columns("T:T").ColumnWidth = 11.5
> >     Columns("V:V").ColumnWidth = 13
> >     Columns("W:W").ColumnWidth = 11.5
> >     Columns("X:X").ColumnWidth = 8
> >     Columns("Y:Z").ColumnWidth = 11.5
> >     Columns("AA:AA").ColumnWidth = 8
> >     Columns("AB:AB").ColumnWidth = 10.5
> >     Columns("AC:AH").Select
> >     Columns("AC:AH").EntireColumn.AutoFit
> >     Columns("AC:AH").Hidden = True
> >     Columns("T:U").Hidden = True
>
> >     'Shade every other row for Performing
> >     Range("A7:AH7").Select
> >     With Selection.Interior
> >         .ColorIndex = 15
> >         .Pattern = xlSolid
> >     End With
> >     Range("a8").Select
> >     ActiveCell.EntireRow.Insert
> >     rows("6:7").Select
> >     Selection.Copy
> >     Range("a9").CurrentRegion.Select
> >     Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone,
> > SkipBlanks:= _
> >         False, Transpose:=False
> >     Range("a8").EntireRow.Delete
> >     rows("6:7").Select
> >     Selection.Copy
>
> >     'Shade every other row for Impaired, if existing
> >         j = WorksheetFunction.CountIf(Sheets(sheetNames1).Columns(1),
> > "zimpaired") - 1
> >         If j >= 1 Then
> >         Range("a5").End(xlDown).Offset(5, 0).CurrentRegion.Select
> >         Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone,
> > SkipBlanks:= _
> >         False, Transpose:=False
> >     End If
>
> >     'Freeze Panes
> >     rows("6:6").Select
> >     ActiveWindow.FreezePanes = True
>
> >     'Printer Settings
> >     Range("AH65536").End(xlUp).Select
> >     With ActiveSheet.PageSetup
> >         .PrintTitleRows = "$1:$5"
> >         .PrintArea = "C:AB"
> >         .LeftMargin = Application.InchesToPoints(0.1)
> >         .RightMargin = Application.InchesToPoints(0.1)
> >         .TopMargin = Application.InchesToPoints(0.5)
> >         .BottomMargin = Application.InchesToPoints(0.5)
> >         .Orientation = xlLandscape
> >         .PaperSize = xlPaperLegal
> >         .FitToPagesWide = 1
> >         .FitToPagesTall = False
> >         .Zoom = False
> >         .PrintQuality = 600
> >     End With
>
> > End Function- Skjul tekst i anførselstegn -
>
> - Vis tekst i anførselstegn -

mtzc

11/13/2008 2:20:00 PM

0

Thanks so much Susan and Per. I will give these a try. All the best!