Announcement

Collapse
No announcement yet.

Some C++ hearder conversion help

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

  • Some C++ hearder conversion help

    Okay I have this certain software's plug-in SDK header that I'm trying to convert to PB6, I used the C header file converter in the Downlaod section, but it's having trouble with these few lines:

    Code:
    #define trillianInitialize(structure) do { memset(&structure,0,sizeof(structure)); structure.struct_size = sizeof(structure); } while (0); 
    #define trillianListInitialize(structure)  \
    	do {\
    		memset(&structure,0,sizeof(structure)); structure.struct_size = sizeof(structure); \
    		structure.section_id = structure.parent_id = structure.previous_id = structure.unique_id = -1;\
    		structure.selectable = 1;\
    		trillianInitialize(structure.font); \
    		structure.font.flags = 1; \
    		structure.font.hover_background = structure.font.hover_foreground = structure.font.select_background = structure.font.select_foreground = structure.font.background = structure.font.foreground = -1; \
    	} while (0);
    anyone have a clue on how that would be converted to PB6?

    ------------------
    Thank you,
    Ryan M. Cross
    Webmaster FlexiFish Inc. UK
    Likuid Creations Inc.
    Thank you,
    Ryan M. Cross

  • #2
    Ryan,

    the code above are C macros. The "\" char is the same as
    "_" in PB for line continuing.

    Be aware that "A=B=C=D=1" is a BOOLEAN expression in PB [A=(B=(C=(D=1)))]
    and an ASSIGNMENT in C [D=1:C=D:B=C:A=B].

    To make a correct translation you should post what "structure" is.
    In code it is a Font.

    Regards,

    Torsten


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




    [This message has been edited by Torsten Rienow (edited September 12, 2002).]

    Comment


    • #3
      Thanks for your help, here's the complete header:
      Or if you want to download it I posted it on the web at: http://www.interfeardev.com/plugin.h

      Thanks again for all the help, it's much appreciated.

      Code:
      #include <windows.h>
      
      #ifndef TRILLIAN_PLUGIN_H
      #define TRILLIAN_PLUGIN_H
      
      typedef int (*ttkCallback)(int windowID, char *subwindow, char *event, void *data, void *userData);
      typedef int (*plugin_function)(char *guid, char *event, void *data);
      typedef int (*plugin_function_send)(char *guid, char *event, void *data);
      typedef int (*plugin_function_main)(char *event, void *data);
      typedef int (*plugin_function_version)();
      
      #define isTrillianError(error_code) (error_code < 0)
      #define isTrillianSuccess(error_code) (error_code >= 0)
      #define trillianInitialize(structure) do { memset(&structure,0,sizeof(structure)); structure.struct_size = sizeof(structure); } while (0); 
      #define trillianListInitialize(structure)  \
      	do {\
      		memset(&structure,0,sizeof(structure)); structure.struct_size = sizeof(structure); \
      		structure.section_id = structure.parent_id = structure.previous_id = structure.unique_id = -1;\
      		structure.selectable = 1;\
      		trillianInitialize(structure.font); \
      		structure.font.flags = 1; \
      		structure.font.hover_background = structure.font.hover_foreground = structure.font.select_background = structure.font.select_foreground = structure.font.background = structure.font.foreground = -1; \
      	} while (0); 
      
      #define TRILLIAN_PREFS_CANCEL 0
      #define TRILLIAN_PREFS_APPLY  1
      #define TRILLIAN_PREFS_OK     2
      
      #define TRILLIAN_PREFS_SHOW   1
      #define TRILLIAN_PREFS_HIDE   0
      
      #define MENU_TEXT             0  
      #define MENU_SEPARATOR        1  
      #define MENU_POPUP            2  
      #define MENU_HEADING          3  
      #define MENU_CALLBACK         4 
      #define MENU_DEFAULT          5   
          
      #define MENU_TIMEOUT_DEFAULT  0  
      #define MENU_TIMEOUT_INFINITE -1  
      
      struct plugin_info_t
      {
      	unsigned int   struct_size;
      
      	/* Information given to the plugin */
      	char *config_directory;
      	char *skin_directory;
      	char *temp_directory;
      	plugin_function_send plugin_send;
      
      	/* Plugin Fills out this information */
      	char guid[128];
      
      	char name[256];
      	char company[256];
      	char version[64];
      	char description[1024];
      };
      
      struct alert_t
      {
      	unsigned int   	struct_size;
      
      	char		*text;
      	char		*type;
      	int		word_wrap;
      	int		formatted;
      	int		link;
      	ttkCallback 	callback;
      	void		*data;
      };
      
      struct plugin_prefs_info_t
      {
      	unsigned int   	struct_size;
      
      	char		name[128];
      	char		description[1024];
      
      	HBITMAP		bitmap;
      };
      
      struct plugin_prefs_show_t
      {
      	unsigned int	   		struct_size;
      
      	int   				show; //1 shows, 0 hides
      
      	char 				*pref_name;
      	char 				*sub_entry;
      	
      	HWND  				hwnd;
      	int   				x;
      	int   				y;
      
      	struct plugin_prefs_info_t 	prefs_info;
      };
      
      struct plugin_prefs_action_t
      {
      	unsigned int   			struct_size;
      
      	int 				type;  //0 = cancel, 1 = apply, 2 = ok
      };
      
      
      struct plugin_prefs_entry_t
      {
      	unsigned int   			struct_size;
      
      	char 				*sub_name;
      	struct plugin_prefs_entry_t 	*next;
      };
      
      struct plugin_prefs_t
      {
      	unsigned int   			struct_size;
      
      	int 				enabled;
      
      	char 				*pref_name;
      
      	struct plugin_prefs_entry_t 	*sub_entry;
      };
      
      struct alias_t
      {
      	unsigned int   		struct_size;
      
      	int     		alias_id;
      
      	char			*text;
      
      	ttkCallback		callback;
      	void			*data;
      };
      
      struct alias_request_t
      {
      	unsigned int   		struct_size;
      
      	int			alias_id;
      
      	char			*alias;
      	char			*text;
      };
      
      struct keyboard_alias_t
      {
      	unsigned int   		struct_size;
      
      	int			alias_id;
      
      	int			alt;
      	int			ctrl;
      	int			shift;
      
      	char			key;
      
      	ttkCallback		callback;
      	void			*data;
      };
      
      struct keyboard_alias_request_t
      {
      	unsigned int   		struct_size;
      
      	int			alias_id;
      
      	int			alt;
      	int			ctrl;
      	int			shift;
      	char			key;
      
      	char			*text; //to be inserted...if none, make this NULL
      }; 
      
      struct list_bmp_t
      {
      	unsigned int   		struct_size;
      
      	int			num_states;
      	HBITMAP			*bitmap;
      	RECT			*location;
      
      	/* Animated support not available currently */
      	int			animated;
      	int			time;
      	int			loop;
      	int			cur_state;
      
      	/* skin based references */
      	int			*skin_based;  
      	char			**skin_name;
      	char			**skin_type;
      	char			**skin_state;
      };
      
      struct list_font_t
      {
      	unsigned int   		struct_size;
      
      	int			flags;  //0x00000000000000
      					//0x00001 = skins
      					//0x00010 = font file not the other stuff
      
      	char   			*skin_name;
      
      	HFONT   		font;
      
      	//skin based
      	char			*hover_fore;
      	char			*hover_back;
      	char			*select_fore;
      	char			*select_back;
      	char			*normal_fore;
      	char			*normal_back;
      
      	//nonskin based
      	COLORREF  		hover_background;
      	COLORREF  		hover_foreground;
      	COLORREF  		select_background;
      	COLORREF  		select_foreground;
      	COLORREF  		background;
      	COLORREF  		foreground;
      
      };
      
      struct menu_entry_t
      {
      	unsigned int   		struct_size;
      
      	int			menu_id;
      	int			sub_menu_id;
      	int			type;
      	
      	int			timeout;
      	int			disabled;
      	int			num_copies;
      
      	char			*icon;
      	char			*text;
      	char			*shortcut;
      
      	void			*data;
      	HWND			hwnd;
      
      	struct menu_entry_t 	*sub_menu;
      	struct menu_entry_t 	*next_menu;
      
      	ttkCallback 		callback;
      };
      
      struct list_entry_t 
      {
      	unsigned int   		struct_size;
      
      	int			num_left_icons;		
      	struct list_bmp_t	*left_icons;
      
      	int			num_right_icons;		
      	struct list_bmp_t	*right_icons;
      
      	struct list_font_t	font;
      
      	int			section_id;
      	int			parent_id;
      	int			previous_id;
      	int			unique_id;
      
      	int			group;				
      	int			section;
      
      	int			drag_and_drop;
      	int			inline_editing;		
      	int			selectable;			
      	int			expanded;			
      	int			auto_expand;
      	int			no_group_icon;
      	int			no_double_click;
      	int			owner_drawn;
      	int			no_section_margins;
      	
      	int			floating;
      	int			floating_x;
      	int			floating_y;
      
      	char			*tooltip;			
      	char			*text;				
      	char			*edit_string;
      	char			*real_name;
      
      	void			*data;				
      	
      	struct menu_entry_t	*menu_entry;
      	ttkCallback		callback;
      };
      
      struct dialog_entry_t
      {
      	unsigned int		struct_size;
      
      	HWND			hwnd;
      };
      
      struct list_update_t 
      {
      	unsigned int	struct_size;
      
      	HDC				hdc;
      	HWND			hwnd;
      
      	int				x;
      	int				y;
      	int				y_offset;
      
      	int				width;
      	int				height;
      
      	//colors
      	COLORREF		hover_background;
      	COLORREF		hover_foreground;
      	COLORREF		hover_border;
      	COLORREF		select_background;	
      	COLORREF		select_foreground;
      	COLORREF		select_border;
      	COLORREF		background;
      	COLORREF		foreground;
      
      	//state	
      	int				selected;
      	int				hover;
      	int				floating;
      	int				black_and_white;
      
      };
      
      struct connection_enum_t
      {
      	unsigned int	struct_size;
      
      	char			*medium;
      
      	ttkCallback		callback;
      	void			*data;
      };
      
      struct connection_entry_t
      {
      	unsigned int	struct_size;
      
      	char			*medium;
      	int				connection_id;
      
      	char			*name;
      	char			*status;
      };
      
      struct contactlist_enum_t
      {
      	unsigned int	struct_size;
      
      	char			*medium;
      	int				connection_id;
      
      	ttkCallback		callback;
      	void			*data;
      };
      
      struct contactlist_entry_t
      {
      	unsigned int	struct_size;
      
      	char			*medium;
      	int				connection_id;
      
      	char			*name;
      	char			*real_name;
      	char			*status;
      };
      
      struct message_t
      {
      	unsigned int	struct_size;
      
      	char			*medium;
      	int				connection_id;
      
      	char			*name;
      	char			*type;
      	char			*text;
      
      	char			*location;
      
      	void			*extra_information;
      };
      
      struct message_broadcast_t
      {
      	unsigned int	struct_size;
      
      	int				broadcast_id;
      
      	ttkCallback		callback;
      	void			*data;
      };
      
      #endif


      ------------------
      Thank you,
      Ryan M. Cross
      Thank you,
      Ryan M. Cross

      Comment


      • #4
        The original appears to have come from http://www.trillian.cc/dev/plugin.h.html

        Admin note: Copyright does not appear to be a problem here, so the code can live.

        The trillianListInitialize Macro would tyranslate to something like this in PB/Win:
        Code:
        MACRO trillianListInitialize(structure)
          RESET structure                    ' (sets all bytes of UDT to $NUL)
          structure.struct_size = SIZEOF(structure)
          structure.section_id = -1
          structure.parent_id = -1
          structure.previous_id = -1
          structure.unique_id = -1
          structure.selectable = 1
          trillianInitialize(structure.font) ' this embeds another MACRO
          structure.font.flags = 1
          structure.font.hover_background = -1
          structure.font.hover_foreground = -1
          structure.font.select_background = -1
          structure.font.select_foreground = -1
          structure.font.background = structure.font.foreground = -1
        END MACRO
        The DO/WHILE(0) loop is a one-shot occurance... it appears to be a kludge to provide some kind of multi-line macro block.

        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          So I would need PB/Win 7 for this code to be translated? Damn! I want ot buy PB/Win 7, just don't have the extra funds for it right now.

          ------------------
          Thank you,
          Ryan M. Cross
          Thank you,
          Ryan M. Cross

          Comment


          • #6
            No, you don't need PB 7.

            That MACRO can easily be rewritten as a FUNCTION...

            Code:
            FUNCTION trillianListInitialize(structure as list_font_t)
            ... same
            END FUNCTION
            MACROs are simply compile-time text-substituters.

            MCM
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Thanks for all your help guys, but I'm sitll having trouble with som other lines. Especially these ones:

              Code:
              typedef int (*ttkCallback)(int windowID, char *subwindow, char *event, void *data, void *userData);
              typedef int (*plugin_function)(char *guid, char *event, void *data);
              typedef int (*plugin_function_send)(char *guid, char *event, void *data);
              typedef int (*plugin_function_main)(char *event, void *data);
              typedef int (*plugin_function_version)();
              
              #define isTrillianError(error_code) (error_code < 0)
              #define isTrillianSuccess(error_code) (error_code >= 0)
              ------------------
              Thank you,
              Ryan M. Cross
              Thank you,
              Ryan M. Cross

              Comment


              • #8
                ttt

                ------------------
                Thank you,
                Ryan M. Cross
                Thank you,
                Ryan M. Cross

                Comment


                • #9
                  ttt = to the top?

                  These typedef statements are generic declarations. The equivalent in PowerBASIC is a DECLARE without an ALIAS or LIB clause, then you'd call the actual function with LoadLibrary(), GetProcAddress(), and finally use CALL DWORD...USING. The generic declaration would be used as the USING template.

                  Code:
                  typedef int (*ttkCallback)(int windowID, char *subwindow, char *event, void *data, void *userData);
                  ~
                  DECLARE FUNCTION ttkCallback CDECL (BYVAL windowID AS LONG, BYREF subwindow AS ASCIIZ, event AS ANY, userData AS ANY) AS LONG
                  The others would use the same kind of conversion. Above I declared "subwindow" as a BYREF ASCIIZ but there might be a better declaration depending on what that parameter is actually doing. As long as you pass an address for that parameter, it will work fine. Ditto for the "event" and "userData" parameters.

                  Oh, those are most likely using CDECL calling convention too...

                  The two #defines are simple macros, of which you can directly substitute a FUNCTION:
                  Code:
                  #define isTrillianError(error_code) (error_code < 0)
                  ~
                  FUNCTION isTrillianError(BYVAL error_code AS LONG) AS LONG
                    FUNCTION = (error_code < 0)
                  END FUNCTION
                   
                  #define isTrillianSuccess(error_code) (error_code >= 0)
                  ~
                  FUNCTION isTrillianSuccess(BYVAL error_code AS LONG) AS LONG
                    FUNCTION = (error_code >= 0)
                  END FUNCTION

                  ------------------
                  Lance
                  PowerBASIC Support
                  mailto:[email protected][email protected]</A>
                  Lance
                  mailto:[email protected]

                  Comment


                  • #10
                    Just gotta say Lance you are the man! I'm almost done with this conversion. I jsut need a little more help. Im having trouble with every remarked line with a "<<<<<<" after it.

                    Code:
                    $INCLUDE "win32api.inc"
                    
                    $IF NOT %DEF(%TRILLIAN_PLUGIN_H)
                    %TRILLIAN_PLUGIN_H = 0
                    
                    DECLARE FUNCTION ttkCallback CDECL (BYVAL windowID AS LONG, BYREF subwindow AS ASCIIZ, event AS ANY, userData AS ANY) AS LONG
                    DECLARE FUNCTION plugin_function CDECL (BYREF guid AS ASCIIZ, BYREF event AS ASCIIZ, dat AS ANY) AS LONG
                    DECLARE FUNCTION plugin_function_send CDECL (BYREF guid AS ASCIIZ, BYREF event AS ASCIIZ, dat AS ANY) AS LONG
                    DECLARE FUNCTION plugin_function_main CDECL (BYREF event AS ASCIIZ, dat AS ANY) AS LONG
                    DECLARE FUNCTION plugin_function_version CDECL () AS LONG
                    
                    FUNCTION isTrillianError(BYVAL error_code AS LONG) AS LONG
                        FUNCTION = (error_code < 0)
                    END FUNCTION
                    
                    FUNCTION isTrillianSuccess(BYVAL error_code AS LONG) AS LONG
                        FUNCTION = (error_code >= 0)
                    END FUNCTION
                    
                    
                    FUNCTION trillianInitialize(structure) AS INTEGER '<<<<<< What should structure be?
                        RESET structure
                        structure.struct_size = SIZEOF(structure)
                    END FUNCTION
                    
                    FUNCTION trillianListInitialize(structure) AS LONG '<<<<<< What should structure be?
                        RESET structure                    ' (sets all bytes of UDT to $NUL)
                        structure.struct_size = SIZEOF(structure)
                        structure.section_id = -1
                        structure.parent_id = -1
                        structure.previous_id = -1
                        structure.unique_id = -1
                        structure.selectable = 1
                        trillianInitialize(structure.font) ' this embeds another MACRO
                        structure.font.flags = 1
                        structure.font.hover_background = -1
                        structure.font.hover_foreground = -1
                        structure.font.select_background = -1
                        structure.font.select_foreground = -1
                        structure.font.background = structure.font.foreground = -1
                    END FUNCTION
                    
                    %TRILLIAN_PREFS_CANCEL  = 0
                    %TRILLIAN_PREFS_APPLY   = 1
                    %TRILLIAN_PREFS_OK      = 2
                    
                    %TRILLIAN_PREFS_SHOW    = 1
                    %TRILLIAN_PREFS_HIDE    = 0
                    
                    %MENU_TEXT              = 0
                    %MENU_SEPARATOR         = 1
                    %MENU_POPUP             = 2
                    %MENU_HEADING           = 3
                    %MENU_CALLBACK          = 4
                    %MENU_DEFAULT           = 5
                    
                    %MENU_TIMEOUT_DEFAULT   = 0
                    %MENU_TIMEOUT_INFINITE  = -1
                    
                    TYPE plugin_info_t
                        struct_size AS DWORD
                        '  Information given to the plugin
                        config_directory AS ASCIIZ PTR
                        skin_directory AS ASCIIZ PTR
                        temp_directory AS ASCIIZ PTR
                        'plugin_send AS plugin_function_send   <<<<<<
                        '  Plugin Fills out this information
                        guid AS ASCIIZ * 128
                        name1 AS ASCIIZ * 256
                        company AS ASCIIZ * 256
                        version AS ASCIIZ * 64
                        description AS ASCIIZ * 1024
                    END TYPE
                    
                    TYPE alert_t
                        struct_size AS DWORD
                        TEXT AS ASCIIZ PTR
                        type_ AS ASCIIZ PTR
                        word_wrap AS LONG
                        formatted AS LONG
                        link AS LONG
                        'callback_ AS CODEPTR(ttkCallback)   <<<<<<
                        data_ AS LONG PTR
                    END TYPE
                    
                    TYPE plugin_prefs_info_t
                        struct_size AS DWORD
                        name_ AS ASCIIZ * 128
                        description AS ASCIIZ * 1024
                        bitmap AS LONG
                    END TYPE
                    
                    TYPE plugin_prefs_show_t
                        struct_size AS DWORD
                        show_ AS LONG                      ' 1 shows, 0 hides
                        pref_name AS ASCIIZ PTR
                        sub_entry AS ASCIIZ PTR
                        hwnd AS LONG
                        x AS LONG
                        y AS LONG
                        prefs_info AS plugin_prefs_info_t
                    END TYPE
                    
                    TYPE plugin_prefs_action_t
                        struct_size AS DWORD
                        type_ AS LONG                      ' 0 = cancel, 1 = apply, 2 = ok
                    END TYPE
                    
                    
                    TYPE plugin_prefs_entry_t
                        struct_size AS DWORD
                        sub_name AS ASCIIZ PTR
                        next_ AS plugin_prefs_entry_t PTR
                    END TYPE
                    
                    TYPE alias_t
                        struct_size AS DWORD
                        enabled AS LONG
                        pref_name AS ASCIIZ PTR
                        sub_entry AS plugin_prefs_entry_t
                    END TYPE
                    
                    TYPE alias_request_t
                        struct_size AS DWORD
                        alias_id AS LONG
                        TEXT AS ASCIIZ PTR
                        'CALLBACK AS CODEPTR(ttkCallback)
                        'data_ AS any   <<<<<<
                    END TYPE
                    
                    
                    TYPE keyboard_alias_t
                        struct_size AS DWORD
                        alias_id AS LONG
                        alt AS LONG
                        ctrl AS LONG
                        shift_ AS LONG
                        key AS ASCIIZ PTR
                        'CALLBACK AS CODEPTR(ttkCallback)
                        'data_ AS any
                    END TYPE
                    
                    TYPE keyboard_alias_request_t
                        struct_size AS DWORD
                        alias_id AS LONG
                        alt AS LONG
                        ctrl AS LONG
                        shift_ AS LONG
                        key AS ASCIIZ PTR
                        TEXT AS ASCIIZ PTR                 ' to be inserted...if none, make this NULL
                    END TYPE
                    
                    TYPE list_bmp_t
                        struct_size AS DWORD
                        num_states AS LONG
                        'bitmap AS HBITMAP   <<<<<<
                        location AS RECT
                        '  Animated support not available currently
                        animated AS LONG
                        time AS LONG
                        loop_ AS LONG
                        cur_state AS LONG
                        '  skin based references
                        skin_based AS LONG PTR
                        skin_name AS ASCIIZ PTR
                        skin_type AS ASCIIZ PTR
                        skin_state AS ASCIIZ PTR
                    END TYPE
                    
                    TYPE list_font_t
                        struct_size AS DWORD
                        flags AS LONG                       ' 0x00000000000000
                        ' 0x00001 = skins
                        ' 0x00010 = font file not the other stuff
                        skin_name AS ASCIIZ PTR
                        font AS LONG
                        ' skin based
                        hover_fore AS ASCIIZ PTR
                        hover_back AS ASCIIZ PTR
                        select_fore AS ASCIIZ PTR
                        select_back AS ASCIIZ PTR
                        normal_fore AS ASCIIZ PTR
                        normal_back AS ASCIIZ PTR
                        ' nonskin based
                        hover_background AS DWORD
                        hover_foreground AS DWORD
                        select_background AS DWORD
                        select_foreground AS DWORD
                        background AS DWORD
                        foreground AS DWORD
                    END TYPE
                    
                    TYPE menu_entry_t
                        struct_size AS DWORD
                        menu_id AS LONG
                        sub_menu_id AS LONG
                        type_ AS LONG
                        timeout_ AS LONG
                        disabled AS LONG
                        num_copies AS LONG
                        icon AS ASCIIZ PTR
                        TEXT AS ASCIIZ PTR
                        shortcut AS ASCIIZ PTR
                        'data_ AS any
                        hwnd AS LONG
                        'sub_menu AS menu_entry_t   <<<<<<
                        'next_menu AS menu_entry_t   <<<<<<
                        'CALLBACK AS CODEPTR(ttkCallback)
                    END TYPE
                    
                    TYPE list_entry_t
                        struct_size AS DWORD
                        num_left_icons AS LONG
                        'list_bmp_t AS left_icons   <<<<<<
                        num_right_icons AS LONG
                        'list_bmp_t AS right_icons   <<<<<<
                        'list_font_t AS font   <<<<<<
                        section_id AS LONG
                        parent_id AS LONG
                        previous_id AS LONG
                        unique_id AS LONG
                        group AS LONG
                        section AS LONG
                        drag_and_drop AS LONG
                        inline_editing AS LONG
                        selectable AS LONG
                        expanded AS LONG
                        auto_expand AS LONG
                        no_group_icon AS LONG
                        no_double_click AS LONG
                        owner_drawn AS LONG
                        no_section_margins AS LONG
                        floating AS LONG
                        floating_x AS LONG
                        floating_y AS LONG
                        tooltip AS ASCIIZ PTR
                        TEXT AS ASCIIZ PTR
                        edit_string AS ASCIIZ PTR
                        real_name AS ASCIIZ PTR
                        data_ AS LONG PTR
                        'menu_entry_t AS menu_entry   <<<<<<
                        'CALLBACK AS CODEPTR(ttkCallback)
                    END TYPE
                    
                    TYPE dialog_entry_t
                        struct_size AS DWORD
                        hwnd AS LONG
                    END TYPE
                    
                    TYPE list_update_t
                        struct_size AS DWORD
                        hdc AS LONG
                        hwnd AS LONG
                        x AS LONG
                        y AS LONG
                        y_offset AS LONG
                        width_ AS LONG
                        height AS LONG
                        ' colors
                        hover_background AS DWORD
                        hover_foreground AS DWORD
                        hover_border AS DWORD
                        select_background AS DWORD
                        select_foreground AS DWORD
                        select_border AS DWORD
                        background AS DWORD
                        foreground AS DWORD
                        ' state
                        selected AS LONG
                        hover AS LONG
                        floating AS LONG
                        black_and_white AS LONG
                    END TYPE
                    
                    TYPE connection_enum_t
                        struct_size AS DWORD
                        medium AS ASCIIZ PTR
                        'CALLBACK AS CODEPTR(ttkCallback)
                        'data_ AS any
                    END TYPE
                    
                    TYPE connection_entry_t
                        struct_size AS DWORD
                        medium AS ASCIIZ PTR
                        connection_id AS LONG
                        name_ AS ASCIIZ PTR
                        STATUS AS ASCIIZ PTR
                    END TYPE
                    
                    TYPE contactlist_enum_t
                        struct_size AS DWORD
                        medium AS ASCIIZ PTR
                        connection_id AS LONG
                        'CALLBACK AS CODEPTR(ttkCallback)
                        data_ AS LONG PTR
                    END TYPE
                    
                    TYPE contactlist_entry_t
                        struct_size AS DWORD
                        medium AS ASCIIZ PTR
                        connection_id AS LONG
                        name_ AS ASCIIZ PTR
                        real_name AS ASCIIZ PTR
                        STATUS AS ASCIIZ PTR
                    END TYPE
                    
                    TYPE message_t
                        struct_size AS DWORD
                        medium AS ASCIIZ PTR
                        connection_id AS LONG
                        name_ AS ASCIIZ PTR
                        type_ AS ASCIIZ PTR
                        TEXT AS ASCIIZ PTR
                        location AS ASCIIZ PTR
                        extra_information AS LONG PTR
                    END TYPE
                    
                    TYPE message_broadcast_t
                        struct_size AS DWORD
                        broadcast_id AS LONG
                        'CALLBACK AS CODEPTR(ttkCallback)
                        data_ AS LONG PTR
                    END TYPE
                    
                    $ENDIF
                    All suggestions and answers are very much appreciated. Also anythign you see I'm doing wrong on uncommented lines would be greatly aprreciated if they were pointed out with a suggestion of correction.

                    ------------------
                    Thank you,
                    Ryan M. Cross
                    Thank you,
                    Ryan M. Cross

                    Comment


                    • #11
                      ttt
                      Thank you,
                      Ryan M. Cross

                      Comment


                      • #12
                        Code:
                        FUNCTION trillianInitialize(structure) AS INTEGER '<<<<<< What should structure be?
                        The C definition for this is a MACRO, which allows structure to be a variable
                        of any user-defined type. You can't duplicate this definition exactly
                        without using macros. Presuming you already know what kind of UDT is
                        involved, you can make corresponding FUNCTIONs instead. Otherwise, it may
                        make just as much sense to plug the macro's meaning in wherever the macro
                        is invoked. There's not much code involved.
                        Code:
                            'plugin_send AS plugin_function_send   <<<<<<
                            'callback_ AS CODEPTR(ttkCallback)   <<<<<<
                            'data_ AS any   <<<<<<
                        For miscellaneous pointer values, use AS DWORD to substitute.
                        Code:
                            'list_bmp_t AS left_icons   <<<<<<
                        '(from :)   struct list_bmp_t    *left_icons;
                        These translate a bit differently. Like so:
                        Code:
                            left_icons AS list_bmp_t PTR

                        ------------------
                        Tom Hanlin
                        PowerBASIC Staff

                        Comment


                        • #13
                          Thanks a lot Tom. Finally got the header to compile without any error. I finally understand about what you're saying with the whole macro thing. I can work around that. Here's my last problem:

                          I'm trying to get Trillian to atleast attempt to load my plugin. But I'm not sure about a few lines of code:

                          Here's the C++ code: the lines i'm having a problem with have a "<<<<<<"
                          Code:
                          /*
                           * sample_main.c: Main routines for the sample plugin.
                           *
                           * Copyright(c) 2002 Cerulean Studios
                           *
                           */
                          
                          #include "sample.h"
                          #include "resource.h"
                          
                          char			*home_directory = NULL; //<<<<<<
                          	
                          plugin_function_send plugin_send = NULL; //<<<<< 
                          
                          /******************************************************************************
                           p l u g i n _ v e r s i o n ()
                          ******************************************************************************
                          
                            Currently supporting version 1 of plugins.
                          */
                          
                          int __declspec(dllexport)plugin_version(void)
                          {
                          	return 1;
                          }
                          
                          /******************************************************************************
                           p l u g i n _ m a i n ()
                          ******************************************************************************
                          
                            plugin_main() gets called whenever the UI has something to tell us.  This includes
                            telling the plugin when to start, stop, unload, show preferences, etc.
                          */
                           
                          int __declspec(dllexport)plugin_main(char *event, void *data) 
                          {   
                          	if (!_stricmp(event,"load")) { 
                          	   struct plugin_info_t *pi = (struct plugin_info_t *)data;
                          
                          	   if (pi) {
                          
                          			/* Fill in plugin information.
                          			 */
                          
                          			strcpy(pi->guid, MYGUID); 
                          			strcpy(pi->name, "Sample Plugin"); 
                          			strcpy(pi->company, "Cerulean Studios"); 
                          			strcpy(pi->version, "1.0"); 
                          			strcpy(pi->description, "This is a sample plugin.");
                                   
                          			/* Extract what we need and store locally.
                          			 */
                          
                          			home_directory = (char *)malloc(strlen(pi->config_directory)+1); //<<<<<<
                          			strcpy(home_directory, pi->config_directory); //<<<<<<
                          
                          			plugin_send = pi->plugin_send; //<<<<<< 
                          	   } 
                          	} else if (!_stricmp(event, "initialLoad")) {
                          
                          		/* First time a plugin is loaded - can do install wizardish stuff here.
                          		 */
                          
                          	} else if (!_stricmp(event, "start")) {
                          		
                          
                          
                          	} else if (!_stricmp(event,"stop") && plugin_send) {
                          
                          
                          	} else if (!_stricmp(event, "unload")) {			
                          
                          		/* Clean up. 
                          		 */
                          
                          		return 0;
                          	} else if (!_stricmp(event, "finalUnload")) {
                          
                          		/* 
                          		 * Final unload means the plugin is actually being removed.  Plugins should clean up
                          		 * saved settings here (delete INI files, etc).
                          		 */
                          
                          	} else if (!_stricmp(event, "prefsShow")) {
                          
                          	} else if (!_stricmp(event, "prefsAction")) {
                          		
                          	}
                          
                          	return 0; 
                          } 
                          
                          /******************************************************************************
                           D l l M a i n ()
                          ******************************************************************************/
                          
                          int WINAPI DllMain(HANDLE hinstDLL, unsigned long dwReason, void *reserved)
                          {
                          	hInstance = (HINSTANCE)hinstDLL;
                          
                          	switch (dwReason) {
                          
                          		case DLL_THREAD_DETACH:
                          			break;
                          
                                  case DLL_PROCESS_DETACH:
                          			break;
                          	}
                          
                          	return 1;
                          }
                          Here's the code I have converted so far:
                          Code:
                          #COMPILE DLL "c:\program files\trillian\plugins\test.dll"
                          
                          #INCLUDE "plugin.inc"
                          
                          $MYGUID = "902A5401-D29B-4b44-8F9D-46753357895t"
                          
                          GLOBAL home_directory AS ASCIIZ PTR
                          
                          FUNCTION plugin_version CDECL () EXPORT AS LONG
                          
                              FUNCTION = 1
                              
                          END FUNCTION
                          
                          FUNCTION plugin_main CDECL (BYREF event AS ASCIIZ, dat AS DWORD) EXPORT AS LONG
                              
                              SELECT CASE event
                                  CASE "load":
                                      DIM pi AS plugin_info_t
                          
                                      pi.guid = $MYGUID
                                      pi.name1 = "Test Plugin"
                                      pi.company = "Interfear Laboratories"
                                      pi.version = "1.0"
                                      pi.description = "This is a sample plugin."
                                      'pi.config_directory = ??? <<<<<<
                                      'plugin_function_send = pi.plugin_send <<<<<<
                          
                                  CASE "initialLoad":
                                      MSGBOX "Welcome to this test plugin for Trillian Pro!"
                          
                                  CASE "start":
                          
                                  CASE "stop":
                          
                                  CASE "unload":
                          
                                  CASE "finalUnload":
                          
                                  CASE "prefsShow":
                          
                                  CASE "prefsAction":
                          
                              END SELECT
                          END FUNCTION
                          
                          FUNCTION DLLMAIN(BYVAL hInstance AS LONG, BYVAL Reason AS LONG, BYVAL Reserved AS LONG) EXPORT AS LONG
                          
                              SELECT CASE Reason
                          
                                  CASE %DLL_THREAD_DETACH:
                                      EXIT SELECT
                          
                                  CASE %DLL_PROCESS_DETACH:
                                      EXIT SELECT
                          
                              END SELECT
                          
                              FUNCTION = 1
                          END FUNCTION
                          The C++ is jsut the basic structure, I left the extra code out.
                          When I try to load what I have so far the only function that seems to be called is DllMain.
                          Trillian requires plugin_version and plugin_main, but it doesn't seem to even attempt to call them
                          Any help is greatly appreciated and once I get past this part I will no longer have to bother
                          you guys (atleast for C++ conversion). I know PB pretty well so I should be set after this.

                          ------------------
                          Thank you,
                          Ryan M. Cross
                          Thank you,
                          Ryan M. Cross

                          Comment


                          • #14
                            ttt
                            Thank you,
                            Ryan M. Cross

                            Comment


                            • #15
                              This is getting to be an ongoing effort, Ryan, and time-consuming.
                              It might be appropriate to look for a consultant to assist. The PB
                              staff is willing to help when practical, but we don't have as much
                              time to spare as we'd like, and I am not seeing other volunteers for
                              this particular project.

                              As a quick hint, I might say that you probably don't need these lines,
                              which should be handled by BASIC's automatic variable initialization:
                              Code:
                              char *home_directory = NULL; //<<<<<<
                               
                              plugin_function_send plugin_send = NULL; //<<<<<

                              ------------------
                              Tom Hanlin
                              PowerBASIC Staff

                              Comment


                              • #16
                                Ok, I'll drop one or two more hints to complete the set.

                                You'll most likely need to add ALIAS clauses to your FUNCTION and SUB statements to ensure the exported names are capitalized correctly (since Win32 is case-sensitive to Sub/Function names of Exported and Import functions).

                                Also, since DLLMAIN is simply returning 1 in all cases here, you can eliminate the function completely (PowerBASIC will create one automatically for you).


                                ------------------
                                Lance
                                PowerBASIC Support
                                mailto:[email protected][email protected]</A>
                                Lance
                                mailto:[email protected]

                                Comment


                                • #17
                                  Alright guys thanks. I kind of figured with the Alias thing after thinking about it. Thanks to all of you that helped me. I will no longer bother you.

                                  ------------------
                                  Thank you,
                                  Ryan M. Cross
                                  Thank you,
                                  Ryan M. Cross

                                  Comment


                                  • #18
                                    Woo! Also jsut to let you guys know I got Trillian to load my plugin! The alias was the last piece to the puzzle, I'll figure the rest out on my own!

                                    ------------------
                                    Thank you,
                                    Ryan M. Cross
                                    Thank you,
                                    Ryan M. Cross

                                    Comment


                                    • #19
                                      Originally posted by RyanCross:
                                      Woo! Also jsut to let you guys know I got Trillian to load my plugin!

                                      Ryan

                                      Would you mind posting the translated headers to the source code forum? It would save me quite a bit of effort

                                      Thanks

                                      Scott


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

                                      Comment

                                      Working...
                                      X