Tech Support > Microsoft Windows > Development Resources > Finding DLL's HMODULE from within the running FARPROC
Finding DLL's HMODULE from within the running FARPROC
Posted by Beagle on May 9th, 2008


Folks,

I have the following running code. Line 5 attempts to pass the DLL
handle to the running DLL code (line 8) for use in later LoadResource
calls. This code results in a "Run-Time Check Failure #0" (Ref *1).
Not sure how to resolve this other than not write this kind of code,
but it seems to me that there is a better way to get the HMODULE/
HINSTANCE of the loaded DLL from within the exported function via
win32 call. Is that possible?

Thanks,
BEA

File : call_dll.c

1 typedef void (__stdcall *PFN_ASSIGN_DLL_HAN)(HINSTANCE hDll);

2 void mycall(void) {
3 HMODULE hDll = LoadLibrary(TEXT("mydll"));

4 PFN_ASSIGN_DLL_HAN Assign_Dll_handle = (PFN_ASSIGN_DLL_HAN)
GetProcAddress(hDll, "Assign_Dll_handle");

5 Assign_Dll_handle(hMir);
....
}

File : mydll.c

6 HINSTANCE theDll;

7 __declspec(dllexport) void Assign_Dll_handle(HINSTANCE hDll) {
8 theDll = hDll;
}

Ref:

*1 Run-Time Check Failure #0 - The value of ESP was not properly saved
across a function call. This is usually a result of calling a
function declared with one calling convention with a function pointer
declared with a different calling convention.

Posted by Beagle on May 9th, 2008


I want to compile the resources (e.g. Text, Bitmaps, Cursors, Dialogs,
Icons etc) into the DLL, then load them from there. Any ideas? That's
what I was trying to do here and got instead Extended Stack Pointer
run time error messages.

Thanks

On May 9, 11:16 am, Beagle <beagle...@hotmail.com> wrote:

Posted by mark on May 9th, 2008


Beagle wrote:
You don't need to export anything from a DLL to load a resource from
this DLL.

Posted by Beagle on May 9th, 2008


The original app was an exe. I changed the compile target from .exe
to .dll. The exe loads resources by a call to
GetModuleFileNameA(GetModuleHandle(NULL), szPath, MAX_PATH);, which as
an .exe works, but as a dll does not. However if I pass the hDLL
returned from the LoadLibrary call, resources are loaded properly.


On May 9, 1:27 pm, mark <m...@hilton.com> wrote:

Posted by Scott Seligman on May 9th, 2008


Beagle <beagle197@hotmail.com> wrote:
Your DLL's DllMain is given a handle to the DLL.

--
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
Money often costs too much.
-- Ralph Waldo Emerson

Posted by Norman Bullen on May 10th, 2008


Beagle wrote:

The message that you quoted here tells you exactly what the problem is.

You are using the __stdcall calling sequence (as declared in the
typedef) to call a function that is declared as __stdcall.

Either remove __stdcall from the typedef or add it to the declaration of
Assign_Dll_handle() in your DLL.
--
Norm

To reply, change domain to an adult feline.


Posted by Beagle on May 10th, 2008


Folks, thank you !

On May 9, 5:34 pm, Norman Bullen <n...@BlackKittenAssociates.com>
wrote:


Similar Posts