Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Adolfo.
  • Administrators
Posted

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?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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?

Adolfo.
Posted
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

Software bugs are impossible to detect by anybody except the end user.
Posted

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 uses

Imports System.Math

or 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.

Posted

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

Software bugs are impossible to detect by anybody except the end user.
Posted

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.

Nothing is as illusive as 'the last bug'.
Posted

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.

Posted
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.

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...