Hi,
I need your help. I cant't export function from EXE and import it into DLL.
I'd like to tell me what I must do for my problem's decision.
This DLL is linked with that EXE - file.
Printable View
Hi,
I need your help. I cant't export function from EXE and import it into DLL.
I'd like to tell me what I must do for my problem's decision.
This DLL is linked with that EXE - file.
In exe Go to Menu Project\settings and on Link tab
type name of your yourdll.Lib file in Text box
Object\Library Module then compile exe.
before this don't ferget to declare function in dll as
extren "C" _dllspec(dllexport) void Function();
and declare same function in exe
as
extren "C" _dllspec(dllimport) void Function();
Please let me know if this works
Hi,
I meen to export function form .EXE module and then import this function into .DLL.
It cannot be done unless your EXE is a full server. And then you are not necessarily exporting functions, you are exporting COM objects. But it can be done that way.
What kind of function is it anyway?
Don't believe it. if you have 4.2 or higher version of the C++ use and dllimport storage-class attributes properly.
Hi,
Would you write some sample code please.
Thanks in advance !
Hi,
I'd like to use a simple C++ function, not any COM object. Is it necessary using of COM-based classes?
This is BS.
Okay if it is bs, then tell him how to do it.
I cannot see how to export a function from an exe into a dll without it being a COM full server. And to be honest why would you want to export from an EXE to a DLL?
Please enlighten me.
Are you saying that instead of
- an EXE calling a DLL function
you want to
- call the EXE function from the DLL?
If we are talking about the same thing, the way that you would do this that I am aware of is to supply a callback function to the DLL. In other words, the DLL defines a function pointer, and the EXE tells the DLL to set the function pointer to one of the functions in the EXE. Once this is done, the DLL makes an indirect call on the function pointer whenever it wants to call the EXE function.
This method has been used since 16-bit Windows. Back in those days, the function would have to be "exported" and the DLL would have to call MakeProcInstance() on the passed function pointer to get the thunk correct. For 32-bit Windows, you don't need to do this anymore.
If this is what you want, then this is the way of doing it. There is no need for COM or anything like that.
Regards,
Paul McKenzie
BS BS BS.
BS is a right term.
I will send you a code sample of class exported from exe to a dll.
Class CChildFrameInExe is used in the dll to derive CChildFrameInDLL. CChildFrameInDLL is used in exe to register template and use it as child frame of the app.
Good luck,
[email protected]
Hi,
I am interested in your "magical" EXE export - DLL import approach. If it works It could be an interesting technique. Could you post or send an example please?
Best Regards,
GBO.
Drago, see my response. And I think you have to be more clear as to what you are trying to do. Like I stated, if it is as simple as trying to make the DLL call an EXE function at certain points within the DLL, then the simple function pointer and callback mechanism is all that you need to do.
As a matter of fact, look at functions such as SetTimer(), EnumWindows(), etc. If you take a look at the prototypes to these Windows API functions, your application supplies an application defined callback function. This callback function is then called by, guess what?...KERNEL32.DLL, USER.EXE, or GDI.EXE!
If you don't understand function pointers, then the "sample code" that you want would be best served if you study how to call an indirect function given a function pointer. This is all you need to know, and is basic C++ with really nothing to do with Windows. Any good book on C++ (or even C) covers function pointers. This sounds like the easiest approach to me instead of fiddling around with importing/exporting/COM etc.
Regards,
Paul McKenzie
Hi,
Thank you very much. I'll try this.
Thanks once again !
If it does what it says then is great stuff. I posted the same problem some time ago but nobody bothered to answer. So I made a workaround.
My problem is that in the Exe module I have some classes/objects and from the DLL i want to call some of their methods (in the DLL I have the pointer to that object).
If you can bring the light to me, it will make me quite happy.
Rares
... But I thought YOU did the backups...
If anybody is still interested in this stuff send me e-mail and I will send you a sample back.
Just to bring this topic to everybodies attention again.
My conclusions after looking at John's sample code:
It is indeed possible to export some definitions from the EXE into a DLL.
When building the EXE it produces the export .lib file wich contains the definitions needed in the DLL.
On first pass, it cannot build the EXE because the Import.lib (from the DLL) is missing.
the Import DLL uses the export.lib (from the EXE) file. You can build the DLL and the import.lib file is produced.
Now the Export.EXE will build.
Sounds a lot like the mutual import problem regarding DLLs except now it is between a DLL and an EXE.
The practical use of this 'technique' is for everyone to decide on his own.
John - the Non-believers (me included)
1 - 0
Best regards,
GBO.
Thanks GBO, your recognition is highly appreciated.
I would like to elaborate on some of your statements though.
I couldn’t agree more that “practical use of this 'technique' is for everyone to decide on his own”.
By the way 'technique' is the same as in DLL – both are executables anyway.
“Sounds a lot like the mutual import problem regarding DLLs except now it is between a DLL and an EXE.” - It is not like, it is exactly the same.
“It is indeed possible to export some definitions from the EXE into a DLL.” – It is possible to export all you can export from a DLL: classes, functions, global variables, global functions etcetera.
Good luck.
Dear Paul,
I have seen your reply for this problem and there you have mentioned about the sample code. I am looking for the same solution. So if you can send me the sample code, it will be a great help to me. My project is stucked up at this point and I am not able to go further with out that.
Thanks a lot.
Tarak Shah