mixing managed and unmanaged c++ code

F

frank

Hi

I've got aplication, which one is written in unmanaged c++ with stl,
i've made for it gui in managed c++.
Problem becomes when I'm starting to filling up for example datagrids,
when I'm adding row to datagrid , some varibles (vectors etc) in
unmanaged class are cleared or filled with null.
I want mention also when i compile only unmanaged class for console
project (without .net gui) problem never happends, everything works fine.

I've done all like in msdn example

ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vclang/html/f072ddcc-e1ec-408a-8ce1-326ddb60e4a4.htm

my program structure looks like that

main.cpp

// gui.cpp : main project file.

#pragma managed(push, off)

#include "source\main.h"
....
#include "source\nfile.h"
#include "source\fun08.h"
....
static SCA Sca; //< --- thats my unmanaged class

#pragma managed(pop)
#include "source\guiTabPageFUN.h"
#include "source\guiTabPageN.h"
....
#include "Form1.h"

using namespace GuiNameSpace;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

Application::Run(gcnew Form1(&Sca));
return 0;
}


//nfile.h:some unmanaged file

#pragma managed(push, off)

class N
{
.....int z;
}

#pragma managed(pop)

//nfile.cpp:some unmanaged file

#pragma managed(push, off)
...some functions body..
N::N()
{
int z=0;
}
#pragma managed(pop)



Is there any way to fix the problem ?

Regards
frank
 
F

frank

frank napisa³(a):
Hi

I've got aplication, which one is written in unmanaged c++ with stl,
i've made for it gui in managed c++.
Problem becomes when I'm starting to filling up for example datagrids,
when I'm adding row to datagrid , some varibles (vectors etc) in
unmanaged class are cleared or filled with null.
I want mention also when i compile only unmanaged class for console
project (without .net gui) problem never happends, everything works fine.

nobody can help me?

Regards
frank
 
N

Nathan Mates

nobody can help me?

You waited about 7 hours between postings. How about a little
patience? How about providing a lot more detail as to what you're
doing?

Nathan Mates
 
F

frank

Nathan Mates napisa³(a):
You waited about 7 hours between postings. How about a little
patience? How about providing a lot more detail as to what you're
doing?

ok i'll wait :D

and the details
in umanaged code i have many classes like

Pseudo code
//nf.h

class nf
{
integers
vectors
void somefunctions()
}

//nf.cpp
#pragma managed(push, off)
#include "main.h"
#include "nf.h"

void nf::somefunctions()
{
//doing some operations on vector
//and setting integers
}

#pragma managed(pop)

and all of them are used by

//SCA.h
class SCA
{
set()
get()
public:
vector<nf> vnf;
vector<vector<int>> vvout;
int makesth()
}

//SCA.cpp
#pragma managed(push, off)
#include "main.h"
#incldue "sca.h"

void SCA::makesth()
{
vnf.push_back(somecountedvalue);
return;
}

#pragma managed(pop)

in managed code i'm forwarding pointer to SCA (main unmanage class)
and then only read public values or execute functions form unmanaged
class SCA

my MAIN manage file looks like that

// gui.cpp : main project file.
#pragma managed(push, off)

#include "source\main.h"
....
#include "source\nfile.h"
#include "source\fun08.h"
....
static SCA Sca; //< --- thats my unmanaged class

#pragma managed(pop)
#include "source\guiTabPageFUN.h"
#include "source\guiTabPageN.h"
....
#include "Form1.h"

using namespace GuiNameSpace;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew Form1(&Sca));
return 0;
}


everything compiles without errors,
problem shows when i'm trying to fill datagrid or makeing some new
dynamic tabs on tabcotrol.
One by one it looks like that

user is pressing some button,
then class SCA if filling vectors with some large data and sets some
varibles , till that moment everything is ok ( all varibles have good
values, and vectors are filled up ) , I've checked with debuger

next step is refreshing forms (unmanaged code).
Form refreshing function use pointer on class SCA to get values, for
example

while(datagridview->rows->count!=Sca->vvout.size())
{
datagridview->rows->add(1);
datagridview->rows->cell[j] = Sca->vvout[j];
}

and when something like that is done (datagrid adds rows or tabcontrol
gets new dynamic created tabs), some values in my class SCA are filled
with null and some vectors are cleared.

Where can be bug, am I doing something wrong?


Regards
frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top