carpe2 Posted April 14, 2004 Posted April 14, 2004 Hi, i have to do some code in c# and i only know managed c++ so i dont know how can i do the next in order to use functions of other class... #include "Validar.h" ... ... Validar *pValidar; pValidar=new Validar(); .... pValidar->Functions(); ... Thanks. Quote Adolfo.
joe_pool_is Posted April 14, 2004 Posted April 14, 2004 If possible, could someone include how to accomplish this in VB.NET as well? Quote Avoid Sears Home Improvement
Administrators PlausiblyDamp Posted April 14, 2004 Administrators Posted April 14, 2004 Header files aren't supported in C# (or VB.Net). If the original class is C++ you could create a manged wrapper class and compile this into a DLL and reference that dll from your application. Alternatively you would have to create a standard DLL that exposes the relevant functionalty and call this through P/Invoke. Out of interest what does the class do? There may be a replacement / viable alternative in the .Net framework? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
carpe2 Posted April 14, 2004 Author Posted April 14, 2004 I meant when i create the class clicking the right button of the mouse adding a new one (in c#)inside the solution explorer... How can i access to the functions in that class? Quote Adolfo.
Administrators PlausiblyDamp Posted April 14, 2004 Administrators Posted April 14, 2004 Just declare a variable of the same type as the class. There is no need to include anything. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
AlexCode Posted April 15, 2004 Posted April 15, 2004 Header files aren't supported in C# (or VB.Net). If the original class is C++ you could create a manged wrapper class and compile this into a DLL and reference that dll from your application. Alternatively you would have to create a standard DLL that exposes the relevant functionalty and call this through P/Invoke. Out of interest what does the class do? There may be a replacement / viable alternative in the .Net framework? Just curious... (as I don't understant absolutly nothing of c++) What do you mean by "Header files" ??? Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
joe_pool_is Posted April 15, 2004 Posted April 15, 2004 Header files are external to your program. Typically, these files will include definitions for many, many variables of something that you want to work with. The best analogy I can think of is the way .NET usesImports System.Mathor something like that. You don't have to worry about defining PI all over again. For me, I am working with some OpenGL components, and there are tons of examples out there referencing header files written in C or C++. A few sites have created applications that will run OpenGL in .NET, but I still want to know how to include a header file. Quote Avoid Sears Home Improvement
AlexCode Posted April 15, 2004 Posted April 15, 2004 If that's it then PlausiblyDamp's suggestion will work as a charm wont it? I think that aside to the dll wraping you must think .net way too... Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
Wile Posted April 15, 2004 Posted April 15, 2004 For me, I am working with some OpenGL components, and there are tons of examples out there referencing header files written in C or C++. A few sites have created applications that will run OpenGL in .NET, but I still want to know how to include a header file. Where in c++ you have to manually include every header you want to use in that file (or through the precompiled header or some other file that has several include statements) you dont have to do that in C#. The only thing that comes close to the #include statement, is the namespace. Basicly everything within the same namespaces is known (after taking scope like public/proteced/private in consideration) to each other. To use objects / methods / .. from another namespace you can either indicate you use that namespace (using <namespace> in c#, #imports <namespace> in vb as joe_pool_is shows) or use the full name. For instance to display a messagebox. In c++ you would have to add the correct headers (well, use the wizard to create an mfc app and you'd get them ;) ). In c# you have to set a reference to the System.Windows.Forms library to be able to use the messagebox (or select the default application and the wizard does that for you ;) ). To show the messagebox you can eiter use: System.Windows.Forms.MessageBox.Show(blaat); or at the start of the .cs file using System.Windows.Forms; and in your method: MessageBox.Show(blaat); So if you want to convert the header files into something you can use in .net, you would have to put them all in a regular file (.cs for c#). For easier navigation you can use a seperate namespace in this file. E.g. namespace MyApp.MyDefinitions. The constants defined in the file will now be grouped in the MyDefinitions namespace, making it a bit easier to navigate ;). Even better would be to use enumerations, but that would probably take a lot more time. Quote Nothing is as illusive as 'the last bug'.
Engine252 Posted April 16, 2004 Posted April 16, 2004 it is not possible to include header files in a vb or c# project however you can create a c++.net library and then make a reference to that project from your project you are working on. Quote
joe_pool_is Posted April 17, 2004 Posted April 17, 2004 it is not possible to include header files in a vb or c# project however you can create a c++.net library and then make a reference to that project from your project you are working on. If you get a moment, could you show a newbie like me how to do something like that? That would come in very helpful with some of the projects I am working on. Quote Avoid Sears Home Improvement
Engine252 Posted April 17, 2004 Posted April 17, 2004 in vs.net it is possible to add references using the ide.(no code needed) in the project explorer richt click on your project and click add reference. then pick the projects tab and the select your c++.net project witch should be in the same solution of course hope it helps. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.