[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Calling C functions from C#

Posted on 2004-11-24
8
Medium Priority
?
217 Views
Last Modified: 2010-05-18
Well, as you can see I'm a first timer...
how do i call a C function from a C# class?
can it be done in the same project or do I need to reside the C code in a Lib?
a simple example will be appreciated.
Thanks!
0
Comment
Question by:udibs
5 Comments
 
LVL 8

Accepted Solution

by:
Razzie_ earned 100 total points
ID: 12663160
You will need to use DLLImport, for example:

[DllImport("MyDLL")] // or the complete dll path
public static extern string MyMethod(int x);

and then you can simply use that function in your code:

string s = MyMethod(55);

HTH,

Razzie
0
 

Author Comment

by:udibs
ID: 12663276
Must I use a DLL or can I use a static lib?
0
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 100 total points
ID: 12663370
C# doesn't work with static libraries. PInvoke requires Dll.
0
 
LVL 8

Expert Comment

by:tomvergote
ID: 12663856
right now you'll have to either use a dll or add a c and a c# project to your solution and reference one from the other (which results in a dynamically loaded dll behind the scenes).

In vs2k5 you'll have the ability to mix code files from different languages in a single project
http://blogs.msdn.com/frankpr/archive/2004/07/27/198918.aspx
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question