-
error importing dll (pinvoke unbalanced the stack error)
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];
}Dummy2;
typedef struct OnlineBufferItem
{
unsigned long NumberOfPosition;
unsigned long TypeOfPosition;
char QuantityOfSale[10];
char ValueAfterDiscSurch[20];
unsigned long TaxRate;
char ValueBeforeDiscSurch[20];
char Barcode[14];
}Dummy3;
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)
{
//Code
}
// Initializing the dll
result=InitializeDLL(P, &EVENTFUNCTION, &ERRORFUNCTION)
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)
and
<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?
Thanks,
kacsa
Similar Threads
-
By garywillams in forum C++
Replies: 2
Last Post: 05-14-2009, 09:22 AM
-
Replies: 1
Last Post: 04-06-2009, 09:56 AM
-
By Chris H Baker in forum C++
Replies: 5
Last Post: 01-17-2007, 01:37 PM
-
By Khalizan in forum VB Classic
Replies: 1
Last Post: 11-28-2001, 01:32 AM
-
By Chandra in forum VB Classic
Replies: 0
Last Post: 06-22-2000, 07:30 AM
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks