C# include

Hello, it's possible to include header file in Visual C# Form application? For example i have code (on bottom of this text) and i want use it in my code, how can i do this? I need copy full function and use it in program? :/ Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
static long aktualnyCasTimestamp()
{
	time_t t = time(NULL);
	struct tm * now = localtime(&t);

	struct tm t1;
	time_t t_of_day;

	int rok;
	int mesiac;
	int den;
	int hodina;
	int minuta;
	int sekunda;

	rok = now->tm_year;
	mesiac = now->tm_mon;
	den = now->tm_mday;
	hodina = now->tm_hour;
	minuta = now->tm_min;
	sekunda = now->tm_sec;

	t1.tm_year = rok;
	t1.tm_mon = mesiac;
	t1.tm_mday = den;
	t1.tm_hour = hodina;
	t1.tm_min = minuta;
	t1.tm_sec = sekunda;
	t1.tm_isdst = -1;


	t_of_day = mktime(&t1);
	return t_of_day;
}
and second question, i have public void FunctionName() in my Form1, when i include in Form2 code
1
2
Form1 form1 = new Form1();
form1.FunctionName();

then nothing happend. When i put messageboxshow in function, i see message, but when for example i want change label or textbox text, then nothing. What i do wrong? THanks :)
1. question
No you can't include native C++ code in C#.

2. question
Try to show form1 first.

Hello, it's possible to include header file in Visual C# Form application?
No, you can however exchange data with StructLayoutAttribute, see:

https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.structlayoutattribute.aspx
I think (from limited experience) that you can wrap the native c++ code in a managed class, (ie ref class MyClass ...) and return result through a managed method or managed functor. This managed wrapper should be made into a dll/assembly that can be include in the c# project.
Hello, thanks for answers,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
namespace SrcdsConfigTool
{
	public partial class Form1 : DevExpress.XtraBars.Ribbon.RibbonForm
	{
		public Form1()
		{
			InitializeComponent();
		}

		class Datapacket
		{
			public string m_Output;
		}

		public void StartWorker(string installDir, string appId)
		{
			label1.Text = installDir + appId;
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			if (!File.Exists("configData"))
			{
				SQLiteConnection.CreateFile("configData");
				//SQLiteConnection m_Connection = new SQLiteConnection("Data Source=configData;Version=3;");
				SQLiteConnection m_Connection = sqLiteConnection1;
				m_Connection.Open();
				string con = "CREATE TABLE config (name varchar(20), string varchar(100))";
				SQLiteCommand command = new SQLiteCommand(con, m_Connection);
				command.ExecuteNonQuery();
				con = "INSERT INTO config(name,string) VALUES('steamcmdpath', '<pathToSteamCMD.exe>')";
				command.CommandText = con;
				command.ExecuteNonQuery();
			}
			else
			{
				//SQLiteConnection m_Connection = new SQLiteConnection("Data Source=configData;Version=3;");
				SQLiteConnection m_Connection = sqLiteConnection1;
				m_Connection.Open();
				string con = "SELECT * FROM config WHERE name='steamcmdpath'";
				SQLiteCommand command = new SQLiteCommand(con, m_Connection);
				SQLiteDataReader reader;
				reader = command.ExecuteReader();
				while (reader.Read())
				{
					label_steamcmdLocation.Text = reader.GetString(1);
				}
				reader.Close();
			}
		}

		private void button_steamcmdLocation_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{


and this is form2 where i call function from form1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace SrcdsConfigTool
{
	public partial class InstallServer : DevExpress.XtraBars.Ribbon.RibbonForm
	{
		public InstallServer()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			string path;
			folderBrowserDialog_installDir.ShowDialog();
			if (folderBrowserDialog_installDir.SelectedPath == "NoDir")
			{
				MessageBox.Show("No Dir selected, aborting");
				return;
			}
			path = folderBrowserDialog_installDir.SelectedPath;
			label_installDir.Text = path;
			
			InstallServer form2 = new InstallServer();
			form2.StartWorker(path, textbox_appid.Text);
		}

		private void button2_Click(object sender, EventArgs e)
		{
			
		}
	}
}
Topic archived. No new replies allowed.