Einzelnen Beitrag anzeigen

TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.060 Beiträge
 
Delphi 10.4 Sydney
 
#4

AW: Windows MBN API für Delphi XE portieren

  Alt 12. Jul 2016, 12:50
Beim Anfang stolpere ich auch ein bisschen, aber das überlasse ich mal deiner Fantasie und Können.

Delphi-Quellcode:
program MBNConsole;

{$APPTYPE CONSOLE}

{$R *.res}


uses
  System.SysUtils,
  Winapi.Windows,
  Winapi.Messages,
  System.Variants,
  System.Classes,
  Winapi.ActiveX,
  MbnApi_TLB;

type
  TConnectionEventsSink = class(TInterfacedObject, IMbnConnectionEvents)

  public
    function OnConnectComplete(const newConnection: IMbnConnection; requestID: Cardinal; status: HRESULT): HRESULT; stdcall;
    function OnConnectStateChange(const newConnection: IMbnConnection): HRESULT; stdcall;
    function OnDisconnectComplete(const newConnection: IMbnConnection; requestID: Cardinal; status: HRESULT): HRESULT; stdcall;
    function OnVoiceCallStateChange(const newConnection: IMbnConnection): HRESULT; stdcall;

  end;

function TConnectionEventsSink.OnConnectComplete(const newConnection: IMbnConnection; requestID: Cardinal;
  status: HRESULT): HRESULT;
begin
  WriteLn('OnConnectComplete');
end;

function TConnectionEventsSink.OnConnectStateChange(const newConnection: IMbnConnection): HRESULT;
var
  activationState: MBN_ACTIVATION_STATE;
  profileName: WideString;
begin
  newConnection.GetConnectionState(activationState, profileName);
  WriteLn('OnConnectStateChange - ' + profileName + ' - ' + Cardinal(activationState).ToString);
end;

function TConnectionEventsSink.OnDisconnectComplete(const newConnection: IMbnConnection; requestID: Cardinal;
  status: HRESULT): HRESULT;
begin
  WriteLn('OnDisconnectComplete');
end;

function TConnectionEventsSink.OnVoiceCallStateChange(const newConnection: IMbnConnection): HRESULT;
begin
  WriteLn('OnVoiceCallStateChange');
end;

procedure Main;
var
  HR: HRESULT;
  mbnInfMgr: TMbnInterfaceManager;
  ConnectionEnum: IEnumConnectionPoints;
  infMgr: IMbnInterfaceManager;
  interfaces: PSafeArray;
  inf: IMbnInterface;
  MbnInterfaceManager: IMbnInterfaceManager;
  mbnConnMgr: TMbnConnectionManager;
  conMgr: IMbnConnectionManager;
  icpc: IConnectionPointContainer;
  icp: IConnectionPoint;
  connEvtsSink: IUnknown;
  cookie, requestID: UINT;
  conn: IMbnConnection;
begin
  mbnInfMgr := TMbnInterfaceManager.Create(nil);

  if Supports(mbnInfMgr.DefaultInterface, IMbnInterfaceManager, infMgr) then
  begin
    // das schlägt bei mir fehlt, hier ist guter Rat teuer
    HR := infMgr.GetInterfaces(interfaces);
    if HR = S_OK then
    begin
// inf := IMbnInterface(interfaces.rgsabound[0]);
    end
    else
    begin
      RaiseLastOSError(HR);
    end;
  end;

  mbnConnMgr := TMbnConnectionManager.Create(nil);

  icpc := mbnConnMgr.DefaultInterface;
  if Supports(icpc, IMbnConnectionManager, conMgr) then
  begin
    if icpc.FindConnectionPoint(IID_IMbnConnectionEvents, icp) = S_OK then
    begin
      connEvtsSink := TConnectionEventsSink.Create;
      icp.Advise(connEvtsSink, cookie);
    end;
  end;

  // Make sure the radio is turned on before here
  requestID := 0;
  if Assigned(inf) and (inf.GetConnection(conn) = S_OK) then
  begin
    // CONNECT HERE - AND WAIT FOR EVENTS
    WriteLn(' Connect - wait for events ');
    conn.Connect(MBN_CONNECTION_MODE_PROFILE, 'voda UK', requestID);
    WriteLn(' requestID:' + requestID.ToString);
    // WAIT 60 SECONDS FOR EVENTS TO FIRE
    Sleep(60000);
    WriteLn(' Disconnect - wait for events ');
    conn.Disconnect(requestID);
    WriteLn(' requestID:' + requestID.ToString);
  end;

  mbnInfMgr.Free;
  mbnConnMgr.Free;

  Readln;
end;

begin
  try
    Main;
  except
    on E: Exception do
      WriteLn(E.ClassName, ': ', E.Message);
  end;

end.
  Mit Zitat antworten Zitat