Hello!
I'm writing a .NET component that forwards calls to it's functions on to an
unmanaged DLL. This DLL is loaded dynamically using LoadLibrary and the
function pointers are retrieved using GetProcAddress.
The "references" to the unmanaged DLL are held inside my ref class.
See this example:
typedef BOOL (WINAPI *FUNC_PTR)(BOOL);
public ref class ManagedWrapperClass
{
....
HMODULE m_hUnmanagedDLL;
FUNC_PTR m_fpUnmanagedFunction;
}
Inside this ManagedWrapperClass, I have a function which loads the DLL and
then calls its function.
Example:
void ManagedWrapperClass::FunctionThatCallsTheDLL()
{
// Load the DLL
m_hUnmanagedDLL = LoadLibrary("Unmanaged.dll");
m_fpUnmanagedFunction = (FUNC_PTR)GetProcAddress(m_hUnmanagedDLL,
"UnmanagedFunction");
// now call it
m_fpUnmanagedFunction(1);
}
When debugging this thing, I see, that both, the handle to the DLL and the
address of the function is loaded correctly. But when calling the pointer, I
get an AccessViolationException.
I switched to disassembly mode and saw, that the generated call, that should
go to the functions address, is generated with a completely different
address which points to memory that cannot be read/write (somewhere above
0xf0000000).
What am I doing wrong?
Do I have to specify any attributes to the function pointer members?
Thanks very very much in advance!
Max