Results 1 to 5 of 5

Thread: [RESOLVED] struct definition advice

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    566

    Resolved [RESOLVED] struct definition advice

    My original project is in C#:

    Code:
    //C#:
    private struct udtCellInfo
    {
    	public int Row;
    	public int Col;
    	public short Style;			
    	public byte Attribute1;			
    	public string Text;			
    	public bool HasText;
    			
    }
    
    private struct udtCellStyle
    {	
            public Font Font;	
    	public Color ForeColor;
    	public Color BackColor;
    }
    
    private struct udtStyleCollection
    {
       public  udtCellStyle SelectionStyle;
       public  short StyleID;   
    }
    Now I am using C++ ATL, what is the closer definitions for Color, byte, string type
    and internal struct so that my code can be less changes?
    Note: some structs may save into binary file w/o lost unicode.

    Code:
    //C++:
    struct udtCellInfo
    {
    	int Row;
    	int Col;
    	short Style;			
    	char Attribute1; //char or BYTE???			
    	string Text;	//string or _bstr_t or LPCTSTR Or CString?		
    	bool HasText;
    			
    }
    
    struct udtCellStyle
    {	
    	HFONT Font; //HFONT  Or LOGFONT???
            COLORREF ForeColor; //COLORREF or OLE_COLOR???
    	COLORREF BackColor;
    }
    
    struct udtStyleCollection
    {
       udtCellStyle SelectionStyle; // udtCellStyle* SelectionStyle
       short StyleID;   
    }
    Last edited by DaveDavis; Apr 14th, 2023 at 11:39 PM.

  2. #2
    Banned
    Join Date
    Nov 2011
    Posts
    8,510

    Re: struct definition advice

    Use COLORREF for Color, not OLE_COLOR. OLR_COLOR is meant for COM and it comes with all kinds of weird semantics of it's own. Someone reading your code could mistakenly believe you actually want a COM OLE_COLOR and not just a plain old RGB colour value.

    HFont for Font is fine.

    For String, use you might want wchar_t* which is a pointer to a UTF-16LE Unicode buffer, the exact kind used in C# to support the String type.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    566

    Re: struct definition advice

    Quote Originally Posted by Niya View Post
    Use COLORREF for Color, not OLE_COLOR. OLR_COLOR is meant for COM and it comes with all kinds of weird semantics of it's own. Someone reading your code could mistakenly believe you actually want a COM OLE_COLOR and not just a plain old RGB colour value.
    All structures are used internal so they are not COM.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    566

    Re: struct definition advice

    Quote Originally Posted by Niya View Post
    For String, use you might want wchar_t* which is a pointer to a UTF-16LE Unicode buffer, the exact kind used in C# to support the String type.
    Can I use CString for easier operations, because those struct are used internally and not involve struct pack saving.

  5. #5
    Banned
    Join Date
    Nov 2011
    Posts
    8,510

    Re: struct definition advice

    Quote Originally Posted by DaveDavis View Post
    Can I use CString for easier operations, because those struct are used internally and not involve struct pack saving.
    Sure, why not.

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