exporting functions from a c# dll

  • Thread starter Thread starter Joshua Emele
  • Start date Start date
J

Joshua Emele

Hello -

I am new to c# having come from the land of c.
With c, I could create a .def file:

library cdll
exports
foo @1
bar @2

and the linker would magically make available these functions at the
specified ordinals:

Dump of file cdll.dll

File Type: DLL

Section contains the following exports for cdll.dll

00000000 characteristics
3FA177EF time date stamp Thu Oct 30 12:43:27 2003
0.00 version
1 ordinal base
2 number of functions
2 number of names

ordinal hint RVA name

2 0 0001131B bar
1 1 0001146A foo

how can I do the same with csharp?
Thanks in advance,
Joshua Emele
 
Joshua, if you want to make your functions available to other .Net code you
don't have to do anything, the compiler will take care of that for you. If
you want to make them available to a COM based app you will have to make
your assembly COM accessible. You can do this by setting 'Register for COM
Interop' to true in the project's properties.
 
Joshua, if you want to make your functions available to other .Net code
you
don't have to do anything, the compiler will take care of that for you.

I would like to import the functions into a legacy app written in c.
If you want to make them available to a COM based app you will have to make
your assembly COM accessible. You can do this by setting 'Register for COM
Interop' to true in the project's properties.

My understanding is the Register for COM Interop setting will cause a COM
type library to be created and registered.
I would prefer to avoid this route.

Ideally I would like to:

LoadLibrary(...);
GetProcAddress(...);
pfn(...);

Is there a way to do this?
Cheers,
Joshua
 
Joshua, you are right that that will create a COM wrapper around your
assembly. Unfortunately, .Net assemblies are only available through COM or
through a .Net app. You could write a C++ app which consumes your assembly
using VC++.Net if that helps at all. You might even be able to wrap your
assembly in C++ and export that for use with legacy C.
 
Back
Top