×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    6

    ShortMsgReceived - Delphi

    Hi Everyone

    To all the delphi people, I have managed to convert (Get working) the VB6 messaging example that comes with the connectivity SDK 3.0, in Delphi. I will post it here as soon as I can get the application to respond to receiving, deleting messages.


    Has anybody managed to get the ShortMsgReceived event to fire on Delphi (5.0)?

    Can anybody help??

    Thank you in advance.
    Quentin

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    18

    An decision of your problem

    Hello Quentin.

    Look at this unit.
    It demonstrate how you can catch
    SMS received event and read the message's fields.
    Moreover there is a implementation of IShortMsgNotify.

    You need to import type library NokiaCLMessaging to compile this unit.


    Alexey K.




    unit SMSMessaging;

    interface

    uses NokiaCLMessaging_TLB, OleServer, Classes;

    type

    TSMSEventSink = class;

    TSMSFactory = class(TObject)
    private
    FSink : TSMSEventSink;
    FConnection : LongInt;
    FMessage : IMessage;
    public
    constructor Create;
    destructor Destroy; override;
    class function GetInstance: TSMSFactory;
    end;

    TSMSEventSink = class(TInterfacedObject, IDispatch, IShortMsgNotify)
    private
    // IDispatch
    function GetTypeInfoCount(out Count: integer): HResult; stdcall;
    function GetTypeInfo(Index, LocaleID: integer; out TypeInfo): HResult; stdcall;
    function GetIDsOfNames( const IID: TGUID; Names: Pointer;
    NameCount, LocaleID: integer;
    DispIDs: Pointer ): HResult; stdcall;
    function Invoke( DispID: integer; const IID: TGUID; LocaleID: integer;
    Flags: Word; var Params; VarResult, ExcepInfo,
    ArgErr: Pointer): HResult; stdcall;
    // ISMSReceiveNotify
    function SMSMemoryFull: HResult; stdcall;
    function SMSDeleted(SMSMemory: ShortMessageMemory; FolderID: Byte; Location: Smallint): HResult; stdcall;
    function CBMessageReceived(var ppIGSMCellBroadcast: IGSMCellBroadcast): HResult; stdcall;
    function CellInfoDisplayChanged(CellInfoDisplayStatus: WordBool): HResult; stdcall;
    function MessageReceived(SMSMemory: ShortMessageMemory; FolderID: Byte; Location: Smallint;
    const pIShortMessageItem: IShortMessageItem): HResult; stdcall;

    end;


    implementation

    uses EventHandling, TextsLoader;

    {---------------------------- TSMSEventSink ---------------------------}

    function TSMSEventSink.GetIDsOfNames(const IID: TGUID; Names: Pointer;
    NameCount, LocaleID: integer; DispIDs: Pointer): HResult;
    begin
    Result := E_NOTIMPL;
    end;

    function TSMSEventSink.GetTypeInfo(Index, LocaleID: integer;
    out TypeInfo): HResult;
    begin
    Result := E_NOTIMPL;
    pointer (TypeInfo) := NIL;
    end;

    function TSMSEventSink.GetTypeInfoCount(out Count: integer): HResult;
    begin
    Result := E_NOTIMPL;
    Count := 0;
    end;

    function TSMSEventSink.Invoke(DispID: integer; const IID: TGUID;
    LocaleID: integer; Flags: Word; var Params; VarResult, ExcepInfo,
    ArgErr: Pointer): HResult;
    begin
    inherited;
    Result := S_OK;
    end;

    procedure TSMSEventSink.SetNotifyForm(const Value: TForm1);
    begin
    FNotifyForm := Value;
    end;

    function TSMSEventSink.SMSDeleted(SMSMemory: ShortMessageMemory; FolderID: Byte; Location: Smallint): HResult;
    begin
    // not implement
    Result := S_OK;
    end;
    function TSMSEventSink.CBMessageReceived(var ppIGSMCellBroadcast: IGSMCellBroadcast): HResult;
    begin
    // not implement
    Result := S_OK;
    end;
    function TSMSEventSink.CellInfoDisplayChanged(CellInfoDisplayStatus: WordBool): HResult;
    begin
    // not implement
    Result := S_OK;
    end;

    function TSMSEventSink.MessageReceived(SMSMemory: ShortMessageMemory; FolderID: Byte; Location: Smallint;
    const pIShortMessageItem: IShortMessageItem): HResult;
    var
    originatorAddress, messageText : WideString;
    sendTime: TDateTime;
    msgType: TOleEnum;
    pVal: IInterface;
    messageItem: IGSMDeliver;
    receivedMessage: TReceivedMessage

    begin
    OleCheck(pIShortMessageItem.Get_type_(msgType));
    OleCheck(pIShortMessageItem.Get_TypeProperties(pVal));
    case msgType of
    SHORTMESSAGE_TYPE_GSM_DELIVER: // Regular mesage
    begin
    messageItem:=pVal as IGSMDeliver;
    messageItem.Get_OriginatorAddress(originatorAddress);
    messageItem.Get_TimeStamp(sendTime);
    messageItem.Get_Message(messageText);

    // Place here code, that store received message

    end;
    SHORTMESSAGE_TYPE_GSM_STATUS_REPORT: // Status report
    begin
    messageStatus:=pVal as IGSMStatusReport;
    with messageStatus do begin
    Get_RecipientAddress(recipientAddress);
    Get_ServiceCenterAddress(serviceCenterAddress);
    Get_DischargeTime(dischargeTime);
    Get_SMSStatus(smsStatus);
    Get_MessageReference(messageReference);
    end;

    // Place here code, that store status report

    end;
    end;


    TMessageReceivedEvent.Generate(Self, receivedMessage.Id);
    Result := S_OK;
    end;

    {--------------------- TSMSFactory ---------------------}

    {$J+}
    class function TSMSFactory.GetInstance: TARSSender;
    const
    instance: TARSSender = nil;
    begin
    if not Assigned(instance) then
    instance:= TSMSFactory.Create;
    Result:= instance;
    end;
    {$J-}

    constructor TSMSFactory.Create;
    begin
    inherited;
    // connect to the phone
    FMessage := CoShortMsgAdapter.Create;

    // create our event sink
    FSink := TSMSEventSink.Create;
    FSink.NotifyForm := Self;

    // hook up our event sink
    InterfaceConnect( FMessage, // Event source
    IID_IShortMsgNotify, // IID of the event interface
    FSink, // Event sink
    FConnection ); // Reference parameter

    OleCheck(FMessage.EnableNotifications);
    end;

    destructor TSMSFactory.Destroy;
    begin
    OleCheck(FMessage.DisableNotifications);
    InterfaceDisconnect( FSink, // Event source
    IID_IShortMsgNotify, // IID of the event interface
    FConnection ); // Reference parameter
    inherited;
    end;

    end.

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    6
    Hi Alexey

    Thank you for your reply.

    I created a new unit and copied your code into it.
    There were some errors compiling, but nothing major.

    Some errors:

    1) TMessageReceivedEvent - Unknown?
    .............
    end;


    TMessageReceivedEvent.Generate(Self, receivedMessage.Id);
    Result := S_OK;
    end;

    {--------------------- TSMSFactory ---------------------}
    ...............

    2) TARSSender - unknown?
    ...............
    {--------------------- TSMSFactory ---------------------}

    {$J+}
    class function TSMSFactory.GetInstance: TARSSender;
    const
    instance: TARSSender = nil;
    .............

    After making some changes, I compiled and ran my application.
    I still get no response from deleting a message or receiving one.

    (I am testing on deleting, cause it is expensive to keep sending myself messages)

    Have I done something wrong?

    Thank You
    Quentin

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    18
    Hi

    Sorry about last unit.
    It's my mistake.

    Here is 100% working code:

    It works with Nokia 6310i , PC Connectivity SDK 3.0 and Delphi 7.

    ------------------------------------------------------

    unit fMain;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, ActiveX, StdCtrls, OleServer, NokiaCLMessaging_TLB, ComObj,
    ExtCtrls;

    type
    TSMSEventSink = class;

    TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    private
    { Private declarations }
    FSink : TSMSEventSink;
    FConnection : LongInt;
    FMessage : IMessage;
    public
    { Public declarations }
    procedure MessageReceived(const pIShortMessageItem: IShortMessageItem);
    end;

    TSMSEventSink = class(TInterfacedObject, IDispatch, IShortMsgNotify)
    private
    function GetTypeInfoCount(out Count: integer): HResult; stdcall;
    function GetTypeInfo(Index, LocaleID: integer; out TypeInfo): HResult; stdcall;
    function GetIDsOfNames( const IID: TGUID; Names: Pointer;
    NameCount, LocaleID: integer;
    DispIDs: Pointer ): HResult; stdcall;
    function Invoke( DispID: integer; const IID: TGUID; LocaleID: integer;
    Flags: Word; var Params; VarResult, ExcepInfo,
    ArgErr: Pointer): HResult; stdcall;
    // ISMSReceiveNotify
    function SMSMemoryFull: HResult; stdcall;
    function SMSDeleted(SMSMemory: ShortMessageMemory; FolderID: Byte; Location: Smallint): HResult; stdcall;
    function CBMessageReceived(var ppIGSMCellBroadcast: IGSMCellBroadcast): HResult; stdcall;
    function CellInfoDisplayChanged(CellInfoDisplayStatus: WordBool): HResult; stdcall;
    function MessageReceived(SMSMemory: ShortMessageMemory; FolderID: Byte; Location: Smallint;
    const pIShortMessageItem: IShortMessageItem): HResult; stdcall;

    protected
    FNotifyForm: TForm1;
    procedure SetNotifyForm(const Value: TForm1);
    public
    property NotifyForm : TForm1 read FNotifyForm write SetNotifyForm;
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    { TSMSEventSink }

    function TSMSEventSink.GetIDsOfNames(const IID: TGUID; Names: Pointer;
    NameCount, LocaleID: integer; DispIDs: Pointer): HResult;
    begin
    Result := E_NOTIMPL;
    end;

    function TSMSEventSink.GetTypeInfo(Index, LocaleID: integer;
    out TypeInfo): HResult;
    begin
    Result := E_NOTIMPL;
    pointer (TypeInfo) := NIL;
    end;

    function TSMSEventSink.GetTypeInfoCount(out Count: integer): HResult;
    begin
    Result := E_NOTIMPL;
    Count := 0;
    end;

    function TSMSEventSink.Invoke(DispID: integer; const IID: TGUID;
    LocaleID: integer; Flags: Word; var Params; VarResult, ExcepInfo,
    ArgErr: Pointer): HResult;
    begin
    inherited;
    Result := S_OK;
    end;

    procedure TSMSEventSink.SetNotifyForm(const Value: TForm1);
    begin
    FNotifyForm := Value;
    end;

    function TSMSEventSink.SMSDeleted(SMSMemory: ShortMessageMemory; FolderID: Byte; Location: Smallint): HResult;
    begin
    // not implement
    Result := S_OK;
    end;
    function TSMSEventSink.CBMessageReceived(var ppIGSMCellBroadcast: IGSMCellBroadcast): HResult;
    begin
    // not implement
    Result := S_OK;
    end;
    function TSMSEventSink.CellInfoDisplayChanged(CellInfoDisplayStatus: WordBool): HResult;
    begin
    // not implement
    Result := S_OK;
    end;


    function TSMSEventSink.MessageReceived(SMSMemory: ShortMessageMemory; FolderID: Byte; Location: Smallint;
    const pIShortMessageItem: IShortMessageItem): HResult;
    begin
    if Assigned(FNotifyForm) then
    FNotifyForm.MessageReceived(pIShortMessageItem);
    Result := S_OK;
    end;

    function TSMSEventSink.SMSMemoryFull: HResult;
    begin
    // Not implemented
    Result := S_OK;
    end;

    { TForm1 }

    procedure TForm1.MessageReceived(const pIShortMessageItem: IShortMessageItem);
    var
    serviceCenterAddress, recipientAddress, originatorAddress, messageText : WideString;
    sendTime,dischargeTime: TDateTime;
    smsStatus, messageReference: Byte;
    msgType: TOleEnum;
    pVal: IInterface;
    messageItem: IGSMDeliver;
    messageStatus: IGSMStatusReport;
    begin
    OleCheck(pIShortMessageItem.Get_type_(msgType));
    OleCheck(pIShortMessageItem.Get_TypeProperties(pVal));
    case msgType of
    SHORTMESSAGE_TYPE_GSM_DELIVER:
    begin
    messageItem:=pVal as IGSMDeliver;
    with messageItem do begin
    Get_OriginatorAddress(originatorAddress);
    Get_TimeStamp(sendTime);
    Get_Message(messageText);
    end;
    Memo1.Lines.Add('Originator address: '+originatorAddress+' send time: '+DateTimeToStr(sendTime)+' message text: '+messageText);
    end;
    SHORTMESSAGE_TYPE_GSM_STATUS_REPORT:
    begin
    messageStatus:=pVal as IGSMStatusReport;
    with messageStatus do begin
    Get_RecipientAddress(recipientAddress);
    Get_ServiceCenterAddress(serviceCenterAddress);
    Get_DischargeTime(dischargeTime);
    Get_SMSStatus(smsStatus);
    Get_MessageReference(messageReference);
    end;
    Memo1.Lines.Add('Recipient address: '+recipientAddress+' Service Center Address: '+serviceCenterAddress+' discharge time: '+DateTimeToStr(sendTime)+' sms status: '+intToStr(smsStatus)+' message reference: '+intToStr(messageReference));
    end;
    end;
    end;

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    // connect to the phone
    FMessage := CoShortMsgAdapter.Create;

    // create our event sink
    FSink := TSMSEventSink.Create;
    FSink.NotifyForm := Self;

    // hook up our event sink
    InterfaceConnect( FMessage, // Event source
    IID_IShortMsgNotify, // IID of the event interface
    FSink, // Event sink
    FConnection ); // Reference parameter

    OleCheck(FMessage.EnableNotifications);
    end;

    procedure TForm1.FormDestroy(Sender: TObject);
    begin
    OleCheck(FMessage.DisableNotifications);
    InterfaceDisconnect( FSink, // Event source
    IID_IShortMsgNotify, // IID of the event interface
    FConnection ); // Reference parameter
    end;


    end.

    ------------------------------------------------------

  5. #5
    Registered User
    Join Date
    Apr 2004
    Posts
    6
    Thank you very much.

    I compiled it straight from the post, and it worked.
    I am so happy now I can dance in the street...

    Thank you for your help an willingness to assit other users.

    Kindest regards
    Quentin

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    2
    Pls,
    what if I want to :
    1. Delete the SMS
    2. how can I access the network component to monitor my signal Level ?
    3. may be if u can give a brief explanation of how to use the Library via delphi it will be straight foward.
    This thing is breaking me up !!!!!!!!!!!!!!!!!!!!!!!
    HELP

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    18
    Hello

    Do you have PC Connectivity SDK 3.0? If yes - check for topic of documentation about delphi.
    Then look on previous code. I think it is a good example how SDK works with Delphi.

    Best regards

    Alexey K.

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    2
    hey I tried and failed ! that is why I believe something much more practical will do. I saw the example but the code in dis forum is different

  9. #9
    Registered User
    Join Date
    Jul 2006
    Posts
    1

    Re: ShortMsgReceived - Delphi

    Hello all, I am new here...

    Not sure if anyone is still subscribed to this thread. I know its a little basic, but how do I send SMS with the above NokiaCLMessaging lib? I am using Nokia 3100

    Anyone ?

    Joshua

  10. #10
    Registered User
    Join Date
    May 2008
    Posts
    10

    Question Re: ShortMsgReceived - Delphi

    Can you please help me,
    I use Delphi 5 and I try to Import a "NclMsg.dll" via
    /Component/Import ActiveX Contol/Add ...
    but its dont make nothing.
    do you have any idea?

    THANK YOU.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×