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

Managed C++/CLI

 
GeneralCoversion between managed and unmanaged type Pin
hatemtaleb23-Apr-08 2:53
hatemtaleb23-Apr-08 2:53 
GeneralRe: Coversion between managed and unmanaged type Pin
hatemtaleb23-Apr-08 3:17
hatemtaleb23-Apr-08 3:17 
QuestionFile Open? Pin
ritz123421-Apr-08 23:15
ritz123421-Apr-08 23:15 
Questionhow to open ports using c++ Pin
ankur010121-Apr-08 7:25
ankur010121-Apr-08 7:25 
AnswerRe: how to open ports using c++ Pin
Mark Salsbery21-Apr-08 21:12
Mark Salsbery21-Apr-08 21:12 
QuestionDid the test succeed Pin
led mike23-Apr-08 9:18
led mike23-Apr-08 9:18 
AnswerRe: how to open ports using c++ Pin
ivanmen23-Apr-08 7:11
ivanmen23-Apr-08 7:11 
QuestionBinaryStream issues with native classes Pin
Xpnctoc21-Apr-08 3:46
Xpnctoc21-Apr-08 3:46 
I encountered an absolutely insane problem with BinaryStream I/O of native classes that I was wondering if someone could shed some light on. I do have a work-around, but the whole thing just doesn't make any sense to me...

First, I have a class, "CMyBinaryIO" to handle the streaming. The Save(IntPtr myData, int iSize) method takes 2 params: an IntPtr to the data, and a integer to indicate the expected byte size. I use Marshal::Copy(...) to copy the structue into an array of bytes, and then pass that array to the BinaryStream::Write(...) method. Simple enough.

OK. Now the dirt... Consider the following, simple code snippets:

<br />
UMyParent<br />
{<br />
public:<br />
    int iParentA, iParentB;<br />
};<br />
<br />
UMyHelper<br />
{<br />
public:<br />
    int iHelpA, iHelpB;<br />
};<br />
<br />
UMyChild : public UMyParent<br />
{<br />
public:<br />
    int iChildA, iChildB;<br />
    UMyHelper uChildHelp;<br />
};<br />


If UMyChild has a Save() method that does this...

<br />
CMyBinaryIO::Save((IntPtr)this, sizeof(UMyChild));<br />


...it works. I can do a similar read operation and retrieve all the data properly. HOWEVER, I cannot read/write the binary file in any environment other than the one it was created in. In other words, if I was running the application through the IDE, I cannot read the file by running the EXE directly!!! If I create a file by running the app directly, I can't even read the file by running the exe directly on a different computer!!!

To be specific, if I created the file running through the IDE and I try to read the file by direct execution, the program acts like it read the data just fine. However, when I try to invoke any other method in the UMyChild class (maybe pChildInstance->DoSomething()), I instantly get a crash with a nice message that says something about not being able to access memory, and that the memory is possibly corrupt.

Now, here's the real confusing part. If I do this in the UMyChild::Save() method...

<br />
CMyBinaryIO::Save((IntPtr)&iParentA, sizeof(int));<br />
CMyBinaryIO::Save((IntPtr)&iParentB, sizeof(int));<br />
CMyBinaryIO::Save((IntPtr)&iChildA, sizeof(int));<br />
CMyBinaryIO::Save((IntPtr)&iChildB, sizeof(int));<br />
CMyBinaryIO::Save((IntPtr)&uChildHelp, sizeof(UMyHelper));<br />


...the the file can be created and re-read on ANY machine, and is completely cross-compatible between IDE and "live" execution. And when I call pChildInstance->DoSomething(), I don't get the corrupted memory messages!!!

I thought it might have something to do with .NET trying to write complex unmanaged types. But look closely at the code... The app does not require the UMyHelper members to be written one field at a time. The "uChildHelp" member can still be written as one chunk of data.

Does anyone have any ideas on how this could possibly be? Thank God I can at least do the single-member read/write to get around the issue, but it doesn't seem like I should have to. Why can't I pass the "this" member with the appropriate size calculation of the inherited class with all its members?

Thanks.
AnswerRe: BinaryStream issues with native classes Pin
led mike21-Apr-08 5:58
led mike21-Apr-08 5:58 
GeneralRe: BinaryStream issues with native classes Pin
Xpnctoc21-Apr-08 6:22
Xpnctoc21-Apr-08 6:22 
GeneralRe: BinaryStream issues with native classes Pin
led mike21-Apr-08 10:10
led mike21-Apr-08 10:10 
GeneralProblem redistributing C++/CLR App Pin
uusheikh20-Apr-08 22:29
uusheikh20-Apr-08 22:29 
GeneralRe: Problem redistributing C++/CLR App Pin
Christian Graus22-Apr-08 12:29
protectorChristian Graus22-Apr-08 12:29 
QuestionLinker error 2028 and 2019 Pin
raydona17-Apr-08 2:00
raydona17-Apr-08 2:00 
AnswerRe: Linker error 2028 and 2019 Pin
led mike17-Apr-08 4:34
led mike17-Apr-08 4:34 
GeneralInstall QT4 Pin
phokojoe16-Apr-08 23:51
phokojoe16-Apr-08 23:51 
GeneralCreating an installer Pin
BuckBrown15-Apr-08 8:09
BuckBrown15-Apr-08 8:09 
GeneralRe: Creating an installer Pin
led mike15-Apr-08 10:32
led mike15-Apr-08 10:32 
GeneralRe: Creating an installer Pin
BuckBrown15-Apr-08 12:04
BuckBrown15-Apr-08 12:04 
GeneralRe: Creating an installer Pin
Jonathan [Darka]15-Apr-08 21:17
professionalJonathan [Darka]15-Apr-08 21:17 
QuestionCalling MeasureString from VC++ 2005 Pin
Soumyadipta15-Apr-08 1:07
Soumyadipta15-Apr-08 1:07 
QuestionRe: Calling MeasureString from VC++ 2005 Pin
Christian Graus15-Apr-08 1:29
protectorChristian Graus15-Apr-08 1:29 
GeneralRe: Calling MeasureString from VC++ 2005 Pin
Soumyadipta15-Apr-08 1:50
Soumyadipta15-Apr-08 1:50 
GeneralRe: Calling MeasureString from VC++ 2005 Pin
Christian Graus15-Apr-08 1:56
protectorChristian Graus15-Apr-08 1:56 
GeneralRe: Calling MeasureString from VC++ 2005 Pin
Soumyadipta15-Apr-08 19:15
Soumyadipta15-Apr-08 19:15 

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.