| Re: Finding DLL's HMODULE from within the running FARPROC |
|
 |
|
 |
|
 |
|
 |
Author: Beagle Date: May 9, 2008 21:08
Folks, thank you !
On May 9, 5:34 pm, Norman Bullen BlackKittenAssociates.com>
wrote:
> Beagle wrote:
>> 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.
>
> 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.
|