473,569 Members | 2,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mixing managed and unmanaged c++ code

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.ht m

my program structure looks like that

main.cpp

// gui.cpp : main project file.

#pragma managed(push, off)

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

#pragma managed(pop)
#include "source\guiTabP ageFUN.h"
#include "source\guiTabP ageN.h"
....
#include "Form1.h"

using namespace GuiNameSpace;

[STAThreadAttrib ute]
int main(array<Syst em::String ^^args)
{
Application::En ableVisualStyle s();
Application::Se tCompatibleText RenderingDefaul t(false);

Application::Ru n(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
Jan 22 '07 #1
3 4693
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
Jan 22 '07 #2
In article <ep**********@n emesis.news.tpi .pl>,
frank <fr***@niemamai la.comwrote:
>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
Jan 22 '07 #3
Nathan Mates napisa³(a):
In article <ep**********@n emesis.news.tpi .pl>,
frank <fr***@niemamai la.comwrote:
>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::somefunctio ns()
{
//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<nfvnf;
vector<vector<i nt>vvout;
int makesth()
}

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

void SCA::makesth()
{
vnf.push_back(s omecountedvalue );
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\mai n.h"
....
#include "source\nfile.h "
#include "source\fun08.h "
....
static SCA Sca; //< --- thats my unmanaged class

#pragma managed(pop)
#include "source\guiTabP ageFUN.h"
#include "source\guiTabP ageN.h"
....
#include "Form1.h"

using namespace GuiNameSpace;

[STAThreadAttrib ute]
int main(array<Syst em::String ^^args)
{
Application::En ableVisualStyle s();
Application::Se tCompatibleText RenderingDefaul t(false);
Application::Ru n(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(datagridv iew->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

Jan 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2812
by: kaalus | last post by:
Hello I have problem mixing managed and unmanaged C++ code in VS.NET 2003. I want to create a windows forms application which uses some C++ code that is incompatible with managed extensions (__fastcall etc.). I have tried disabling "compile as managed" option for these specific files, but it does not help: by trial and error I figured out that...
2
489
by: Neil | last post by:
I am developing a demo in C# using Managed DirectX. I wanted to use a C++ static library in the demo (its a class for handling physics), so I decided to create my Graphics classes in C#, inherit from them in MC++. So far so good...... I modified my MC++ project to run as mixed mode (removed nochkclr.obj, added msvcrt.lib, etc etc), and...
4
1684
by: Daniel Lidström | last post by:
Hello, is it possible to ``use CS to code a class, and (M)C++ for the logic''? Sorry if this sounds vague, I'm not really sure myself what it means. Does anyone have any ideas? -- Daniel
1
1255
by: Steve Marsden | last post by:
Hi All the information I had read suggested that if you had an existing C project that you wished to change to managed code all you had to do was use the /clr switch and then over time you could convert/add managed code bit by bit. I have done this on my large C project and all compiles and links OK. So far so good.
13
2239
by: DD | last post by:
I'm puzzled how to mix managed/unmanaged C++ in the following scenario: Unmanaged ------------ Callback listener class with method that should call an event in managed Form1. Initialization code for the listener that launches the listener thread. Managed ----------
2
4434
by: quat | last post by:
I am getting the error: error C4368: cannot define 'd3dPP' as a member of managed 'FormEx::Form1': mixed types are not supported I am trying to mixed managed and unmanaged code (d3dPP is unmanaged, where the form is managed). Can I not have an unmanaged instance in a managed class?
3
2176
by: frank | last post by:
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...
2
16841
by: jraul | last post by:
Hi, This is probably a noobie question but: I just created a new C++/CLI project in VS 2005. It created an empty class: public ref class Class1 { // TODO: Add your methods for this class here.
2
12350
by: Jon Slaughter | last post by:
How difficult is it for one to integrate unmanaged C++ into C#? I know for functions one can use DLLimport but how does one go about doing it for classes? Do I have to completely reimplement the classes in managed C++ as a wrapper to the unmanaged C++ classes or is there an easier way? Essentially what I have done is written a C++ kernel...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.