Click here to Skip to main content
15,892,768 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: Wrapper for CDialog class in C++/CLI dll Pin
led mike27-Mar-09 8:50
led mike27-Mar-09 8:50 
GeneralRe: Wrapper for CDialog class in C++/CLI dll Pin
Mark Salsbery27-Mar-09 8:55
Mark Salsbery27-Mar-09 8:55 
GeneralRe: Wrapper for CDialog class in C++/CLI dll Pin
Oldboy231-Mar-09 14:59
Oldboy231-Mar-09 14:59 
Questionshort cut key to a button ... Pin
m_mun25-Mar-09 23:09
m_mun25-Mar-09 23:09 
AnswerRe: short cut key to a button ... Pin
N a v a n e e t h25-Mar-09 23:32
N a v a n e e t h25-Mar-09 23:32 
Questionhelp with C++ Pin
mimikoyan25-Mar-09 18:15
mimikoyan25-Mar-09 18:15 
AnswerStop reposting your question you fraking monkey Pin
led mike26-Mar-09 4:42
led mike26-Mar-09 4:42 
QuestionCorrect handling of binary data defined in .h from a .Net perspective Pin
atzplzw25-Mar-09 9:02
atzplzw25-Mar-09 9:02 
I like to create an application which reads and writes data from a specific set of binary files. I choose C++/CLI because it’s easy to create a GUI with .Net but the file format is documented in c++ header files (.h).

File format is the following: Header, Header2, Data, Import, Export
Header is:
<br />
class fHeader {<br />
DWORD Id1;<br />
DWORD Id2;<br />
DWORD Id iSig;<br />
DWORD iCrc;<br />
DWORD iCompression;<br />
DWORD iFlags;<br />
LWORD iDataSize;<br />
DWORD iImportSize;<br />
DWORD iExportSize;<br />
}<br />

My idea is the following:
MBinaryFile::MBinaryFile(String^ name)<br />
{<br />
	this->FileName = name;<br />
<br />
	OriginalFileHeader = gcnew array<Byte>(sizeof(fHeader));<br />
<br />
FileStream^ fs = gcnew FileStream(this->FileName, FileMode::Open, <br />
FileAccess::Read);<br />
<br />
BinaryReader^ br = gcnew BinaryReader(fs);<br />
OriginalFileHeader = br->ReadBytes(OriginalFileHeader->Length);<br />
<br />
	//convert it to C++<br />
pin_ptr<Byte> pHeader = &OriginalFileHeader[0];<br />
	fHeader* iOrigHdr = reinterpret_cast<fHeader*>(pHeader);<br />
<br />
//read other sections...<br />
	Data = gcnew array<Byte>(iOrigHdr->iDataSize);<br />
	Data = br->ReadBytes(Data->Length);<br />
}<br />


The problem with this approach is that every time I need to change the header I have to convert it to C++ as the pin_ptr is not able to be used as a class variable.
<br />
MBinaryFile::ChangeFlags(DWORD newFlags)<br />
{<br />
	//convert it to C++<br />
pin_ptr<Byte> pHeader = &OriginalFileHeader[0];<br />
	fHeader* iOrigHdr = reinterpret_cast<fHeader*>(pHeader);<br />
<br />
	iOrigHdr->iFlags = newFlags;	<br />
}<br />

Creating the Header as a .Net class would be another option but I also need that to work for Header2. Header2 is a much larger C++ class with inline functions so I don’t want to convert all of the members and (inline) methods.

Is pin_ptr the way to go or is there a better way to deal with this problem?

Thanks for your help!
AnswerRe: Correct handling of binary data defined in .h from a .Net perspective Pin
led mike25-Mar-09 9:47
led mike25-Mar-09 9:47 
Questionlistbox not visible in thread Pin
Thilek25-Mar-09 6:53
Thilek25-Mar-09 6:53 
AnswerRe: listbox not visible in thread Pin
Thilek25-Mar-09 9:09
Thilek25-Mar-09 9:09 
Questionhelp with C++ pragraming Pin
mimikoyan25-Mar-09 0:56
mimikoyan25-Mar-09 0:56 
QuestionForm refresh... and accept click on button while performing other task... Pin
Thilek24-Mar-09 23:31
Thilek24-Mar-09 23:31 
AnswerRe: Form refresh... and accept click on button while performing other task... Pin
N a v a n e e t h25-Mar-09 1:14
N a v a n e e t h25-Mar-09 1:14 
AnswerRe: Form refresh... and accept click on button while performing other task... Pin
erfi25-Mar-09 2:10
erfi25-Mar-09 2:10 
GeneralRe: Form refresh... and accept click on button while performing other task... Pin
Thilek25-Mar-09 3:29
Thilek25-Mar-09 3:29 
GeneralRe: Form refresh... and accept click on button while performing other task... Pin
Thilek25-Mar-09 4:04
Thilek25-Mar-09 4:04 
GeneralRe: Form refresh... and accept click on button while performing other task... [modified] Pin
erfi25-Mar-09 11:21
erfi25-Mar-09 11:21 
QuestionProblem calling C++ DLL from Excel Pin
gvanto24-Mar-09 16:12
gvanto24-Mar-09 16:12 
QuestionDebug Assertion failed error while using an mfc dll via import library in an managed console application Pin
Muhammad.Ahmad.Malik24-Mar-09 10:02
professionalMuhammad.Ahmad.Malik24-Mar-09 10:02 
QuestionRe: Debug Assertion failed error while using an mfc dll via import library in an managed console application Pin
paxal31-Mar-09 4:02
paxal31-Mar-09 4:02 
AnswerRe: Debug Assertion failed error while using an mfc dll via import library in an managed console application Pin
Muhammad.Ahmad.Malik31-Mar-09 6:55
professionalMuhammad.Ahmad.Malik31-Mar-09 6:55 
QuestionCircular Form Reference Pin
thenutz7224-Mar-09 4:28
thenutz7224-Mar-09 4:28 
AnswerRe: Circular Form Reference [modified] Pin
led mike24-Mar-09 5:20
led mike24-Mar-09 5:20 
GeneralRe: Circular Form Reference Pin
thenutz7224-Mar-09 5:47
thenutz7224-Mar-09 5:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.