Mam przykład w C i nie wiem jak go przerobić na kod C# aby cała funkcjonalnośc się zachowała. Proszę o wyrozumiałość bo z programowaniem dopiero zaczynam zabawę.
Na chwilę obecną wyszukalem, że define mogę zamienić na C#'powe const
devlink.h
#ifndef _DEVLINK_H_
#define _DEVLINK_H_
typedef char TEXT;
#define DEVLINK_SUCCESS 0
#define DEVLINK_UNSPECIFIEDFAIL 1
#define DEVLINK_LICENCENOTFOUND 2
#define DEVLINK_COMMS_OPERATIONAL 0
#define DEVLINK_COMMS_NORESPONSE 1
#define DEVLINK_COMMS_REJECTED 2
#define DEVLINK_COMMS_MISSEDPACKETS 3
#ifdef __cplusplus
extern "C"
{
#endif
typedef void (CALLBACK * CALLLOGEVENT) ( DWORD pbxh, TEXT * info );
typedef void (CALLBACK * COMMSEVENT) ( DWORD pbxh, DWORD comms_state, WORD parm1 );
LONG PASCAL DLOpen( DWORD pbxh, TEXT * pbx_address, TEXT * pbx_password, TEXT * reserved1, TEXT * reserved2, COMMSEVENT cb);
LONG PASCAL DLClose( DWORD pbxh );
LONG PASCAL DLRegisterType2CallDeltas( DWORD pbxh, CALLLOGEVENT cb );
#ifdef __cplusplus
};
#endif
#endif
devlink.c
#include <windows.h>
#include <stdio.h>
#include "devlink.h"
LONG hEvent;
DWORD dwCommsEvent;
BOOL bStarting;
void CALLBACK HandleCommsEvent( LONG pbxh, DWORD comms_evt, DWORD parm1 )
{
switch( comms_evt )
{
case DEVLINK_COMMS_OPERATIONAL:
// we are working fine... fall through
case DEVLINK_COMMS_NORESPONSE:
// system not found (initial connection),
// or network connection lost (rebooted?)
// fall through...
case DEVLINK_COMMS_REJECTED:
// incorrect system password specified...
if( bStarting )
{
dwCommsEvent = comms_evt;
SetEvent( hEvent );
}
else
{
// insert your code here...
}
break;
case DEVLINK_COMMS_MISSEDPACKETS:
// Indicates that the system is under
// heavy load. IP Office always prioritises
// data routing and call handling above CTI events.
// (parm1 contains the number of packets missed)
break;
}
}
int main(int argc, char* argv[])
{
printf( "connecting..." );
bStarting = TRUE;
hEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
DLOpen( 0, "255.255.255.255" "systempassword", NULL, NULL, HandleCommsEvent );
dwCommsEvent = DEVLINK_COMMS_NORESPONSE;
WaitForSingleObject( hEvent, 10000 ); // 10 seconds
bStarting = FALSE;
if ( dwCommsEvent == DEVLINK_COMMS_OPERATIONAL )
{
printf("Connected OK\n");
}
else
{
printf("Error connecting to IP Office\n");
}
DLClose( 0 );
CloseHandle( hEvent );
return 0;
}