Click here to Skip to main content
16,005,734 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionDatagridview and Bindingsource Pin
Nielvh29-Jun-10 1:48
Nielvh29-Jun-10 1:48 
AnswerRe: Datagridview and Bindingsource Pin
DaveAuld29-Jun-10 2:05
professionalDaveAuld29-Jun-10 2:05 
GeneralRe: Datagridview and Bindingsource Pin
Nielvh29-Jun-10 3:14
Nielvh29-Jun-10 3:14 
GeneralRe: Datagridview and Bindingsource [modified] Pin
DaveAuld29-Jun-10 3:28
professionalDaveAuld29-Jun-10 3:28 
GeneralRe: Datagridview and Bindingsource Pin
Nielvh29-Jun-10 4:06
Nielvh29-Jun-10 4:06 
AnswerRe: Datagridview and Bindingsource Pin
DaveAuld29-Jun-10 2:09
professionalDaveAuld29-Jun-10 2:09 
GeneralRe: Datagridview and Bindingsource Pin
Nielvh29-Jun-10 3:15
Nielvh29-Jun-10 3:15 
QuestionPinvoking a non WIN32 API under VB, cant get handle to printer Pin
Hrizip28-Jun-10 22:45
Hrizip28-Jun-10 22:45 
I am having some problems getting a printer driver to work in Visual Basic.

I am stuck at not being able to get a printer handle from the printer dll.

This is what I got thus far;

Static dll_loaded As Boolean
      If Not dll_loaded Then
          Dim dll_handle = LoadLibrary("ZBRPrinter.dll")
          If dll_handle = 0 Then
              MsgBox("LoadLibrary failed")
              Return
          Else
              dll_loaded = True
              MsgBox("LoadLibrary success!")
          End If
      End If
      Dim pName As StringBuilder = New StringBuilder("Zebra P330i USB Card Printer")
      Dim hPrinter As IntPtr = 2
      Dim printerType = 330
      Dim err As Integer = 0

      Dim ret = ZBRGetHandle(hPrinter, pName, printerType, err)
      If err = 61 Then
          MsgBox("Unable to open handle to Zebra printer driver")
      End If


I am using the following pinvoke sig:

DllImport("ZBRPrinter.dll", SetLastError:=True, CharSet:=CharSet.Auto)> Public Shared Function ZBRGetHandle(ByRef hPrinter As IntPtr, ByVal pName As StringBuilder, ByRef printerType As Integer, ByRef err As Integer) As IntPtr
    End Function


I am getting the following data returned to me as I run this code;
hprinter gets changed from 2 (test number) to 0
pname is the stringbuilder (also tried it as a string)
printertype is 330
err is 61

It seems that I am getting "through" to the dll but I am unable to get a proper printer handle.

This is what I got in Zebra SDK:

	// Load the Zebra MIFARE SDK library
	HMODULE hModule = LoadLibrary(_T("ZBRGPMF.dll"));
	if (hModule)
	{
		form1.StatusBox->Text = "The DLL has been successfully loaded.";
	}
	else
	{
	//StatusBox->Text = "Error loading Zebra SDK DLL.";
	return FALSE;
	}
	
	// Get the functions
	zsdkGetHandle		= (ZBRGetHandle)GetProcAddress(hModule, "ZBRGetHandle");


HANDLE hPrinter = NULL;
	INT printerType = NULL;
	INT err = 0,
		ret = 0;

	ret = getHandle(&hPrinter, "Zebra P330i USB Card Printer", &printerType, &err);
	ret = getPrinterStatus(&err);


And by running that example I do get a handle returned (its 0x000000) and the thing works.

This is the typedef I got with the SDK:

typedef INT (CALLBACK *ZBRGetHandle)(LPHANDLE hPrinter, LPSTR pName, INT* printerType, LPINT err);


I am (quite obviously) new to adapting the code from C# to VB, I have managed to make several projects work (win32 API based) but I hit a wall on this one, please help if you can, any suggestions are most welcome, thanks in advance!
AnswerRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
freakyit29-Jun-10 0:15
freakyit29-Jun-10 0:15 
GeneralRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
Hrizip29-Jun-10 0:35
Hrizip29-Jun-10 0:35 
GeneralRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
Hrizip29-Jun-10 1:29
Hrizip29-Jun-10 1:29 
GeneralRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
freakyit29-Jun-10 2:34
freakyit29-Jun-10 2:34 
GeneralRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
Hrizip29-Jun-10 2:41
Hrizip29-Jun-10 2:41 
GeneralRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
Hrizip29-Jun-10 3:00
Hrizip29-Jun-10 3:00 
AnswerRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
Luc Pattyn29-Jun-10 3:37
sitebuilderLuc Pattyn29-Jun-10 3:37 
GeneralRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
Hrizip29-Jun-10 3:43
Hrizip29-Jun-10 3:43 
GeneralRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
freakyit29-Jun-10 4:00
freakyit29-Jun-10 4:00 
GeneralRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
Hrizip29-Jun-10 4:31
Hrizip29-Jun-10 4:31 
AnswerRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
Luc Pattyn29-Jun-10 4:34
sitebuilderLuc Pattyn29-Jun-10 4:34 
GeneralRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
Hrizip29-Jun-10 4:36
Hrizip29-Jun-10 4:36 
AnswerRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
Luc Pattyn29-Jun-10 7:41
sitebuilderLuc Pattyn29-Jun-10 7:41 
GeneralRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
Hrizip29-Jun-10 7:58
Hrizip29-Jun-10 7:58 
GeneralRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
Luc Pattyn29-Jun-10 8:26
sitebuilderLuc Pattyn29-Jun-10 8:26 
GeneralRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
Hrizip29-Jun-10 8:34
Hrizip29-Jun-10 8:34 
GeneralRe: Pinvoking a non WIN32 API under VB, cant get handle to printer Pin
Luc Pattyn29-Jun-10 8:52
sitebuilderLuc Pattyn29-Jun-10 8:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.