Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I'm have problems to control a ID-Card Printer (HiTi CS-200e) in VB.NET (VS 2013).
It comes with a dll "PavoApi.dll" (seems to be an unmanaged dll).
The DLL is linked into the project and is in the project directory.
I try to move the ID-Card into the printer.
Referring to the pinters SDK docs I have to use
C++
DWORD __stdcall PAVO_MoveCard(char* szPrinter, DWORD dwPosition);


I tried to translate it into VB.NET with
VB
Imports System.Runtime.InteropServices

Friend Class HiTiDLL

    <DllImport("PavoApi.dll", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function PAVO_MoveCard(ByVal szPrinter As String, ByVal dwPosition As Long) As Integer

    End Function

    Public Function HitiMoveCard(ByVal PrinterName As String, ByVal Position As Long) As Integer
        Return PAVO_MoveCard(PrinterName, Position)
    End Function
End Class


Public Class cls_HiTiPrinterControl
    Public Sub Test()
        Dim HiTi As New HiTiDLL


        HiTi.HitiMoveCard("HiTi CS-200e", 3)




    End Sub
End Class

The debugger returns "PInvokeStackImbalance".

I'm new to unmanaged dlls, so what's going wrong?

Thank's for any help.
Phil
Posted

1 solution

The equivalent of DWORD is Integer in VB.NET; it would have been Long in VB6, which was still rooted in the 16-bit world.

Also, I don't think CallingConvention.Cdecl matches your __stdcall declaration.

Try:
VB
Friend Class HiTiDLL

    <DllImport("PavoApi.dll")> _
    Public Shared Function PAVO_MoveCard(ByVal szPrinter As String, ByVal dwPosition As Integer) As Integer

    End Function

    Public Function HitiMoveCard(ByVal PrinterName As String, ByVal Position As Integer) As Integer
        Return PAVO_MoveCard(PrinterName, Position)
    End Function
End Class
 
Share this answer
 
v3
Comments
Philipp fgi 13-Jan-15 3:16am    
Perfect, it works! Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900