Results 1 to 13 of 13

Thread: [RESOLVED] Issue with GetProcAddress in that it will not return ptr

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2025
    Posts
    392

    Resolved [RESOLVED] Issue with GetProcAddress in that it will not return ptr

    Hi all,

    I have a program I'm writing in VBA for work. I have built a DLL, but it seems that I'm not accessing the functions. I have tried "user32" with messageboxw and was able to get the address. This tells me that there is something wrong with the compilation of the DLL, or some other reason.

    I'm not sure what's going on and would appreciate some input. Below are the sections of code that I am using. The first is the DLL defines, and the second is the loadlibrary code in VBA.

    Code:
    #pragma once
    
    #ifdef EPIQUTIL_EXPORTS
    #define EPIQUTIL_API __declspec(dllexport)
    #else
    #define EPIQUTIL_API __declspec(dllimport)
    #endif
    
    // The functions needed to interface with VBA EPIQ Utils
    
    // This function must be called before any other function.
    extern "C" EPIQUTIL_API void EPIQ_init(const long MyWaitTime);
    
    
    ----------------------------------------------------------------------------
    
    Calling routine.
    
        Dim ProcAddress As LongPtr
        Dim hinstLib As LongPtr
        Dim hFreeLib As LongPtr
        Dim szFunc As String
        
        hinstLib = 0
        ProcAddress = 0
        hFreeLib = 0
        ' Get a handle to the DLL module.
    '    If (bUseLibrary = True) Then
    '        Call SetEnvironmentVariable("PATH", "C:\Users\epperbx\source\repos\EPIQ Util DLL\x64\Debug")
            hinstLib = LoadLibrary("C:\Users\epperbx\source\repos\EPIQ Util DLL\Debug\EPIQ Util.dll")
     
            ' If the handle is valid, try to get the function address.
        
    '        If (hinstLib <> Null) Then
    '            szFunc = "EPIQ_Init"
                ProcAddress = GetProcAddress(hinstLib, "EPIQ_init")
                
                hFreeLib = FreeLibrary(hinstLib)
    Every little bit of information is very helpful.

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: Issue with GetProcAddress in that it will not return ptr

    Did you check with a PE tool (I usually use PE File Browser) that the function is indeed exported and under that name? And what's failing, the LoadLibrary call or the GetProcAddress call?

  3. #3
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,622

    Re: Issue with GetProcAddress in that it will not return ptr

    If this is a DLL that you made yourself, you probably forgot to export the functions. For example in VC++ 6.0 this is done in a ".def" file using an "EXPORTS" section where you list the functions you wish to export. Then you will be able to call GetProcAddress successfully but probably you want to use a "Declare" statement instead and call the function directly by name..

  4. #4
    Frenzied Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,169

    Re: Issue with GetProcAddress in that it will not return ptr

    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2025
    Posts
    392

    Re: Issue with GetProcAddress in that it will not return ptr

    Not sure how this helps, or why it matters that I posted 1 "SIMILAR" question and 1 same question on another website. Are you telling me that I should not be allowed to reach as many as possible to get an answer?

    Thanks.

  6. #6
    Frenzied Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,169

    Re: Issue with GetProcAddress in that it will not return ptr

    Quote Originally Posted by FunkMonkey View Post
    Not sure how this helps, or why it matters that I posted 1 "SIMILAR" question and 1 same question on another website. Are you telling me that I should not be allowed to reach as many as possible to get an answer?

    Thanks.
    No. it's just to let users know that there are potential answers elsewhere so that they don't spend time duplicating what already has been posted. It's good etiquette.

    eg. There's now a reply on codeguru asking if EPIQUTIL_EXPORTS has been properly defined.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2025
    Posts
    392

    Re: Issue with GetProcAddress in that it will not return ptr

    Quote Originally Posted by VanGoghGaming View Post
    If this is a DLL that you made yourself, you probably forgot to export the functions. For example in VC++ 6.0 this is done in a ".def" file using an "EXPORTS" section where you list the functions you wish to export. Then you will be able to call GetProcAddress successfully but probably you want to use a "Declare" statement instead and call the function directly by name..
    HI. I am allowing the compiler to export the function, unmangled, using extern "C".

    I do know that the return code is "Procedure not found" so I am positive it is with the DLL, but I can't track it down. After all, this is really a simple DLL and the extern "C" should have handled the exporting of the functions for me.

    Any other suggestions?
    Last edited by FunkMonkey; Mar 7th, 2025 at 11:47 AM.

  8. #8
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,622

    Re: Issue with GetProcAddress in that it will not return ptr

    You haven't specified what compiler you used but in VC++ (that comes with Visual Studio 6.0) you absolutely need an "EXPORTS" section if you want your functions to be visible outside the DLL.

    I've also suggested trying a "Declare" statement in VB6 the same as you would declare any other API function. If that returns "Entry point not found" then your function is definitely not exported!

  9. #9
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: Issue with GetProcAddress in that it will not return ptr

    Check with a PE file tool to see if it's exported. In addition to not being exported it could also be exported under a mangled name.

    If it's not exported or the name is mangled post the DLL code, .def file, and the compile command you're using.

  10. #10
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,622

    Re: Issue with GetProcAddress in that it will not return ptr

    I'm betting on the function not being exported at all. If it was exported with a mangled name you would still be able to "Declare" it using its ordinal number.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2025
    Posts
    392

    Re: Issue with GetProcAddress in that it will not return ptr

    Thanks all.

    So how do I build a .Def file and how do I place it in VC so that it will use it?

  12. #12
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,622

    Re: Issue with GetProcAddress in that it will not return ptr

    It's just a text file with a .def extension, just add it to the project and ask Copilot about the EXPORTS directive to provide you with the syntax.

  13. #13
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: Issue with GetProcAddress in that it will not return ptr


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