473,383 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Calling unmanaged function pointer

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
Jan 11 '08 #1
0 2505

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jarmopy | last post by:
Hi, I have made a service with C# and calling that service class from another C# program with remoting. (Referendes from the calling program) That service class is configured so that garpage...
15
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that...
8
by: Johann Blake | last post by:
I need to call a C DLL function. The first parameter expects a pointer to a long. It returns a value at the address of the pointer. The second parameter expects a pointer to a pointer. It creates...
7
by: Lev | last post by:
Hi, I have an unmanaged pointer to a class that I want to hold in a managed class. I pass the pointer (from unmanaged code) in the constructor of the managed class, and at that point it has...
0
by: sklett | last post by:
I'm having a really hard time with wrapping an unmanaged class with a managed class, then calling that managed class from my C# code. I will show you the three pieces, then explain: --------...
1
by: H.B. | last post by:
Hi, I need to make a function that can display data on my Managed C++ app and be called by an unmanaged C++ DLL. Something like : void Form1::Form1_Load(System::Object * sender,...
9
by: Laurent | last post by:
Hello, I received a C++ DLL and I must include it in my C# programm. The problem is that I don't know how to convert the parameters from C++ to C#, specialy when there are pointers in it....
3
by: Klaus | last post by:
Hi, I have an existing VC 6 MFC application which communicates asynchronly with a VC 2005 managed code dll. I use an unmanaged base class with virtual functions to access methods in the MFC...
10
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.