Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

how to convert an exe application to a dll

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 ?

Comments

  • weiccoweicco Posts: 950Member
    : 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...
  • jtcoelhojtcoelho Posts: 44Member
    : : 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 ?

  • jtcoelhojtcoelho Posts: 44Member
    : : 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 ?
    :

  • weiccoweicco Posts: 950Member
    : : : 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.
  • jtcoelhojtcoelho Posts: 44Member
    : : : : 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.
  • jtcoelhojtcoelho Posts: 44Member
    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);

    }
  • weiccoweicco Posts: 950Member
    : 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(...)
Sign In or Register to comment.