473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Calling c# from c

Hi All,

Is it possible to export a c# method into a dll in such a way that your
"normal" C application can then call this method?

To be clear: I am not asking how to use "DllImport" or PInvoke. My
question is the other way around.

Regards
Pieter Breed

Jul 21 '05 #1
2 3196
"pi**********@gmail.com" <pi**********@gmail.com> wrote:
Hi All,

Is it possible to export a c# method into a dll in such a way that your
"normal" C application can then call this method?

To be clear: I am not asking how to use "DllImport" or PInvoke. My
question is the other way around.

Regards
Pieter Breed


I'm afraid the simple answer is no.

UNLESS you are willing to have COM invade your C application
and aren't afraid to manipulate the COM interfaces exposed
by the COM Callable wrapper (CCW; created with Regasm.exe)
manually.

Not pretty...

NET Framework Tools Assembly Registration Tool (Regasm.exe)
http://msdn.microsoft.com/library/de...lregasmexe.asp

..NET Framework Developer's Guide Registering Assemblies
with COM
http://msdn.microsoft.com/library/de...ieswithcom.asp

..NET Framework Developer's Guide: Exposing .NET Framework
Components to COM
http://msdn.microsoft.com/library/de...nentstocom.asp
If your going down that road you may want to invest in:

COM and .NET Interoperability
by Andrew Troelsen
769 pages
Apress; 1st edition (April 20, 2002)
ISBN: 1590590112
http://www.amazon.com/exec/obidos/ASIN/1590590112
http://www.apress.com/book/bookDisplay.html?bID=81
http://www.apress.com/book/supplemen...bID=81&sID=371

It contains a concise rundown on how COM works (and why it
was put together that way). And of course it discusses many
of the .NET interop attributes that influence how the CCW is
generated (which only helps if you own the source to the
..NET assembly).
Jul 21 '05 #2
Thanks for your reply.

Now just for curiosity; It seems to me as if it should be possible to
do this. (calling c# dll via c-style dll exports/calling conventions).
I would imagine that you could /start/ the dll the same way that the OS
/starts/ a normal .net exe.

What I mean by this is that the dll that you just made with c# should
as a compiler extra export some functions in the 'extern "C" ' style,
really by just wrapping some attributed functions.

When you call these functions with the c calling convention from just
about anywhere else, they will know to invoke the mscore dll, start the
runtime, do the parameter translation thing etc and run the "exported"
function/method /normally/ as if it really was a c dll as seen from the
outside.

You would obviously be limited in that you will not have access to your
c#/.net classes as such in that you will be confined to calling public
static methods, but this /is/ usefull.

At least from my limited perspective this should/can be implimented
similarly to how normal COM Interop is implimented since really the
same process is taking place.

Friendly Regards
Pieter Breed

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Asapi | last post by:
1. Are linkage convention and calling convention referring to the same thing? 2. Does calling convention differ between languages C and C++? 3. How does calling convention differ between...
8
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int...
7
by: Klaus Friese | last post by:
Hi, i'm currently working on a plugin for Adobe InDesign and i have some problems with that. I'm not really a c++ guru, maybe somebody here has an idea how to solve this. The plugin is...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
3
by: Mike | last post by:
Timeout Calling Web Service I am calling a .NET 1.1 web service from an aspx page. The web service can take several minutes to complete its tasks before returning a message to the aspx page. ...
2
by: Geler | last post by:
A theoretical question: Sorry if its a beginner question. Here is a quote from the MSDN explaning the C/C++ calling convention.. It demonstrates that the calling function is responsible to clean...
47
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
10
by: sulekhasweety | last post by:
Hi, the following is the definition for calling convention ,which I have seen in a text book, can anyone give a more detailed explanation in terms of ANSI - C "the requirements that a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.