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)?
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;
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;
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;
{$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;
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;
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
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.
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
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?