ByRef Value in using a DLL

texmex
03-12-2006, 07:59 PM
Hi All,

I have been creating a VB6 app using a printer SDK DLL (the sample files are written in C++) and all has gone well so far, thanks to many people helping on this forum, but I am now stuck again. I am trying to expand my app to write to more than 1 printer at a time.

I have a line in the module that looks like this:

Public Declare Function chcusb_listupPrinter Lib "CHCUSB.DLL" (ByRefl IdArray As Byte) As Long


Now the IdArray should return all of the printer Id's (up to a max of 128, 0 to 127). But when I try the chcusb_listupPrinter I get an error "ByRef type mismatch", I have had a look at the help files and I am no closer to understanding the error. My code looks like this:


Private Sub cmdListUp_Click()
'list up printers
PrinterCount = chcusb_listupPrinter(IdArray)
lblText.Caption = PrinterCount
End Sub


The PrintCount is Dim'ed in the option explicit section as an integer. Could someone tell me what I am doing wrong please.

MilanJ
03-12-2006, 09:48 PM
In function declaration there is
IdArray As Byte
so (according to the name of the parameter) I would expect, that you should have declared byte array and in function calling use first element of the array.
Such:
PrinterCount = chcusb_listupPrinter(IdArray(0))
But I only guess, because I know nothing about the DLL and its functions. So sorry in advance, if my answer isn't what you are looking for.
EDIT:
BTW, the function is declared "As Long", so you should declare PrinterCount variable as long, not as integer as you wrote. You can obtain an overflow error due to this discrepancy between declarations in function and result receiving variable.
Regards
MilanJ

texmex
03-12-2006, 09:58 PM
Not sure if that has fixed it, but at least I get past the compile error now. I think I needed to point to the first byte in the array, I added (0) to IdArray and it compiles. Thanks again, I will let you know how it goes.

MilanJ
03-12-2006, 10:04 PM
My suggestion
PrinterCount = chcusb_listupPrinter(IdArray(0))
assumes, that you have IdArray declared as byte array. You perhaps forgot to declare it so?

texmex
03-14-2006, 03:16 PM
It is all working, great now. Thanks very much. As outlined before I needed to point to the first element in the array. There are some even more complicated calls to get the labelnames of the printers back, if I'm feeling brave I may even give those a go. Thanks again. :D

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum