CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Posts
    336

    Calling DLL function that is not imported(MFC and WinMain)

    Hi

    We know that, WinMain is buried in the MFC Framework. OK but how can Windows call it?

    I opened MFC project in VC++ and tried to find out how it imports the dll(Mfc90ud.dll) and functions in that dll. But i couldn't find it. I also disassembled the mfc90ud.dll but there is no function like WinMain in exported function list. Function names are just numbers.

    So, I have 2 questions.

    1-) How does VS knows that Mfc90ud.dll must be imported and Windows know that it must call a function in a dll that is imported by EXE?

    2-) If i import a dll and although i do not use one of the imported function in that dll, OS can still call that function? Or OS can only call imported dll functions which are used by exe?? If the function doesn't import by exe, it is never be called?

    Thanks...

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Calling DLL function that is not imported(MFC and WinMain)

    There are two common ways to access code in a dll, one is to load it into your process space explicitly through the LoadLibrary() and associated functions and the other is to link your code to a library that is essentially a stub that handles all the loading and mapping.

  3. #3
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Calling DLL function that is not imported(MFC and WinMain)

    Quote Originally Posted by sawer View Post
    1-) How does VS knows that Mfc90ud.dll must be imported and Windows know that it must call a function in a dll that is imported by EXE?
    In your project settings you specify if you want to use MFC, if you want to use unicode and if you want to link against debug or release library statically or dynamically. The IDE figures out what it should tell the linker.
    2-) If i import a dll and although i do not use one of the imported function in that dll, OS can still call that function? Or OS can only call imported dll functions which are used by exe?? If the function doesn't import by exe, it is never be called?
    I don't understand what you mean with the OS calling a function in your dll. How is it going to do that?
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  4. #4
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Calling DLL function that is not imported(MFC and WinMain)

    WinMain, main are functions called by framework when .exe or Dll are loaded. They have different rules and not included to exported functions list. See /ENTRY linker option:
    http://msdn.microsoft.com/en-us/libr...2e(VS.80).aspx
    Linker creates executable with entry point address. Entry point function is called when executable is loaded.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured