-
Apr 14th, 2023, 11:36 PM
#1
Thread Starter
Fanatic Member
[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.
-
Apr 15th, 2023, 12:03 AM
#2
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.
-
Apr 15th, 2023, 02:03 AM
#3
Thread Starter
Fanatic Member
Re: struct definition advice
 Originally Posted by Niya
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.
-
Apr 15th, 2023, 03:05 AM
#4
Thread Starter
Fanatic Member
Re: struct definition advice
 Originally Posted by Niya
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.
-
Apr 15th, 2023, 03:21 AM
#5
Re: struct definition advice
 Originally Posted by DaveDavis
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|