Dear all,

I have to use a dll in VB.NET 2005, but I get the "pinvoke unbalanced the stack" error when I call the dll function.
I have a C++ sample code, where evrithing run well.
Here is the C++ code:

typedef struct Parameters
unsigned long SerialPortNumber; //1..255
unsigned long TransmissionSpeed; //9600 lub 19200
unsigned long Mode; //1 - local
unsigned long CustomerCardOnline; //0 - disabled, !0 - enabled
unsigned long CustomerCardOffline; //0 - disabled, !0 - enabled
unsigned long DisplayBarcodeOfCustomerCard; //0 - disabled, !0 - enabled
unsigned char TextForArticleNotFound[25];
unsigned long CardsInPositionBuffer; //0 - disabled, !0 - enabled
unsigned long PaymentsInPositionBuffer; //0 - disabled, !0 - enabled
unsigned long CashInOutInPositionBuffer; //0 - disabled, !0 - enabled
unsigned long StornoInPositionBuffer; //0 - disabled, !0 - enabled
unsigned long DLLDebugMode;
} Dummy1;

typedef struct ArticleData
unsigned long PLUNumber;
unsigned char Name[19];
unsigned char Barcode[14];
unsigned long TaxRate;
unsigned long Department;
unsigned long QAC;
unsigned long Tariff;
unsigned long Price;
unsigned char BarcodeOfLinkedArticle[14];

typedef struct OnlineBufferItem
unsigned long NumberOfPosition;
unsigned long TypeOfPosition;
char QuantityOfSale[10];
char ValueAfterDiscSurch[20];
unsigned long TaxRate;
char ValueBeforeDiscSurch[20];
char Barcode[14];

typedef struct OnlineBufferItem OnlineBufferArray[100];

typedef void __stdcall HANDLEEVENT( unsigned long TypeOfEvent,
unsigned char* CustomerCardBarcode,
unsigned long CustomerCardType,
unsigned char* ArticleBarcode,
unsigned long TypeOfReceipt,
unsigned char* QuantityOfArticle,
struct OnlineBufferItem OnlineBufferArray[100],
unsigned long* CustomerCardAccepted,
unsigned char* CustomerCardReturnText,
unsigned long* ArticleBarcodeFound, //filled by app
unsigned long* LinkedArticle, //filled by app
struct ArticleData *Article1, //filled by app
struct ArticleData *Article2); //filled by app

typedef void __stdcall HANDLEERROR(unsigned long Error);
extern "C"
int __declspec(dllimport) __stdcall InitializeDLL(struct Parameters P, HANDLEEVENT* EVENTFUNCTION, HANDLEERROR* ERRORFUNCTION);

void __stdcall EVENTFUNCTION(the same declaration)

// Initializing the dll

So, I have to rewrite this code to VB.NET
I know that i have to use delegate in .NET like

<UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)> _
Public Delegate Sub HANDLEEVENT
(ByVal TypeOfEvent As UInteger
, ByVal CustomerCardBarcode As String
, ByVal CustomerCardType As UInteger
, ByVal ArticleBarcode As String
, ByVal TypeOfReceipt As UInteger
, ByVal QuantityOfArticle As String
, ByRef OnlineBufferItem As OnlineBufferArray
, ByRef CustomerCardAccepted As UInteger
, ByRef CustomerCardReturnText As String
, ByRef ArticleBarcodeFound As UInteger
, ByRef LinkedArticle As UInteger
, ByRef Article1 As ArticleData, ByRef Article2 As ArticleData)

<UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)> _
Public Delegate Sub HANDLEERROR(ByRef pError As UInteger)


<DllImport("dll name", CallingConvention:=CallingConvention.StdCall)> _
Friend Overloads Shared Function InitializeDLL(ByRef p As Parameters, ByVal pEvent As HANDLEEVENT, ByVal pError As HANDLEERROR) As Integer
End Function

and so on.
Using this declaration I get the pinvoke unbalanced the stack error.

Could anybody tell me the correct declaration for VB.NET?