Einzelnen Beitrag anzeigen

Pow3rus3r

Registriert seit: 17. Apr 2012
43 Beiträge
 
Delphi XE Professional
 
#12

AW: dll einbinden / Pointer Probleme

  Alt 18. Apr 2012, 10:06
Wow, danke für die Beteiligung!

Konkret geht es um folgendes: Ich habe eine Hardware, die über Ethernet angesteuert werden soll. Der Hardwarehersteller hat dazu eine dll zur Verfügung gestellt, welche die Funktionen für Kommunikationsaufbau, Abbau und Datenübertragung enthält. Ich versuche nun eine Kommunikation mit dem Steuergerät herzustellen (Funktion COM_TcpOpen in der DLL). Die Funktion ist in der Onlinehilfe des Hardwareherstellers wie folgt dokumentiert:
Code:
EXPORTDLL COM_RETURN EBEL_API COM_TcpOpen ( COM_Handle *  handle,
  const char *  ipAddress,
  u16  port
 )  

Generates a new PC HW interface. To communicate with a hardware over Ethernet.

Parameters:
handle = Pointer to a handle representing the interface instance. Will be filled by this function.
ipAddress = IP Address of the target.
port = Port number used to communicate with the target.

Returns:
COM_RETURN_OK Function executed successfully.
COM_RETURN_Failed The function failed to create a new handle.
Hier die Codeausschnitte aus dem c++ Beispielprogramm vom Hardwarehersteller:
Typedef:
Code:
/// \brief Defines a handle to a PC->Hardware communication object.
typedef void* COM_Handle;
COM_Return Definition:
Code:
/// \brief Return values used by the interface functions. This type provides information about an error. A zero value means no error occured.
typedef enum COM_RETURNtag
{
    COM_RETURN_OK = 0,               ///< Function executed successfully.
    COM_RETURN_Failed,               ///< Function execution failed.
    COM_RETURN_InvalidHandle,         ///< The handle parameter was NULL or not a matching PC HW interface handle.
    COM_RETURN_InvalidParameter,      ///< One of the parameter was invalid.
    COM_RETURN_NullPointer,            ///< One of the paramter was a NULL pointer but should point to a stucture or variable.
    COM_RETURN_Timeout,               ///< The hardware was not responding or not reachable.
    COM_RETURN_NotSupported,         ///< The command requested was not supported by the application on the hardware.
    COM_RETURN_AlreadyRunning,         ///< The function / application is already running.
    COM_RETURN_Locked               ///< The function can not be executed while the HW/SW/region is locked.
} COM_RETURN;
COM_TcpOpen Aufruf in C++:
Code:
//---------------------------------------------------------------------------
// Example of an implementation of a COM_TcpOpen call
//---------------------------------------------------------------------------

void CHwComTestGuiDlg::OnBnClickedOpentcp()
{
    CString str;

    UpdateData();   // Update the member variables with the values in the text fields.
#ifdef BLUETOOTH_INTERFACE
    //Disable bluetooth "Open" and "Close" buttons
    CButton *tcpBTHOpenClose;
    tcpBTHOpenClose = (CButton*) GetDlgItem(IDC_CBUTTON_OPEN);
    tcpBTHOpenClose->EnableWindow(FALSE);
    tcpBTHOpenClose = (CButton*) GetDlgItem(IDC_CBUTTON_CLOSE);
    tcpBTHOpenClose->EnableWindow(FALSE);
#endif   
    COM_RETURN ret = COM_TcpOpen(&m_hCom,m_ipAddress.GetBuffer(),m_nPort);      // Call the function
    PrintErrorInfos("COM_TcpOpen",ret);         // Visualize the result
}
Der komplette C++ Quellcode ist wohl leider zu groß, um ihn hier zu posten. Falls aber noch weitere Infos nötig sind, poste ich diese gerne.

Der Entwickler der dll hat mir eben noch geschrieben, dass er sich mit Delphi leider nicht auskennt, aber er davon ausgeht, dass ich vergessen habe, die Zeigeradresse beim Funktionsaufruf mit anzugeben. Nun bin ich aber leider selber nicht der Delphi-Pro und wüsste auf Anhieb auch nicht, ob und wie ich die Adresse übergeben kann.
  Mit Zitat antworten Zitat