Buongiorno oregon e grazie mille per la risposta e la disponibilità
Il produttore della DLL, fornisce, con essa, due file (C e C#) contenente la dichiarazione delle funzioni e delle variabili così da prenderne spunto.
Di seguito, la dichiarazione della funzione data dal produttore:
Codice PHP:
// Returns:
public const Int32 INVALID_PARAMETER = -1; // Invalid parameter
public const Int32 NOT_CONNECTED = 0; // Not connected (trying to connect)
public const CONNECTED = 1; // Connected
// Method C#:
[DllImport(ApiDll, CallingConvention = CallingConvention.Cdecl)]
public static extern Int32 GetConnectionStatus(out UInt16 NodeNumber, out UInt8 BNumber, out UInt32 GatewayControlIpAddrOfNode, out UInt16 GatewayControlIpPortOfNode, out string NodeDescriptionString);
// Method C:
Int32 __cdecl GetConnectionStatus(UInt16 *NodeNumber, UInt8 *BNumber, UInt32 *GatewayControlIpAddrOfNode, UInt16 *GatewayControlIpPortOfNode, char **NodeDescriptionString);
Di seguito, la dichiarazione della funzione nel mio codice Vb.Net
codice:
//Vecchia dichiarazione (remmata) che, nel Framework 4.0, non passava "CallingConvention.Cdecl"
//Declare Function GetConnectionStatus Lib "ApiDll" (ByRef NodeNumber As Int16, ByRef BNumber As Byte, ByRef GatewayControlIpAddrOfNode As Int32, ByRef GatewayControlIpPortOfNode As Int16, ByRef NodeDescriptionString As String) As Int32
//Nuova dichiarazione della funzione per Framework 4.0
<DllImport("ApiDll.dll", CallingConvention:=CallingConvention.Cdecl)> _
Public Shared Function GetConnectionStatus(ByRef NodeNumber As UInt16, ByRef BNumber As Byte, ByRef GatewayControlIpAddrOfNode As UInt32, ByRef GatewayControlIpPortOfNode As UInt16, ByRef NodeDescriptionString As String) As Int32
End Function
Qui di seguito, il suo utilizzo all'interno del codice:
codice:
Dim NodeNumber As UInt16
Dim BNumber As Byte
Dim GatewayControlIpAddrOfNode As UInt32
Dim GatewayControlIpPortOfNode As UInt16
Dim NodeDescriptionString As String = ""
Dim newRes as Int32 = GetConnectionStatus(NodeNumber, BNumber, GatewayControlIpAddrOfNode, GatewayControlIpPortOfNode, NodeDescriptionString)
Niente di particolarmente complicato quindi, se non fosse che con i Framework 2.0 e 3.0 la funzione restituisce correttamente il valore "1 - CONNECTED", mentre, con il framework 4.0, genera l'errore "c0000005" quando viene eseguito l'exe compilato in "Debug" o "Release" da VS2010 mentre funziona correttamente se eseguito in "modalità Debug" all'interno di Visual Studio.
Grazie a chiunque riuscirà a risolvermi questo maledetto arcano...purtroppo, non posso tornare indietro a Framework precedenti perchè, nuove DLL interne all'applicazione, necessitano l'utilizzo del Framework 4.0
Buona giornata