Announcement

Collapse
No announcement yet.

Am I even close on these several lines of C translation?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Am I even close on these several lines of C translation?

    The following is a "C" type structure define, followed by my (un)educated guesses as to what it translates to...

    C Code:

    typedef struct st_ServerRecord {
    const char *className;
    const char *name;
    ActivateFunc *activate;
    ServerTagInfo *tagInfo;
    } ServerRecord;


    ** Note: "activate" is a FUNCTION, "tagInfo" is another TYPE also defined elsewhere in the code.

    PowerBasic(?):

    TYPE ServerRecord
    className AS ASCII PTR
    name AS ASCII PTR
    ActivateFunc AS activate PTR
    ServerTagInfo AS tagInfo PTR
    END TYPE

    The only 'translation' I feel remotely comfortable with is the "ServerTagInfo AS tagInfo PTR". The ASCII PTR is simply a guess on my part; looking at it more & more, I'm increasingly convinced that I got that one wrong-- Maybe its wanting to define $string constants based on the sting data located at "*..." (?)

    Since "activate" is a coded function, could the CODEPTR-function work here?


    I've spent the last 16+ hours looking just at these six lines of code, and quite honestly, I'm feeling more lost than when I started this yesterday.


    Any help on this would be GREATLY appreciated!

    Sincerely,

    Scott Martindale



    [This message has been edited by Scott Martindale (edited July 27, 2001).]

  • #2

    scott, did you try the latest update of my header conversion program?

    http://www.powerbasic.com/support/pb...ad.php?t=27849

    regards,

    ------------------
    kev g peel
    kgp software, bridgwater, uk.
    mailto:[email protected][email protected]</a> http://www.kgpsoftware.com
    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

    Comment


    • #3
      Hi Kev,

      I'm sorry for not getting back with you sooner-- I was swamped with emails from a mailing list I subscribe to, and your email got lost in the pile.

      To answer your question; yes, I have tried the latest version you sent me, and it I have to say that it does a pretty darned commendable job!

      The "translations" I just posted were the few elements that didn't make it across. The following is the original snipet (again), and what "HeaderToInclude" interpreted it as meaning:

      --- Original Code ---
      typedef struct st_ServerRecord {
      const char *className;
      const char *name;
      ActivateFunc *activate;
      ServerTagInfo *tagInfo;
      } ServerRecord;


      --- Translated To... ---
      Type ServerRecord
      char *className As const
      char *name As const
      ActivateFunc *activate As ActivateFunc *activate
      ServerTagInfo *tagInfo As ServerTagInfo *tagInfo
      End Type


      Once again, I apologize for not responding sooner. Gosh knows that I hate it when I send someone something I spent a lot of time on, and I don't hear back from them...

      Thanks again!

      Scott


      [This message has been edited by Scott Martindale (edited July 27, 2001).]

      Comment


      • #4
        Scott,

        I need the C/C++ type breakdown on the following:

        ActivateFunc
        ServerTagInfo

        Sounds like they maybe structures but not sure.

        Your first two were right on target.

        Cheers,
        Cecil

        ------------------

        Comment


        • #5
          Hi Cecil,

          Buried in another header file are the following typedefs with comments:

          --- ActivateFunc ---
          /*
          * Activation Function. The server entry points are all functions of
          * this kind, taking a version number, global function pointer, local
          * (class-specific) data and module data. The return value indicates
          * if the service could run and the reason for failure if it couldn't.
          */
          typedef int ActivateFunc (long version,
          GlobalFunc *global,
          void *local,
          void *serverData);

          --- ServerTagInfo ---
          typedef struct st_ServerTagInfo {
          const char *string;
          unsigned int tag;
          } ServerTagInfo;

          --- Additional Info "Nugget" ---
          /*
          * Server Definition Record. Each server record describes a single
          * activation entry point in the plug-in module. Each has a class,
          * a name, an activation function, and an array of tag info structs
          * terminated with a zero tag code.
          */
          typedef struct st_ServerRecord {
          const char *className;
          const char *name;
          ActivateFunc *activate;
          ServerTagInfo *tagInfo;
          } ServerRecord;

          #define ServerUserName ServerTagInfo
          ---------------------------

          Thank you for taking the time to ask me about this!

          Scott


          ps-- I have just registered for a "C++ for Programmers" class at a local community college. If its even close to what the the course description says, it sounds like just what a lot of us C-impaired people need. It starts up in several weeks, and I'll post the books used and pass-along what I pick up along the way. Having umteen c-related reference books can come in handy, but to have the ability to learn directly from an instructor can eliminate a lot of the initial ambiguity C frequently provides to people who are new to it.

          Once again, I'll keep all interested parties posted, and in the mean time, ANY additional help on these two examples would be DEEPLY appreciated. There are approximately 700 other structs like this I have the honor of disseminating which, once I have a clearer understanding on these two examples, appears be more grunt-work than deciphering.

          I work with a guy that programs in C (primarily MFC C++), but it appears (though I can't see how) that he's suffering from a moderate case of PB-impairment. We've sort of developed this psudo-code/flowchart system that we use as a "Rosetta Stone", so fortunately I'll be able to keep these sorts of posts to a minimum in the future-- Its just that he's out of the office for the next couple of weeks, and I'll be institutionalized if I haven't broken through this 6-line log jam by then...

          Also, I'd be in remiss if I didn't pass-along just how much of a time-saver Kev Peel's programs, "Draw Funk" and "Header To Include" have already proven to be. Go check-out his site-- The URL is listed in an earlier post in this thread, amongst other places...

          /sm




          [This message has been edited by Scott Martindale (edited July 27, 2001).]

          Comment


          • #6
            Scott,

            The [ActivateFunc *activate;] translates to a fn pointer. A more
            accurate trans would be [ActivateFunc as DWORD]. You initialize
            this member of the udt by using the PB fn CODEPTR. The
            [unsigned int tag;] translates to [tag as DWORD]. An unsigned
            integer in Win32 is a DWORD in PB.

            BIG question is, how is this ActivateFunc fn utilized in the
            program???? Is it stowed away in a DLL or are you going to
            need the thing translated???

            Have a great weekend. Be back on Monday!!!!!!!!

            Cheers,
            Cecil


            ------------------

            Comment

            Working...
            X