0

A third-party app I have can call extension DLLs if they have C-compliant interfaces as described below.

I would like the third-party app to call my C# DLL, since I would rather write in C# than C. (Maybe my other choice would be to write a C DLL wrapper to call my C# DLL, which is an extra step that I might not get right).

I've searched the net and SO but haven't found (or recognized) a good match to my question.

The best suggestion seemed to be this special marshalling declarations in the C# code here: Calling a C# DLL from C; linking problems

Is it possible to write a C# DLL that has a C-compliant interface like the one below? If so, could someone tell me what I have to do or point me to some documentation?

The third-party app documentation says, "The DLL function must be a PASCAL function that takes a single LPCSTR (long pointer to a constant string) argument. C or C++ DLL functions called must have prototypes equivalent to:

extern "C" __declspec(dllexport) void __stdcall fn(LPCTSTR szParam );
Kevin
  • 1,548
  • 2
  • 19
  • 34
  • 1
    It is not possible to make the C# functions directly callable from C since the C# code must run on the CLR. The 2 approaches I have used are: 1-write your C# code to be a COM DLL using COM callable wrappers, or 2-write a wrapper for the C# code using C++/CLI. – Moby Disk May 31 '20 at 06:02

1 Answers1

0

Take a look at this article: https://www.codeproject.com/Articles/12512/Using-the-CDECL-calling-convention-in-C-changing

It discusses a different problem (opposite to yours) but also explains the linkage of C# functions - by default C# uses __stdcall (and it cannot be overridden). This means your third party app should be able to call the C# function as it stands. Have you tried it? Did you get any errors?

Catch22
  • 391
  • 2
  • 5