|
-
Mar 6th, 2025, 09:02 PM
#1
Thread Starter
Hyperactive Member
[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.
-
Mar 6th, 2025, 11:41 PM
#2
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?
-
Mar 7th, 2025, 12:32 AM
#3
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..
-
Mar 7th, 2025, 04:40 AM
#4
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)
-
Mar 7th, 2025, 10:05 AM
#5
Thread Starter
Hyperactive Member
Re: Issue with GetProcAddress in that it will not return ptr
 Originally Posted by 2kaud
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.
-
Mar 7th, 2025, 10:59 AM
#6
Re: Issue with GetProcAddress in that it will not return ptr
 Originally Posted by FunkMonkey
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)
-
Mar 7th, 2025, 11:01 AM
#7
Thread Starter
Hyperactive Member
Re: Issue with GetProcAddress in that it will not return ptr
 Originally Posted by VanGoghGaming
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.
-
Mar 7th, 2025, 11:32 AM
#8
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!
-
Mar 7th, 2025, 02:48 PM
#9
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.
-
Mar 7th, 2025, 03:03 PM
#10
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.
-
Mar 7th, 2025, 03:18 PM
#11
Thread Starter
Hyperactive Member
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?
-
Mar 7th, 2025, 04:35 PM
#12
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.
-
Mar 7th, 2025, 05:09 PM
#13
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|