Добрый день! Тестирую Trans2QuikAPI в простом проекте с двумя кнопками: Connect и Disconnect. Проект на VB.Net. За основу взял код VBA из примера в Excel. С потоками проблема. Поэтому следующую ошибку не могу побороть, подскажите, как решить проблему.
Ошибка: A call to PInvoke function 'ПроектAPI.Form1::TRANS2QUIK_IS_QUIK_CONNECTED' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
[/CODE]
Ошибка: A call to PInvoke function 'ПроектAPI.Form1::TRANS2QUIK_IS_QUIK_CONNECTED' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
Код |
---|
Код:[CODE]Public Class Form1 Public Const TRANS2QUIK_SUCCESS = 0 Public Const TRANS2QUIK_FAILED = 1 Public Const TRANS2QUIK_QUIK_TERMINAL_NOT_FOUND = 2 Public Const TRANS2QUIK_DLL_VERSION_NOT_SUPPORTED = 3 Public Const TRANS2QUIK_ALREADY_CONNECTED_TO_QUIK = 4 Public Const TRANS2QUIK_WRONG_SYNTAX = 5 Public Const TRANS2QUIK_QUIK_NOT_CONNECTED = 6 Public Const TRANS2QUIK_DLL_NOT_CONNECTED = 7 Public Const TRANS2QUIK_QUIK_CONNECTED = 8 Public Const TRANS2QUIK_QUIK_DISCONNECTED = 9 Public Const TRANS2QUIK_DLL_CONNECTED = 10 Public Const TRANS2QUIK_DLL_DISCONNECTED = 11 Public Const TRANS2QUIK_MEMORY_ALLOCATION_ERROR = 12 Public Const TRANS2QUIK_WRONG_CONNECTION_HANDLE = 13 Public Const TRANS2QUIK_WRONG_INPUT_PARAMS = 14 Public TransStr As String Dim PathToInfo As String Dim FunctionResult As Long Dim FunctionResultString As String Dim pnExtendedErrorCode As Long Dim lpstrErrorMessage As String = Mid(lpstrErrorMessage, 250) Public Const dwErrorMessageSize = 250 Dim nReturnCode As Long Dim dwTransID As Long Dim dOrderNum As Double Dim lpstrResultMessage As String = Mid(lpstrResultMessage, 250) Const dwResultMessageSize = 250 Dim curRow As Long Dim g_nOrdersCount As Long Dim g_nTradesCount As Long Public Declare Function TRANS2QUIK_CONNECT Lib "D:\...Проект\Resources\TRANS2QUIK.dll" _ Alias "_TRANS2QUIK_CONNECT@16" _ (ByVal lpstConnectionParamsString As String, _ ByRef pnExtendedErrorCode As Long, _ ByVal lpstrErrorMessage As String, ByVal dwErrorMessageSize As Long) As Long Public Declare Function TRANS2QUIK_DISCONNECT Lib "D:\...Проект\Resources\TRANS2QUIK.dll" _ Alias "_TRANS2QUIK_DISCONNECT@12" _ (ByRef pnExtendedErrorCode As Long, _ ByVal lpstrErrorMessage As String, ByVal dwErrorMessageSize As Long) As Long Public Function Trans2QuikResultToStr(ByVal Num As Long) As String If Num = 0 Then Trans2QuikResultToStr = "TRANS2QUIK_SUCCESS" If Num = 1 Then Trans2QuikResultToStr = "TRANS2QUIK_FAILED" If Num = 2 Then Trans2QuikResultToStr = "TRANS2QUIK_QUIK_TERMINAL_NOT_FOUND" If Num = 3 Then Trans2QuikResultToStr = "TRANS2QUIK_DLL_VERSION_NOT_SUPPORTED" If Num = 4 Then Trans2QuikResultToStr = "TRANS2QUIK_ALREADY_CONNECTED_TO_QUIK" If Num = 5 Then Trans2QuikResultToStr = "TRANS2QUIK_WRONG_SYNTAX" If Num = 6 Then Trans2QuikResultToStr = "TRANS2QUIK_QUIK_NOT_CONNECTED" If Num = 7 Then Trans2QuikResultToStr = "TRANS2QUIK_DLL_NOT_CONNECTED" If Num = 8 Then Trans2QuikResultToStr = "TRANS2QUIK_QUIK_CONNECTED" If Num = 9 Then Trans2QuikResultToStr = "TRANS2QUIK_QUIK_DISCONNECTED" If Num = 10 Then Trans2QuikResultToStr = "TRANS2QUIK_DLL_CONNECTED" If Num = 11 Then Trans2QuikResultToStr = "TRANS2QUIK_DLL_DISCONNECTED" If Num = 12 Then Trans2QuikResultToStr = "TRANS2QUIK_MEMORY_ALLOCATION_ERROR" If Num = 13 Then Trans2QuikResultToStr = "TRANS2QUIK_WRONG_CONNECTION_HANDLE" If Num = 14 Then Trans2QuikResultToStr = "TRANS2QUIK_WRONG_INPUT_PARAMS" Return 0 End Function Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConnect.Click On Error Resume Next PathToInfo = "C:\Quik\info.exe" FunctionResult = TRANS2QUIK_CONNECT(PathToInfo, pnExtendedErrorCode, lpstrErrorMessage, dwErrorMessageSize) FunctionResultString = Trans2QuikResultToStr(FunctionResult) MsgBox("F: " & vbCrLf & _ "FunctionResult = " & FunctionResult & vbCrLf & _ "FunctionResultString = " & FunctionResultString & vbCrLf & _ "pnExtendedErrorCode = " & pnExtendedErrorCode & vbCrLf & _ "lpstrErrorMessage = " & lpstrErrorMessage) g_nOrdersCount = g_nTradesCount = 1 End Sub Private Sub cmdChekConnectDell_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChekConnectDell.Click FunctionResult = TRANS2QUIK_IS_DLL_CONNECTED(pnExtendedErrorCode, lpstrErrorMessage, dwErrorMessageSize) FunctionResultString = Trans2QuikResultToStr(FunctionResult) MsgBox("F: " & vbCrLf & _ "FunctionResult = " & FunctionResult & vbCrLf & _ "FunctionResultString = " & FunctionResultString & vbCrLf & _ "pnExtendedErrorCode = " & pnExtendedErrorCode & vbCrLf & _ "lpstrErrorMessage = " & lpstrErrorMessage) End Sub End Class |