Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / March 2006

Tip: Looking for answers? Try searching our database.

calling c++ function from c#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SeanGerman@gmail.com - 17 Mar 2006 23:18 GMT
Howdy,

I've worked through the few threads on this issue in the group archives
but still not quite getting where i need to be.  Other than whacking
around some MUD code a few years ago, this is my first time with C++.

Working in VS.net 2k3, my solution has a C# project and a C++ project.
In C++ I have a public function in a class exported from the project
dll.

In the VS class view, I have
cppProject
|--{}cppNamespace
   |--cppClass
      |--cppFunction
and I added cppProject.dll to the C# project references.  In my C#, I
type "cppNamespace." and intellisense will list the cppClass.  I figure
that's a good sign.

So again in C#, I have "cppClass myClass = new cppClass();" but that's
a far as I get.  There's doesn't seem to be any recognition of
cppFunction in cppClass.  I get a lot of "'cppNamespace.cppClass' does
not contain a reference for 'cppFunction'" errors.

Any thoughts on what I'm missing?  All suggestions most appreciated.

TIA,

Sean G
scottelloco@gmail.com - 18 Mar 2006 00:36 GMT
Sean,

First, your function in your C++ app will need to be a "C" function.
You can place the decorated name in the header for your C++ class. For
example:

extern "C"
{
       CEDB_API bool LoadProcedure();

}

Is the C++ project a dll? If so, then you'll need to add a dll imfort
for each function you want to call in your C++ dll., like this:

[DllImport("CedbXml", CharSet = CharSet.Auto)]
       public static extern bool LoadProcedure();

Let say you place your DllImport statement in a C# class called
CppApi... you'll then be able to call your C++ function liek so:

bool result = CppApi.LoadProcedure();
SeanGerman@gmail.com - 20 Mar 2006 23:21 GMT
Thank you!  Exactly what I was looking for.

I had to specify an EntryPoint, but then it was off and running.

Thanks again,

Sean G.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.