Click to See Complete Forum and Search --> : Passing String in function issue


jipeval
August 1st, 2005, 05:50 PM
Hello,
I am new to managed C++ and I am trying to figure out how to pass a String in a function member of a managed object:
Here is my code:

private: System::Void menuItem4_Click(System::Object * sender, System::EventArgs * e)
{
// INITIATE
CCG *BCG=new CCG();
String* STR;
if( this->openFileDialog1->ShowDialog() == DialogResult::Cancel )
{
MessageBox::Show(S"No file loaded.");
}
STR=this->openFileDialog1->get_FileName();
BCG->Read_E(STR,10,400);
}

Read_E is defined as follow in .h file:
public __gc class CCG
{
public:
void Read_E(String *FileName, long lStart, long lDataLenght);
CCG(void);
~CCG(void);

}
in my .cpp file:
void CCG::Read_E(String *strFileName, long lStart, long lDataLenght)
{......}


The code debugs fine but the strFilename is out of scope in my CCG::Read_E....

I spent a lot of time trying to figure this out.. if someone could help me understanding why my strFileName becomes out of scope ...

unmanaged JP...

NoHero
August 2nd, 2005, 04:10 AM
What do you mean with: "It goes out of scope"? It shall not go out of scope... Try to Copy() the string.

Best Regards,
Florian

jipeval
August 2nd, 2005, 02:29 PM
That was helpful....

actually the passed string pointer was working fine I could copy the string but somehow I could not see the content of the string in the Watch window... strFileName was refered as out of scope.(which does not make sense)
... must be an issue with this feature of the .net studio.
I wrote another similar function in the same class and it was working fine ...
still, I do not understand what went wrong on this previous function!