11

I have an executable written in C that has some functions in it that I would like to use from a c# application. I have written plenty of dlls before and was able to use functions in them by prepending __declspec(dllexport) to the function declaration. Can I do this from an executable? will the executable actually export the function?

2 Answers 2

9

Yes you can! Yes the executable will export the functions. This is not done very often, but it works pretty good. According the Specification (http://msdn.microsoft.com/en-us/gg463119.aspx) of the Executable, there is no difference between DLL and Executable as far as the Exports is concerned. EXE like DLL can have an Export Table directory that documents the functions that will be exported by the image. As an Example of a "normal" Executable exporting functions, have a look at Chrome.exe. See the snapshot I made using PEStudio showing Chrome exporting some functions. Some Windows built-in Executable also export functions (e.g. the Local Security Authority Subsystem - lsass.exe). The Windows Kernel (ntoskrnl.exe) image also exports more than 2000 functions (on a Windows7 system).

Sign up to request clarification or add additional context in comments.

1 Comment

But... how do you do that? __declspec(dllexport) didn't work with MSVC 2010 (which building Java 8 requires to use)
1

Yes. A PE file can export functions using __declspec(dllexport) or a .DEF file and GetProcAddress will return valid functional addresses which were exported by that EXE file. If PE imports a DLL function, then that imported function can access exported EXE function using GetProcAddress(GetModuleHandle(NULL),TEXT("exported_function")).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.