Results 1 to 3 of 3

Thread: Dev tool: typedef Converter - Convert C/C++/IDL typedef struct and typedef enum to VB

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,625

    Dev tool: typedef Converter - Convert C/C++/IDL typedef struct and typedef enum to VB

    After spending way too much time doing this manually, this idea came to be. I use this extraordinarily frequently, so thought someone else might one day have a use for it. The title pretty much sums it up; here's some notes:

    PROJECT UPDATE, v3:
    -Added support for blocks of #define statements; can convert to Public/Private Const's or to Public/Private Enums
    -More automatic data type replacements
    -Now automatic replacement of | with Or in enums

    Original project:
    -Automatically detects if typedef struct or typedef enum
    -Types support automatic variable type changing and have the most common ones built in (e.g. DWORD = Long, LPSTR = String)
    -Arrays are supported for types, both when defined by number var[10]->var(0 To 9) and by variable, var[MAX_PATH]->var(0 To (MAX_PATH - 1))
    -Comments have the option to be included or removed
    -Enums that don't have an = sign (sequential) are supported, both with and without an initial entry with =0 or =1
    -Option for public or private
    -Option to remove 'tag' in names
    -Various automatic syntax corrections
    -I did leave most string types out of type-replacement, since whether they're used as a String or Long is up to the user; only strings I defined were LPWSTR, LPCWSTR, and LPCTSTR as Long, then LPSTR and BSTR as string.

    Samples
    Code:
            typedef enum _tagPSUACTION
            {
                PSU_DEFAULT            = 1         // gets security URL and returns its domain.
                ,PSU_SECURITY_URL_ONLY             // gets just the security URL
            } PSUACTION;
    Code:
    Public Enum PSUACTION
    	PSU_DEFAULT=1 ' gets security URL and returns its domain.
    	PSU_SECURITY_URL_ONLY = 2 ' gets just the security URL
    End Enum
    Code:
    typedef struct SMDATA
    {
        DWORD   dwMask;             // SMDM_* values
        DWORD   dwFlags;            // Not used
        long    hmenu;              // Static HMENU portion.
        HWND    hwnd;               // HWND owning the HMENU
        UINT    uId;                // Id of the item in the menu (-1 for menu itself)
        UINT    uIdParent;          // Id of the item spawning this menu
        UINT    uIdAncestor[80];        // Id of the very top item in the chain of ShellFolders
        //IUnknown*    punk;          // IUnkown of the menuband
    	long punk; //use pointer??
        long pidlFolder;// pidl of the ShellFolder portion
        long   pidlItem;  // pidl of the item in the ShellFolder portion
        //IShellFolder*   psf;        // IShellFolder for the shell folder portion
        long  psf; //use pointer??
    	WCHAR   pvUserData[MAX_PATH];         // User defined Data associated with a pane.
    } SMDATA;
    Code:
    Public Type SMDATA
    	dwMask As Long ' SMDM_* values
    	dwFlags As Long ' Not used
    	hmenu As long ' Static HMENU portion.
    	hwnd As Long ' HWND owning the HMENU
    	uId As Long ' Id of the item in the menu (-1 for menu itself)
    	uIdParent As Long ' Id of the item spawning this menu
    	uIdAncestor(0 To 79) As Long ' Id of the very top item in the chain of ShellFolders
    	'IUnknown*    punk;          // IUnkown of the menuband
    	punk As long 'use pointer??
    	pidlFolder As long ' pidl of the ShellFolder portion
    	pidlItem As long ' pidl of the item in the ShellFolder portion
    	'IShellFolder*   psf;        // IShellFolder for the shell folder portion
    	psf As long 'use pointer??
    	pvUserData(0 To (MAX_PATH - 1)) As Integer ' User defined Data associated with a pane.
    End Type

    Those two really show it all...

    I might change this into an add-in that could do convert-on-paste or convert from the right click menu, if anyone is interested in that let me know.

    NOTE: I believe the people who would use a tool like this would also not need extensive documentation of the code or e.g. not be ok with the only way to add type replacements being to add another line in a function... this isn't for beginners so don't be too harsh about the cryptic code
    Also, I rely on VB to do things like correct the case of native data types (long isn't replaced with Long), and change &H0001 to &H1; it's not worth doing manually.

    If anyone is interested I also have a utility that will turn a UUID into a IID_IWhatever function like the ones in mIID.bas in oleexp.

    PS- Don't actually use that SMDATA type; I altered it to show features.
    Attached Files Attached Files
    Last edited by fafalone; Sep 29th, 2015 at 05:25 AM. Reason: New version

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,900

    Re: Dev tool: typedef Converter - Convert C/C++/IDL typedef struct and typedef enum t

    As this is a complete utility rather than a code snippet I've moved it to the utilities section.

    Good work, by the way, and I hope others will find it useful.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,625

    Re: Dev tool: typedef Converter - Convert C/C++/IDL typedef struct and typedef enum t

    Thanks Senor Funky

    ---

    Project updated; support for #define -> Const or Enum, support for | -> Or, and more data types.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width