|
It doesn't work.
If I guess,
I'd say myself that the error is in the starting of the form.h
What if the variables are always reset to 0?
What if the form, would be... in a repeatative process?
So where should I put the variable Tsn11 ?
|
|
|
|
|
Fenix2 wrote: It doesn't work.
What doesn't work?
You have statements of the form if (Tsn11 = 0) , which, as Luc pointed out are incorrect. The equality operator in C++ is == . Correct all your if statements and see what happens.
|
|
|
|
|
Yeah Thanks to all of you.
It works now.
|
|
|
|
|
Whats a natural successor to the COM object in the managed C++/CLI world?
I am migrating an app which has COM objects for no better reason that than is the only way I could get a form into a DLL to share between two exe's.
What should I be using in C++/CLI?
Ger
|
|
|
|
|
Ger Hayden wrote: What should I be using in C++/CLI?
It should be managed assemblies. You can pack windows forms in to assemblies(DLLs) which can be used with multiple applications. Create a Class Library project and add reference to System.Windows.Forms assembly.
|
|
|
|
|
I am migrating to Managed C++/CLI and .NET.
Previously I have used mysql++ with some difficutly.
Should I stick with it or move to ODBC or Connector/.NET?
Ger
|
|
|
|
|
In .NET, MySql connector is the best. It follows ADO.NET standards and provide a neat interface. Download from here[^].
|
|
|
|
|
Thanks. A few minutes to down load. Working example in less than half an hour....
Ger
|
|
|
|
|
How to divide a class into multi-files(like c# partial)?
I want to divide class MainForm into multi-files?
Could somebody tell me how do I achieve this goal?
namespace MyTools {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Globalization;
vector<MyData> m_MyData;
public ref class MainForm : public System::Windows::Forms::Form
{
|
|
|
|
|
akira32 wrote: How to divide a class into multi-files(like c# partial)?
C++ or C++/CLI already supports this. One header file and several source files is possible. You can have a MainFormUI.cpp which includes MainForm.h and have methods like InitializeComponent . Another source file say MainForm.cpp which has all other method implementations.
Unfortunately, VS designer won't support this kind of separation and it will always write the auto-generated code to MainForm.h.
|
|
|
|
|
A C# Partial Class is not equivalent to the C++ & C++/CLI header/source model. The following cannot not be done with C++ or C++/CLI in different (or in the same) files:
public partial class Employee
{
public void DoWork()
{
}
}
public partial class Employee
{
public void GoToLunch()
{
}
}
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
George L. Jackson wrote: A C# Partial Class is not equivalent to the C++ & C++/CLI header/source model.
I never said they are equal.
George L. Jackson wrote: The following cannot not be done with C++ or C++/CLI in different (or in the same) files:
Correct because it needs all the functions to be declared before using.
The question here is How to divide a class into multi-files(like c# partial)? and I believe C++'s header and multiple source files model is the answer. Please correct me if you feel it is wrong.
|
|
|
|
|
It depends on the point of view, just having multiple physical files or having both multiple physical files and the method of class construction. Yes, you can use multiple files (header/source) in C++ as you do in C#. However, the C# partial class is constructed more like a C++ class-namespace hybrid where you can define methods and data members in multiple source files that somehow come together in the scope of one class.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
ok i'm anoob in cli and i'm sure this quesiton has a simple answer ...but i'm new to managed code so...
what i wanna do is:
void mod_str(String ^bb) {
bb="bau";
}
void action() {
String ^str="ciao";
mod_str(str);
this->button1->Text=str;
}
what i wanna is that this button1 text became "bau" but with this code it remains "ciao"...
in c++ it wolud be something like...
void mod_str(string &str) {
str="bau";
}
void action() {
string str="ciao";
mod_str(str);
....
}
|
|
|
|
|
instead of
void mod_str(String ^bb) {
bb="bau";
}
use
void mod_str(String ^%bb) {
bb="bau";
}
EDIT:
This is a pretty good place to learn the keywords and operators specific to C++/CLI
http://msdn.microsoft.com/en-us/library/xey702bw.aspx[^]
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Thank you for this simple but important reply
|
|
|
|
|
Is it possible to create a DLL that exposes both a managed interface and a native one so that it can be used by both managed and native clients?
For instance, can it contain a managed class that wraps exported "C"-linkage functions, so that a managed client can see the managed class, and a native client can see the C-type functions?
|
|
|
|
|
Hi,
I'm not aware of any official solution, and I haven't tried it yet, however I got this[^] answer more than 2 years ago on a similar question of mine.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Thanks Luc. I think that it might be possible because I'm not trying to export any native classes, only native API's.
Thanks for digging up that old post, I appreciate it.
|
|
|
|
|
No problem.
If you have any results, please let us know.
TIA
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
This is possible using conditional compilation. You need to create managed and unmanaged methods in the header files separated with _MANAGED preprocessor symbol.
Consider the following code.
#ifdef _MANAGED
using System;
using System::Runtime::InteropServices;
#endif
#include <string>
class MixedAPI
{
public:
#ifdef _MANAGED
void TakeAString(gcroot<String^>); #else
void TakeAString(std::string); #endif
};
void MixedAPI::TakeAString(gcroot<String^> str)
{
}
void MixedAPI::TakeAString(std::string str)
{
}
|
|
|
|
|
So the library must be recompiled for managed or native?
|
|
|
|
|
Nope. Library should be compiled only once and it should be a mixed mode DLL (compiled using /clr ). Trick is with header files. When a native user uses your library, he will see only the methods defined for native. Other methods are not seen as those are guarded with _MANAGED preprocessor directive.
1 - You create the library with exported functions and managed wrapper functions. This should be compiled with /clr switch.
2 - Supply the library along with header file. Since header file has preprocessor statements, managed method definitions won't be seen by a native compiler. They still can work with native methods.
Since your DLL is mixed mode, all users require .NET framework to be installed of course.
|
|
|
|
|
- using visual studio 2008 -
what i have done so far is this:
a) i selected the file .lib and the .h and imported in my project -- done
b) i set in the project properties the linker to point to the lib file --done
c) i set in the project properties the c++ to look for the .h file --done
d) i set in the general project properties to compile using clr
e) my portion of code where i inlude the .h:
...
#pragma unmanaged
#include "database.h"
#pragma managed
...
f) i put a button in my form and onclick i initialize a class in the unmanaged class
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
try {
db::database db2;
}
catch (System::Exception ^exception) {
}
}
g) after that i compile and everything goes fine (i thinked "maybe too simple")
h) i run the application and ....tada error...
An unhandled exception of type 'System.TypeInitializationException' occurred in Unknown Module.
Additional information: The type initializer for '<Module>' threw an exception.
i googled around and i see is a common problem but i can't find an answer on what i have a todo...a magic code like #pragma something or some compiler settings or somethings....i neither find a good "howTo" on how to do this... can someone help me out or point me to a tutorial - how to ?? thx
modified on Thursday, October 1, 2009 8:02 AM
|
|
|
|
|
maybe the question was to general...i make a link where you can download my sample file with the problem. Th warnings are only because of my lib was for 'release' only. Hope someone can help me.
link
ps you need to correct the path of the linker to where you have the project to get the lib
ps2 maybe you need mysql do be installed on your pc with developer option to use because it use a mysql dll to run
or you have to put this dll in the project folder and you'll get it--download--
modified on Thursday, October 1, 2009 8:24 AM
|
|
|
|