Call function undirectly
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Call function undirectly

Hybrid View

  1. #1
    Join Date
    Sep 2012
    Posts
    3

    Call function undirectly

    Hello
    I am programming an executable application (not a dll or any kind of library). I simply want an equivalent of calling function using GetProcAddress and not just a simple typedef because that method didn't seem to work for executable but only for dll developments. Here is a working example:


    typedef HRESULT (*pCoInit)(LPVOID);
    pCoInit CoInit = (pCoInit)GetProcAddress(LoadLibrary("ole32.dll"),"CoInitialize");

    CoInit will be called instead of CoInitialize.

    But when I try this code to generate an executable, when I double click the executable the program crashes. So I don't know if their is an alternative to GetProcAddress which can be used to build executable and not a dll. Also I don't know if loadlibrary can be used to load from a static library rather than a dynamic one or no, example ole32.lib instead of ole32.dll ?

    Regards
    Last edited by Emapat; October 1st, 2012 at 07:56 PM.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    11,978

    Re: Call function undirectly

    A static library is linked to your code, so LoadLibrary doesn't make sense as it's part of the executable and already loaded.

    If you already know the function's name, why do you want to call it using GetProcAddress?

  3. #3
    Join Date
    Sep 2012
    Posts
    3

    Re: Call function undirectly

    Thank you very mush for your help

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center