Dev tool: typedef Converter - Convert C/C++/IDL typedef struct and typedef enum to VB-VBForums
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
    Frenzied Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    1,114

    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

  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
    5,328

    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.
    When one of my minions says, "Hey, he's just one guy, what can he do?" I say "This"... and shoot them.

    The problem with putting your lair in a volcano is keeping your robot army from melting.

    I know that the human being and the fish can coexist peacefully - George Bush

  3. #3

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.