Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / January 2007

Tip: Looking for answers? Try searching our database.

mixing managed and unmanaged c++ code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
frank - 22 Jan 2007 13:10 GMT
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
frank - 22 Jan 2007 20:19 GMT
frank napisał(a):
> Hi
>
[quoted text clipped - 5 lines]
> 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
Nathan Mates - 22 Jan 2007 20:58 GMT
>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

--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/ 
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein
frank - 22 Jan 2007 22:13 GMT
Nathan Mates napisał(a):
>> 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?

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[i][j] = Sca->vvout[i][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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.