Re: Passing struct of virtual functions
- From: Pavel Minaev <int19h@xxxxxxxxx>
- Date: Wed, 16 Jul 2008 23:39:58 -0700 (PDT)
On Jul 16, 8:12 pm, ROLST5 <ROL...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I have a native win32 C++ DLL that has exported functions (I can't modify the
win32 DLL). One of these exported functions needs a pointer to a structure.
The structure contains virtual functions. I want to call the win32 function
from C# and pass it a ref to a struct of virtual functions - just as I would
from win32 C.
For example, I'm trying to call this exported win32 DLL function from C#.
I can call it from C#, but I can't get the C# mangling correct and it throws
exceptions at in the DLL at the location below.
bool initialize(ExportFuncs *f)
{
ExportFuncs *temp = f;
f->busWrite(... -> exception
}
The C struct look something like this
struct ExportFuncs{
public:
virtual int busWrite(long regNo, long data);
...
}
Possible?
Yes, it is possible, but it is highly dependent on the implementation
of virtual functions in your C++ compiler. Typically, it would be
something like this:
struct ExportFuncs {
struct VTable {
// _virtual_ functions in order declared in C++ header
Func<long, long, int> busWrite;
...
}
VTable* vtable;
// data members in order declared in C++ header
...
}
The above would probably work for Visual C++ unless struct is itself
inherited from another class.
.
- References:
- Passing struct of virtual functions
- From: ROLST5
- Passing struct of virtual functions
- Prev by Date: Re: Passing Structures to Unmanaged Code
- Next by Date: Re: Focus Stuck on TextBox
- Previous by thread: Passing struct of virtual functions
- Next by thread: Creatign new setting in userSettings section of app.config file
- Index(es):
Relevant Pages
|