Calling EXE Function Getting handle to calling exe

A

Abhishek

Hello All
I am able to call the function exported by Exe from a dll file
im getting the address of the function but whille calling that function im
getting access violation Error as bellow my code



Function Exported by EXE
void __declspec(dllexport) ExeFn()
{
MessageBox(NULL,"hi","From Exe",MB_OK);
}


Function call from Dll

HMODULE hModule;
LPTSTR modname;
hModule=GetModuleHandle("Placeholder.exe");
if (hModule == NULL)
{
hModule=(HMODULE)LoadLibrary ("Placeholder.exe");
}

FnPtrT FnPtr = (FnPtrT)::GetProcAddress((HMODULE)hModule, "ExeFn");
if(FnPtr)
{
MessageBox(NULL,(LPCTSTR)FnPtr,"Exec",MB_OK);
(*FnPtr)();
}



Followinf Error

Unhandled exception at 0xfffffff9 in Mayur.dll 0xC0000005: Access violation
reading location 0xfffffff9.
 
B

Bruno van Dooren [MVP VC++]

MessageBox(NULL,(LPCTSTR)FnPtr,"Exec",MB_OK);

You are casting a function pointer to a text pointer. Probably NOT a good
idea.
Is there a reason for this?

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top