dmircea

Hello,

Sorry if this has been discussed, but I did not get any link.

I have the following scenario: one C# dll and one exe file. I want to call from the dll one function in the exe file.

Case 1) the exe file is a C++ CLI program.

Case 2) the exe file is a normal C/C++ exe (non-managed exe)

Which of these calls is possible A small sample or a link to a sample would be great.

Thank you.



Re: Visual C++ General call a C++ function from a C# dll

PatickG

AFAIK an EXE under Win32 does not export functions.

You should create a DLL to export functions.





Re: Visual C++ General call a C++ function from a C# dll

einaros

If the .exe is native you have to export the functions from it. As the previous poster said, using a dll would be preferred, but it's not necessary.





Re: Visual C++ General call a C++ function from a C# dll

PatickG

But how can you export a function from an exe I can export function from DLLs but i doní»t know how to do that in an Exe file

If i understood the poster right he has an c# dll and would like to call a function that is implemented in an exe

Or did i fully missunderstood the poster and he has an exe with that he would like to call a function that is in the C# DLL





Re: Visual C++ General call a C++ function from a C# dll

einaros

PatickG wrote:

But how can you export a function from an exe I can export function from DLLs but i doní»t know how to do that in an Exe file



Just as you would from a dll; __declspec(dllexport) from the .exe, and [DllImport()] it into the C# application.





Re: Visual C++ General call a C++ function from a C# dll

PatickG

Sounds logical... And ití»s also working. But i never seen that neither heard about that. And also doní»t see a reason to do so...





Re: Visual C++ General call a C++ function from a C# dll

limpduck

By my experience, export functions from an exe can be used:

1. Want to share a function from the exe like using dll. In this way, the calling process call LoadLibrary to map the exe into its space and get the adress of the function. Then call it.

2. One dll mapped into a host application wants to call a function provided by the calling process. In this way, the dll calls GetModuleHandle to get the handle of calling process. Then get the address and call the function.

Some people asked me if it possible to make App1 launch App2, and at the run-time, call an exported function of App2 from App1. I doubt it and never try. But I think for interprocess communication, maybe should use RPC or so.