كيف ارسال sms ببرنامج الدلفي والهاتف النقال
#6
وعليكم السلام ورحمة الله
لن أزيد على ما قال الأستاذ عبد العزيز
غير بعض التفاصيل التي لا يمكن أن تجدها إلا عند مصنع الجهاز الذي تود الاتصال به
هناك مكتبة SMS3ASuiteLib شهيرة للتخاطب مع الجوالات (ابحث عن ترجمتها بدلفي)
مكتبة NokiaCLMessaging مخصصة للتخاطب مع نوكيا
جرب استحضار مكتبة النظام NokiaCLMessaging لتحصل على NokiaCLMessaging_TLB.pas
هنا مثال يدعي صاحبه أنه يعمل 100% مع Nokia 6310i , PC Connectivity SDK 3.0 and Delphi 7
PHP كود :
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. 
المصدر من مجتمع نوكيا:
كود :
http://www.developer.nokia.com/Community/Discussion/showthread.php?43185-ShortMsgReceived-Delphi

مكونات أخرى تجارية TOxygenSMS
كود :
http://www.oxygensoftware.com/en//products/tsms/
بالتوفيق.
الرد


الردود في هذا الموضوع
كيف ارسال sms ببرنامج الدلفي والهاتف النقال - بواسطة kachwahed - 05-11-2011, 11:12 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم