C-Problem

C-Problem

Postby byte-one » Thu Dec 15, 2011 1:41 pm

Question to the C-programmers:
The following C-code-snippet is included in a harbour-function (HB_FUNC( TEST ). Now i must give the "Mc5Message81C" a value. But with hb_parc( 1 ) or so a compiler-error occurs. Whats the right parameter-conversion?

Code: Select all  Expand view
struct Mc5Message81D {
    Mc5MsgHead h; // Kopf
    union {
        Mc5TargetDataD targetL; // Daten
    };
};

class Mc5Message81C: public Mc5Message81D {
  public:
    Mc5Message81C( void )
    {
      clear();
    }
    ~Mc5Message81C( void )
    {
    }
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: C-Problem

Postby Antonio Linares » Thu Dec 15, 2011 1:48 pm

Günther,

Code: Select all  Expand view

Mc5Message81C mc5 = new Mc5Message81C();

Mc5Message81D mc5m;

mc5m.h = ( Mc5MsgHead ) hb_parnl( 1 );
memcpy( ( unsigned char * ) mc5m.targetL, ( unsigned char * ) hb_parnd( 2 ), sizeof( Mc5TargetDataD ) );
 


Not sure if that is what you are looking for. Is targetL a string or a number ? I have assumed that it is a string
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42085
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: C-Problem

Postby byte-one » Thu Dec 15, 2011 2:16 pm

Antonio, thanks! The above code is from the headerfile.
This is code from my function. The first parameter is a string and should assigned to mtlg. But I cannot convert the string-parameter to mtlg

Code: Select all  Expand view

HB_FUNC (TEST)
Mc5Message81C mtlg;
 
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: C-Problem

Postby Antonio Linares » Thu Dec 15, 2011 4:54 pm

Günther,

But Mc5Message81C is a Class name, why do you want to fill an object with a string ?

Do you want to replace the contents of the object ?

Do you have some example code ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42085
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: C-Problem

Postby byte-one » Thu Dec 15, 2011 8:26 pm

Antonio, this is the original code from the example. I mean, if in the recvfrom() the "&mtlg" is filled with the data from network, this must be a string!?

Code: Select all  Expand view
.
Mc5Message81C mtlg;
.
.
   if( (laengeMtlg = recvfrom( sock, &mtlg, sizeof(mtlg), MSG_OOB, (struct sockaddr *) &cltIpAdr, &cltIpAdrLaenge )) > 0 )
.
.
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: C-Problem

Postby Antonio Linares » Thu Dec 15, 2011 8:51 pm

Günther,

Use memcpy( unsigned char * destination, unsiged char * source, int size )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42085
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: C-Problem

Postby byte-one » Fri Dec 16, 2011 8:42 am

Antonio, thanks very much!
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: karinha and 48 guests