Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3670
Number of posts: 9122

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
how to convert an exe application to a dll Posted by jtcoelho on 19 Nov 2003 at 7:32 AM
I am wondering if it's possible to convert an executable to a dll.
I wrote a windows application that is called by a 16bit application. I was thinking that it might be easier to just make the windows app a dll and then just call the winmain in the windows app from the 16bit app. Is it possible to do this ?
Report
Re: how to convert an exe application to a dll Posted by weicco on 21 Nov 2003 at 5:53 AM
: I am wondering if it's possible to convert an executable to a dll.
: I wrote a windows application that is called by a 16bit application. I was thinking that it might be easier to just make the windows app a dll and then just call the winmain in the windows app from the 16bit app. Is it possible to do this ?
:

Write little .def file and tell linker to use it with /DEF:file.def option. def-file defines entrypoints to DLL like this:

LIBRARY yourlibraryname
EXPORTS
WinMain

Oh, and write DllMain-entrypoint somewhere...
Report
Re: how to convert an exe application to a dll Posted by jtcoelho on 21 Nov 2003 at 11:24 AM
: : I am wondering if it's possible to convert an executable to a dll.
: : I wrote a windows application that is called by a 16bit application. I was thinking that it might be easier to just make the windows app a dll and then just call the winmain in the windows app from the 16bit app. Is it possible to do this ?
: :
:
: Write little .def file and tell linker to use it with /DEF:file.def option. def-file defines entrypoints to DLL like this:
:
: LIBRARY yourlibraryname
: EXPORTS
: WinMain
:
: Oh, and write DllMain-entrypoint somewhere...
:
Much appreciated, thanks. But i have a stupid question. Where do i use the DLLMain entry point ? In the WinMain file ?

Report
Re: how to convert an exe application to a dll Posted by weicco on 22 Nov 2003 at 2:14 AM
: : : I am wondering if it's possible to convert an executable to a dll.
: : : I wrote a windows application that is called by a 16bit application. I was thinking that it might be easier to just make the windows app a dll and then just call the winmain in the windows app from the 16bit app. Is it possible to do this ?
: : :
: :
: : Write little .def file and tell linker to use it with /DEF:file.def option. def-file defines entrypoints to DLL like this:
: :
: : LIBRARY yourlibraryname
: : EXPORTS
: : WinMain
: :
: : Oh, and write DllMain-entrypoint somewhere...
: :
: Much appreciated, thanks. But i have a stupid question. Where do i use the DLLMain entry point ? In the WinMain file ?
:
:

It doesn't really matter if you do all the initialization stuff in WinMain. Stick DllMain-stub where ever you like, best place would propably be after DllMain. Just make that DllMain returns TRUE in all cases.
Report
Re: how to convert an exe application to a dll Posted by jtcoelho on 22 Nov 2003 at 5:59 AM
: : : : I am wondering if it's possible to convert an executable to a dll.
: : : : I wrote a windows application that is called by a 16bit application. I was thinking that it might be easier to just make the windows app a dll and then just call the winmain in the windows app from the 16bit app. Is it possible to do this ?
: : : :
: : :
: : : Write little .def file and tell linker to use it with /DEF:file.def option. def-file defines entrypoints to DLL like this:
: : :
: : : LIBRARY yourlibraryname
: : : EXPORTS
: : : WinMain
: : :
: : : Oh, and write DllMain-entrypoint somewhere...
: : :
: : Much appreciated, thanks. But i have a stupid question. Where do i use the DLLMain entry point ? In the WinMain file ?
: :
: :
:
: It doesn't really matter if you do all the initialization stuff in WinMain. Stick DllMain-stub where ever you like, best place would propably be after DllMain. Just make that DllMain returns TRUE in all cases.
:

Thanks again.
Report
Re: how to convert an exe application to a dll Posted by jtcoelho on 21 Nov 2003 at 11:42 AM
: : I am wondering if it's possible to convert an executable to a dll.
: : I wrote a windows application that is called by a 16bit application. I was thinking that it might be easier to just make the windows app a dll and then just call the winmain in the windows app from the 16bit app. Is it possible to do this ?
: :
:
: Write little .def file and tell linker to use it with /DEF:file.def option. def-file defines entrypoints to DLL like this:
:
: LIBRARY yourlibraryname
: EXPORTS
: WinMain
:
: Oh, and write DllMain-entrypoint somewhere...
One more question. What about the rc file, can i still use it or do i need to do anything with it ?
:

Report
Re: how to convert an exe application to a dll - Warning message Posted by jtcoelho on 24 Nov 2003 at 12:00 PM
I finally was able to get the dll working, but when i compile the executable that calls the dll i get the following warning message.

warning C4113: 'int (__stdcall *)()' differs in parameter lists from 'int (__stdcall *)(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int )'

The dll project has an entry point as well as the winmain function. I also declare the winmain in the calling program as int WINAPI WinMain(....);
then in the calling program i load the library that contains the exported function WinMain with an alias CMyFunc.
In the calling function i declare a function pointer as follows:
int (WINAPI * fptr)(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpCmdLine,int nShowCmd);
I use that function pointer to call GetProcAddress(hinst,"CMyFunc").
That's the line that gives me the warning message. Otherwise the program works fine, it calls the DLL and it's great. Thanks, but i am concerned about the warning because i think i am doing everything correctly. Any ideas anyone ?
Below is the code i am using in the calling program.
hinstLib = LoadLibrary("mirpdll.dll");
if( hinstLib != NULL)
{
fptr = GetProcAddress(hinstLib,"CMyFunc");
if (fRunTimeLinkSuccess = (fptr != NULL))
(fptr(hInst,NULL,str,0)) ;

// Free the DLL module.

fFreeResult = FreeLibrary(hinstLib);

}
Report
Re: how to convert an exe application to a dll - Warning message Posted by weicco on 24 Nov 2003 at 11:42 PM
: I finally was able to get the dll working, but when i compile the executable that calls the dll i get the following warning message.
:
: warning C4113: 'int (__stdcall *)()' differs in parameter lists from 'int (__stdcall *)(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int )'
:
: The dll project has an entry point as well as the winmain function. I also declare the winmain in the calling program as int WINAPI WinMain(....);
: then in the calling program i load the library that contains the exported function WinMain with an alias CMyFunc.
: In the calling function i declare a function pointer as follows:
: int (WINAPI * fptr)(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpCmdLine,int nShowCmd);
: I use that function pointer to call GetProcAddress(hinst,"CMyFunc").
: That's the line that gives me the warning message. Otherwise the program works fine, it calls the DLL and it's great. Thanks, but i am concerned about the warning because i think i am doing everything correctly. Any ideas anyone ?
: Below is the code i am using in the calling program.
: hinstLib = LoadLibrary("mirpdll.dll");
: if( hinstLib != NULL)
: {
: fptr = GetProcAddress(hinstLib,"CMyFunc");
: if (fRunTimeLinkSuccess = (fptr != NULL))
: (fptr(hInst,NULL,str,0)) ;
:
: // Free the DLL module.
:
: fFreeResult = FreeLibrary(hinstLib);
:
: }
:

Answer is simple :)

GetProcAddress returns pointer of type void (__stdcall *)(void). You need to cast it to correct form. In your case like this:

fptr = (int (WINAPI *)(HINSTANCE,HINSTANCE,LPSTR,int))GetProcAddress(...)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.