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
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.
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
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.