Integrate C and C# Codes
-
Hi, I can current move the cursor to the position by doing in a c# application: Cursor.Position = new Point(Cursor.Position.X - 0, Cursor.Position.Y - 80); However, if i run the above codes in a C application, it will give errors. I am developing a C application which is compile and run by using visual studio.net 2005, i cannot add the "using System.Windows.Forms;" to the C application too. Is there any other method they can perform the above cursor.position function in a C application? A short sample of the coding: #include "cv.h" #include "highgui.h" #include #ifdef _EiC #define WIN32 #endif using namespace System::Windows::Forms; <--- when i try to add the namespace, the program have alot of error upon compilation static CvMemStorage* storage = 0; static CvHaarClassifierCascade* cascade = 0; void detect_and_draw( IplImage* image ); Errors Encounter: error C2061: syntax error : identifier 'namespace' error C2143: syntax error : ';' error C2143: syntax error : missing '{' before ':' error C2059: syntax error: ':' I can't figure out the problems behind. Can anyone help? Thanks Jas
-
Hi, I can current move the cursor to the position by doing in a c# application: Cursor.Position = new Point(Cursor.Position.X - 0, Cursor.Position.Y - 80); However, if i run the above codes in a C application, it will give errors. I am developing a C application which is compile and run by using visual studio.net 2005, i cannot add the "using System.Windows.Forms;" to the C application too. Is there any other method they can perform the above cursor.position function in a C application? A short sample of the coding: #include "cv.h" #include "highgui.h" #include #ifdef _EiC #define WIN32 #endif using namespace System::Windows::Forms; <--- when i try to add the namespace, the program have alot of error upon compilation static CvMemStorage* storage = 0; static CvHaarClassifierCascade* cascade = 0; void detect_and_draw( IplImage* image ); Errors Encounter: error C2061: syntax error : identifier 'namespace' error C2143: syntax error : ';' error C2143: syntax error : missing '{' before ':' error C2059: syntax error: ':' I can't figure out the problems behind. Can anyone help? Thanks Jas
-
Hi, I can current move the cursor to the position by doing in a c# application: Cursor.Position = new Point(Cursor.Position.X - 0, Cursor.Position.Y - 80); However, if i run the above codes in a C application, it will give errors. I am developing a C application which is compile and run by using visual studio.net 2005, i cannot add the "using System.Windows.Forms;" to the C application too. Is there any other method they can perform the above cursor.position function in a C application? A short sample of the coding: #include "cv.h" #include "highgui.h" #include #ifdef _EiC #define WIN32 #endif using namespace System::Windows::Forms; <--- when i try to add the namespace, the program have alot of error upon compilation static CvMemStorage* storage = 0; static CvHaarClassifierCascade* cascade = 0; void detect_and_draw( IplImage* image ); Errors Encounter: error C2061: syntax error : identifier 'namespace' error C2143: syntax error : ';' error C2143: syntax error : missing '{' before ':' error C2059: syntax error: ':' I can't figure out the problems behind. Can anyone help? Thanks Jas
if you want to set cursor position on C++ you can use
SetCursorPos
:)
WhiteSky
-
if you want to set cursor position on C++ you can use
SetCursorPos
:)
WhiteSky
Hi, I find out that we can use the user32.dll to control the cursor. Do you happen to know the difference between using the user32.dll and ::Cursor::Position? Do you think it is easier if i convert my c coding to c++ using the ::Cursor::Position or should i try to use the user32.dll with the c coding? I try to create a new C++ file with the following codes: SAMPLE CODING: #pragma once namespace yg { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: /// /// Clean up any resources being used. /// ~Form1() { if (components) { delete components; } } private: /// /// Required designer variable. /// System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// void InitializeComponent(void) { this->components = gcnew System::ComponentModel::Container(); this->Size = System::Drawing::Size(300,300); this->Text = L"Form1"; this->Padding = System::Windows::Forms::Padding(0); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; } #pragma endregion }; void MoveCursor() { ::Cursor::Position = Point(::Cursor::Position.X - 50,::Cursor::Position.Y - 50); } } Errors Encountered: error C3083: 'Cursor': the symbol to the left of a '::' must be a type c:\projects\yp\yg\yg\Form1.h 70 error C2039: 'Position' : is not a member of '`global namespace'' c:\projects\yp\yg\yg\Form1.h 70 error C2065: 'Position' : undeclared identifier c:\projects\yp\yg\yg\Form1.h 70 error C3083: 'Cursor': the symbol to the left of a '::' must be a type c:\projects\yp\yg\yg\Form1.h 70 error C2228: left of '.X' must have class/struct/union c:\projects\yp\yg\yg\Form1.h 70 error C3083: 'Cursor': the symbol to the left of a '::' must be a type c:\projects\yp\yg\yg\Form1.h 70 error C2228: left of '.Y' must have class/struct/union c:\projects\yp\yg\yg\Form1.h 70 Sorry for the trouble Thanks alot Jas
-
You can't use C# code in a C program. You can either wrap your C code into a dll and call it via
DllImport
from the C# project, or you might want to use C++/CLI. regardsHi, The C program is the main executable file, the codes in c# is the function i would like to call. Can i compile the C# into a dll and use it in the C program? As i have not use the VC++.net before, do you have any idea whats the difference between the MFC, Win 32 or window Form. I wish to build a GUI, and some of my frds mention that i can use the MFC as it has the auto drag and drop toolbox, but i found out recently that VC++ window form also has this properties. Sorry for the trouble thanks alot jas
-
Hi, The C program is the main executable file, the codes in c# is the function i would like to call. Can i compile the C# into a dll and use it in the C program? As i have not use the VC++.net before, do you have any idea whats the difference between the MFC, Win 32 or window Form. I wish to build a GUI, and some of my frds mention that i can use the MFC as it has the auto drag and drop toolbox, but i found out recently that VC++ window form also has this properties. Sorry for the trouble thanks alot jas
Cassiopeiaxy wrote:
The C program is the main executable file, the codes in c# is the function i would like to call. Can i compile the C# into a dll and use it in the C program?
You can compile the C# classes into a DLL, but you won't be able to call the DLL from your C program. It's a bit difficult, you might need to create a wrapper DLL written in C++/CLI that will convert your C# calls into C++/CLI ones. It'S a bit more involved, though, check out this article
Cassiopeiaxy wrote:
As i have not use the VC++.net before, do you have any idea whats the difference between the MFC, Win 32 or window Form.
Win32 - the oldest C++ sindowing API for Windows, pretty complicated to create complex windows MFC - Makes it easier to work with the Win32 API, you can drag-drop your windows with a designer in VC++ Windows.Forms - the new .NET approach, requires the .NET framework. Makes it very easy to create windows with the designer of VS .NET You have two choices: a) you still program in C++ and don't want the .NET framework: use MFC b) you program in .NET: use Windows.Forms regards
-
Hi, I find out that we can use the user32.dll to control the cursor. Do you happen to know the difference between using the user32.dll and ::Cursor::Position? Do you think it is easier if i convert my c coding to c++ using the ::Cursor::Position or should i try to use the user32.dll with the c coding? I try to create a new C++ file with the following codes: SAMPLE CODING: #pragma once namespace yg { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: /// /// Clean up any resources being used. /// ~Form1() { if (components) { delete components; } } private: /// /// Required designer variable. /// System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// void InitializeComponent(void) { this->components = gcnew System::ComponentModel::Container(); this->Size = System::Drawing::Size(300,300); this->Text = L"Form1"; this->Padding = System::Windows::Forms::Padding(0); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; } #pragma endregion }; void MoveCursor() { ::Cursor::Position = Point(::Cursor::Position.X - 50,::Cursor::Position.Y - 50); } } Errors Encountered: error C3083: 'Cursor': the symbol to the left of a '::' must be a type c:\projects\yp\yg\yg\Form1.h 70 error C2039: 'Position' : is not a member of '`global namespace'' c:\projects\yp\yg\yg\Form1.h 70 error C2065: 'Position' : undeclared identifier c:\projects\yp\yg\yg\Form1.h 70 error C3083: 'Cursor': the symbol to the left of a '::' must be a type c:\projects\yp\yg\yg\Form1.h 70 error C2228: left of '.X' must have class/struct/union c:\projects\yp\yg\yg\Form1.h 70 error C3083: 'Cursor': the symbol to the left of a '::' must be a type c:\projects\yp\yg\yg\Form1.h 70 error C2228: left of '.Y' must have class/struct/union c:\projects\yp\yg\yg\Form1.h 70 Sorry for the trouble Thanks alot Jas
What happens if you run this code
Cursor::Position = Point(Cursor::Position.X - 50,Cursor::Position.Y - 50);
WhiteSky