Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9201891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:07:38+00:00 2026-06-17T23:07:38+00:00

please can you help me? I need convert this C header to pascal header

  • 0

please can you help me? I need convert this C header to pascal header

#include <wtypes.h>
extern "C"
{

typedef struct _sms_report
{
    char            sUserNumber[24];           
    unsigned char   cPort;                      
    unsigned char   cErrorCode;             
    unsigned char   cCount;                 
    unsigned char   cSuccCount;             

    _sms_report()
    {
        memset(this,0,sizeof(_sms_report));
    }
}_SMS_REPORT;





enum ERRORCODE
{
    _SUCCESS = 0,  
    _INVALID = 1,  
    _PORTCANTUSED = 2, 
    _TIMEOUT = 3,  
      _SOMEFAIL = 4, 
    _UNKNOW = 255   
};



typedef void (*On_WIAConnect)(short conn_no);          
typedef void (*On_WIADisConnect)(short conn_no);          
typedef void (*On_SendSmsReport)(short conn_no,char* seq,unsigned short numberCount,_SMS_REPORT* smsReport);
typedef void (*On_ReceiveSmsMsg)(short conn_no,unsigned char portno,char* seq,char* CallerNumber,char* text,
                                unsigned char type,char* receivetime,char timezone);
typedef void (*On_WIAStatusMsg)(short conn_no,char* seq,unsigned char portnum,unsigned char *pPortStatus);
typedef void (*On_SendUSSDResponse)(short conn_no,unsigned char portno,char* seq,unsigned char errcode);
typedef void (*On_ReceiveUSSDMsg)(short conn_no,unsigned char portno,char* seq,char* text,unsigned char status);


struct CBHandler
{
    On_WIAConnect _OnWIAConnect; 
    On_WIADisConnect  _OnWIADisConnect;
    On_SendSmsReport _OnSendSmsReport; 
    On_ReceiveSmsMsg _OnReceiveSmsMsg; 
    On_WIAStatusMsg  _OnWIAStatusMsg; 
    On_SendUSSDResponse _OnSendUSSDResponse;
    On_ReceiveUSSDMsg _OnReceiveUSSDMsg;
};


bool __declspec(dllexport) __stdcall InitLib(CBHandler *);
bool __declspec(dllexport) __stdcall StartRun(char *svrip,WORD port);
bool __declspec(dllexport) __stdcall GetSvrInfo(char *svrip,WORD port);
bool __declspec(dllexport) __stdcall SendSms(short conn_no,unsigned char PortNo,char* dstNumber,
                unsigned char msgCodingType,char* text,unsigned char type,char * seq);
bool __declspec(dllexport) __stdcall SendUSSD(short conn_no,unsigned char PortNo,unsigned char status,
                                    char* text,char * seq);
bool __declspec(dllexport) __stdcall UninitLib();
};

I make thius pascal header:

unit zfsmsdll;

interface
uses
{$IFDEF WIN32}
  Windows;
{$ELSE}
  Wintypes, WinProcs;
{$ENDIF}

const
 DLL_NAME = 'zfsmsdll.dll';

type
 TSmsReport = record

   sUserNumber: packed array [1..24] of Char;
         cPort: Byte;
    cErrorCode: Byte;
        cCount: Byte;
      cSuccCount: Byte;

 end;

 TErrorCode = (

      ecSuccess = 0,
      ecInvalid = 1,
  ecPortCansued = 2,
      ecTimeout = 3,
     ecSomeFail = 4,
      ecUnknown = 255
 );


 TOnWIAConnect = procedure ( conn_no: SmallInt) of object; cdecl;
 TOnWIADisconnect = procedure ( conn_no: SmallInt) of object; cdecl;
 TOnSendSmsReport = procedure (conn_no: SmallInt;  seq: PChar; numberCount: Word; smsReport: TSmsReport) of object; cdecl;
 TOnReceiveSmsMsg = procedure (conn_no: SmallInt; portno: Byte; seq: PChar; CallerNumber: PChar; text: PChar;
                               ttype: Byte; receivetime: PChar; timezone: Char) of object; cdecl;
 TOnWIAStatusMsg = procedure (conn_no: SmallInt; seq: PChar; portnum: Byte; pPortStatus: Byte) of object; cdecl;
 TOnSendUSSDResponse = procedure (conn_no: SmallInt; portno: Byte; seq: PChar; errcode: Byte) of object; cdecl;
 TOnReceiveUSSDMsg = procedure (conn_no: SmallInt; portno:Byte; seq: PChar; text: PChar; status: Byte ) of object; cdecl;


 PCBhandler = ^TCBHandler;
 TCBHandler = record
       HOnWIAConnect: TOnWIAConnect;
    HOnWIADisconnect: TOnWIADisconnect;
    HOnSendSmsReport: TOnSendSmsReport;
    HOnReceiveSmsMsg: TOnReceiveSmsMsg;
     HOnWIAStatusMsg: TOnWIAStatusMsg;
 HOnSendUSSDResponse: TOnSendUSSDResponse;
   HOnReceiveUSSDMsg: TOnReceiveUSSDMsg;
 end;

function InitLib ( Handler: PCBhandler ):Boolean; cdecl; external DLL_NAME;
function StartRun ( SrvIp: PChar; Port: Word ):Boolean; cdecl; external DLL_NAME;
function GetSvrInfo ( SrvIp: PChar; Port: Word ):Boolean; cdecl; external DLL_NAME;
function SendSms (conn_no: SmallInt; PortNo: Byte; dstNumber: PChar; msgCodingType: Byte;
                  text: PChar; ttype: Byte; seq: PChar):Boolean; cdecl; external DLL_NAME;
function SendUSSD (conn_no: SmallInt; PortNo: Byte; status: Byte; text: PChar;
                   seq: PChar):Boolean; cdecl; external DLL_NAME;
function UninitLib ():Boolean; cdecl; external DLL_NAME;


implementation

end.

When i call InitLib function where parameter is record of methods pointers that initialization done but adter method InitLib program throw excepotion access violation type. I think that probem is in declaring method pointers. This is my main form unit:

unit main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,zfsmsdll;

type
  TForm1 = class(TForm)
    btn1: TButton;
    mmoLog: TMemo;
    btn2: TButton;
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

  THandlerEvents = class

    procedure OnWIAConnect ( conn_no: SmallInt);cdecl;

    procedure OnWIADisconnect ( conn_no: SmallInt);cdecl;
    procedure OnSendSmsReport (conn_no: SmallInt;  seq: PChar; numberCount: Word; smsReport: TSmsReport);cdecl;
    procedure OnReceiveSmsMsg (conn_no: SmallInt; portno: Byte; seq: PChar; CallerNumber: PChar; text: PChar;
                               ttype: Byte; receivetime: PChar; timezone: Char);cdecl;
    procedure OnWIAStatusMsg (conn_no: SmallInt; seq: PChar; portnum: Byte; pPortStatus: Byte);cdecl;
    procedure OnSendUSSDResponse (conn_no: SmallInt; portno: Byte; seq: PChar; errcode: Byte);cdecl;
    procedure OnReceiveUSSDMsg (conn_no: SmallInt; portno:Byte; seq: PChar; text: PChar; status: Byte );cdecl;

  end;


var
  Form1: TForm1;
  HandlerEvents: THandlerEvents;

  InitHandler: TCBhandler;



implementation

{$R *.dfm}

procedure THandlerEvents.OnWIAConnect ( conn_no: SmallInt);cdecl;
begin
  Form1.mmoLog.Lines.Add('OnConnect processed');
end;

procedure THandlerEvents.OnWIADisconnect ( conn_no: SmallInt);cdecl;
begin
  Form1.mmoLog.Lines.Add('OnWIADisconnect processed');
end;
procedure THandlerEvents.OnSendSmsReport (conn_no: SmallInt;  seq: PChar; numberCount: Word; smsReport: TSmsReport);cdecl;
begin
  Form1.mmoLog.Lines.Add('OnSendSmsReport processed');
end;
procedure THandlerEvents.OnReceiveSmsMsg (conn_no: SmallInt; portno: Byte; seq: PChar; CallerNumber: PChar; text: PChar;
                               ttype: Byte; receivetime: PChar; timezone: Char);cdecl;
begin
  Form1.mmoLog.Lines.Add('OnReceiveSmsMsg processed');
end;
procedure THandlerEvents.OnWIAStatusMsg (conn_no: SmallInt; seq: PChar; portnum: Byte; pPortStatus: Byte);cdecl;
begin
  Form1.mmoLog.Lines.Add('OnWIAStatusMsg processed');
end;
procedure THandlerEvents.OnSendUSSDResponse (conn_no: SmallInt; portno: Byte; seq: PChar; errcode: Byte);cdecl;
begin
  Form1.mmoLog.Lines.Add('OnSendUSSDResponse processed');
end;
procedure THandlerEvents.OnReceiveUSSDMsg (conn_no: SmallInt; portno:Byte; seq: PChar; text: PChar; status: Byte );cdecl;
begin
 Form1.mmoLog.Lines.Add('OnReceiveUSSDMsg processed');
end;


procedure TForm1.btn1Click(Sender: TObject);
begin

// try

     InitHandler.HOnWIAConnect := HandlerEvents.OnWIAConnect;
     InitHandler.HOnWIADisconnect := HandlerEvents.OnWIADisconnect;
     InitHandler.HOnSendSmsReport := HandlerEvents.OnSendSmsReport;
     InitHandler.HOnReceiveSmsMsg := HandlerEvents.OnReceiveSmsMsg;
     InitHandler.HOnWIAStatusMsg := HandlerEvents.OnWIAStatusMsg;
     InitHandler.HOnSendUSSDResponse := HandlerEvents.OnSendUSSDResponse;
     InitHandler.HOnReceiveUSSDMsg := HandlerEvents.OnReceiveUSSDMsg;

     if (InitLib(@InitHandler)) then
      begin
         mmoLog.Lines.Add('DLL initialized');
      end else
      begin
         mmoLog.Lines.Add('DLL NO initialized');
      end;

// except on e:Exception do
//  begin
//    mmoLog.Lines.Add('Exception:' + e.Message);
//  end;
// end;


end;

procedure TForm1.btn2Click(Sender: TObject);
begin
 try
     if (UninitLib) then
      begin
         mmoLog.Lines.Add('DLL UNinitialized');
      end else
      begin
         mmoLog.Lines.Add('DLL NO UNinitialized');
      end;
 except on e:Exception do
  begin
    mmoLog.Lines.Add('Exception:' + e.Message);
  end;
 end;
end;

end.

Can you help ,me somebody? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:07:40+00:00Added an answer on June 17, 2026 at 11:07 pm

    You have used of object for all the callback functions. That is incorrect. The C header does not do that and so there is a binary mismatch. That explains your errors.

    Fix the problem by removing all mention of of object from your Delphi unit.

    Some other comments:

    • C char maps to Delphi AnsiChar, or Delphi Byte. On a Unicode Delphi, your use of Char will be incorrect.
    • Likewise you should use PAnsiChar rather than PChar.
    • The functions InitLIb, StartRun etc. are declared as __stdcall in the C code. You’ve made them cdecl in your Delphi code.
    • The fourth parameter of On_SendSmsReport takes a pointer to the struct. Your Delphi code is declared to receive the struct. You need to add that indirection and make the Delphi code also receive a pointer.
    • The pPortStatus parameter of On_WIAStatusMsg is a pointer to a byte array. You’ve declared it in Delphi as Byte.

    I suspect there are a handful more errors in your conversion. I recommend you go over it again very carefully.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you guys help with this please? I need to convert a real number,
Im a beginner to css, please can someone help me get this element to
To all: Can someone please help me about how to convert the time (HH:mm)
I'm currently working with Zend framework and I need help to convert this query
Can you please help me how to convert the following code to using "in"
Please can someone help? I have the following code which uploads a file to
Any body please can please help me, how to center a JFrame on Mac.
I am new to HTML and Javascript. Please someone can help me with the
I wonder whether someone can help me please. I'm using the following script to
Can you please help to derive a regular expression that matches the bold-italics portion

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.