473,856 Members | 1,704 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 4706
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
2886
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 if there are any "references" in the project, IDE adds /FU switch with each of these references to...
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 created 2 unmanaged classes which handled the calls to the static lib (btw all the code works fine in...
4
1694
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
1271
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
2284
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
4448
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
2192
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 unmanaged class for console project (without .net gui) problem never happends, everything works fine.
2
16868
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
12372
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 mode driver and I want to use it from my C# program. Because it requires some setup outside the...
0
9904
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9758
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11049
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10692
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10378
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7928
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7086
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5956
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3195
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.