Hi!
I've got an issue. I have more or less an internal class model for
which I want to write various bindings e.g. for Windows COM. Now I've
figured to make my internal classes based on IDispatchEx which works
fine. The biggest pain I have right now is that I need to register
properties and methods dynamically and I need to call those
dynamically, too. Take the following example:
struct method {
short calltype; // 0=property_get, 1=property_set, 2=method
unsigned id;
const char* name;
int* params;
}
class A :
public MyTemplate<A>
{
public:
BEGIN_METHODS(A )
METHOD(0, "something" , 1, {})
METHOD(1, "something" , 2, {})
METHOD(2, "doSomethin g", 3, {4,5,2})
END_METHODS
public:
// Properties
virtual std::string get_Something() ;
virtual void set_Something(c onst std::string& name);
// Methods
virtual void doSomething();
}
Now in myTemplate I have two functions called from outside, one to get
an unique id for the given name and type and one for calling it. The
question I have is this:
The biggest pain is that I've wanted to call the functions that I have
registered with METHOD() macro directly, passing the parameters
dynamically as an array. But as I'd require my own call stack frame
and my asm knowledge is not the best, I've thought to create two
functions within my BEGIN_METHODS and END_METHODS macros that is, one
for registering the functions which could look like
static const method* _get_methods()
{
...
}
and one that calls it like
void _call_method(in t id, params* p)
{
switch( id)
{
case 2: doSomething(p[0].int, p[1].double);
....
}
Now as you can see the issue I have is that I cannot have my Macros
declare two independant functions that is, to be able to create a
_get_methods and a _call_method routine, I'd need to redeclare
evertything like this:
class A :
public MyTemplate<A>
{
public:
BEGIN_METHODS(A ) // _get_methods()
METHOD(0, "something" , 1, {})
METHOD(1, "something" , 2, {})
METHOD(2, "doSomethin g", 3, {4,5,2})
END_METHODS
BEGIN_METHODS2( A) // _call_method
METHOD(0, (p[0].int, p[1].double))
END_METHODS2
public:
// Properties
virtual std::string get_Something() ;
virtual void set_Something(c onst std::string& name);
// Methods
virtual void doSomething();
}
You might see my issue here -- I have to declare everything twice
which is not really nice.
So after fighting and trying and everything for days, I was hoping
that someone could help me out here with a smart advice, hint, help or
anything?
Thanks and Regards
Alexander 5 1860
Alexander Adam wrote:
Hi!
I've got an issue. I have more or less an internal class model for
which I want to write various bindings e.g. for Windows COM. Now I've
figured to make my internal classes based on IDispatchEx which works
fine. The biggest pain I have right now is that I need to register
properties and methods dynamically and I need to call those
dynamically, too. Take the following example:
struct method {
short calltype; // 0=property_get, 1=property_set, 2=method
unsigned id;
const char* name;
int* params;
}
class A :
public MyTemplate<A>
{
public:
BEGIN_METHODS(A )
METHOD(0, "something" , 1, {})
METHOD(1, "something" , 2, {})
METHOD(2, "doSomethin g", 3, {4,5,2})
END_METHODS
public:
// Properties
virtual std::string get_Something() ;
virtual void set_Something(c onst std::string& name);
// Methods
virtual void doSomething();
}
Now in myTemplate I have two functions called from outside, one to get
an unique id for the given name and type and one for calling it. The
question I have is this:
The biggest pain is that I've wanted to call the functions that I have
registered with METHOD() macro directly, passing the parameters
dynamically as an array. But as I'd require my own call stack frame
and my asm knowledge is not the best, I've thought to create two
functions within my BEGIN_METHODS and END_METHODS macros that is, one
for registering the functions which could look like
static const method* _get_methods()
{
...
}
and one that calls it like
void _call_method(in t id, params* p)
{
switch( id)
{
case 2: doSomething(p[0].int, p[1].double);
...
}
Now as you can see the issue I have is that I cannot have my Macros
declare two independant functions that is, to be able to create a
_get_methods and a _call_method routine, I'd need to redeclare
evertything like this:
class A :
public MyTemplate<A>
{
public:
BEGIN_METHODS(A ) // _get_methods()
METHOD(0, "something" , 1, {})
METHOD(1, "something" , 2, {})
METHOD(2, "doSomethin g", 3, {4,5,2})
END_METHODS
BEGIN_METHODS2( A) // _call_method
METHOD(0, (p[0].int, p[1].double))
END_METHODS2
public:
// Properties
virtual std::string get_Something() ;
virtual void set_Something(c onst std::string& name);
// Methods
virtual void doSomething();
}
You might see my issue here -- I have to declare everything twice
which is not really nice.
So after fighting and trying and everything for days, I was hoping
that someone could help me out here with a smart advice, hint, help or
anything?
Well, my honest advice would be give up and do something more productive
with your time. But I guess you don't want me to tell you that.
So.
Why not combine _get_methods and _call_method into a single function?
Any reason that can't be done? Sure it's ugly but you seem to be in ugly
territory anyway.
john
Hi,
Well, my honest advice would be give up and do something more productive
with your time. But I guess you don't want me to tell you that.
How is it you come to that opinion?
The issue here is just that the internal object model is quite huge (>
1800 classes) and I've started building COM Wrappers around each
object but it took way too much time to just implement a few classes
so I've decided to let each single class be the COM Object itself.
So.
Why not combine _get_methods and _call_method into a single function?
Any reason that can't be done? Sure it's ugly but you seem to be in ugly
territory anyway.
Uhm that's what I've tried first, too. The issue is just that I need
to register the function before using it within _call_method. This is
necessary to be able to check for parameters count, types etc. and
combining both into one function wouldn't really work in this case as
the code gets really really unusable. How's it you're saying that I
seem to be in ugly territory anyway, do you mean my C Code is ugly?
Well I've just written that as more or less pseudo code, not saying
that the original code looks as crappy as this one. Or is it that you
say calling dynamic functions is the ugly territory?
I'd be very thankful for some more hints on such kind of issue, I
can't believe I am the only one having this as calling dynamic
functions including dynamic parameters and returns seems to me as a
quite common problem?
Regards
Alexander
Alexander Adam wrote:
Hi!
I've got an issue. I have more or less an internal class model for
which I want to write various bindings e.g. for Windows COM.
If I understand you right, you have some classes written (presumably) in
C++, but you want to publish your framework via Microsoft COM to the
world. This involves a lot of work, as you can only define interfaces in
COM, whereas C++ mixes interfaces and implementation into single
entities. This means that you'll have to untangle interfaces from
implementations by hand, which is going to be quite time-consuming.
Now I've
figured to make my internal classes based on IDispatchEx which works
fine. The biggest pain I have right now is that I need to register
properties and methods dynamically and I need to call those
dynamically, too. Take the following example:
I don't believe that working with IDispatchEx is useful here, as you'll
need to work over your code completely. So instead of doing this, you
may as well start with defining real COM interfaces and make your C++
classes to implementors of these interfaces.
IDispatchEx as COM interface doesn't make sense to me, as it is intended
for dynamically adding properties and methods to objects. Adding
properties can be done by any container class, and adding methods is not
useful (as they cannot access private data members, and that is what
half of object-orientation is all about : encapsulation).
Anyway, if you're using IDispatchEx you'll have to be automation
compatible, and I very much doubt that your C++ framework is automation
compatible. I'd advice you to start introducing real COM (not using
IDispatchEx) interfaces in your project step by step.
Regards,
Stuart
On Mar 12, 2:10 am, "Alexander Adam" <cont...@emiasy s.comwrote:
....
Now as you can see the issue I have is that I cannot have my Macros
declare two independant functions that is, to be able to create a
_get_methods and a _call_method routine, I'd need to redeclare
evertything like this:
class A :
public MyTemplate<A>
{
public:
BEGIN_METHODS(A ) // _get_methods()
METHOD(0, "something" , 1, {})
METHOD(1, "something" , 2, {})
METHOD(2, "doSomethin g", 3, {4,5,2})
END_METHODS
BEGIN_METHODS2( A) // _call_method
METHOD(0, (p[0].int, p[1].double))
END_METHODS2
public:
// Properties
virtual std::string get_Something() ;
virtual void set_Something(c onst std::string& name);
// Methods
virtual void doSomething();
}
You might see my issue here -- I have to declare everything twice
which is not really nice.
....
class A :
public MyTemplate<A>
{
public:
#undef L
#define L(METHOD) \
METHOD(0, "something" , 1, {}) \
METHOD(1, "something" , 2, {}) \
METHOD(2, "doSomethin g", 3, {4,5,2})
GENERATE_GET(L)
GENERATE_CALL(L )
....
On the other hand, I'm not sure I see why you
can't go with a (macro-free) solution that just
uses an array:
int doSomethingPara m[] = {4,5,2};
method myMethods[] =
{
{"something" , 1, 0},
{"something" , 2, 0},
{"doSomethin g", 3, doSomethingPara m}
};
hi,
>
class A :
public MyTemplate<A>
{
public:
#undef L
#define L(METHOD) \
METHOD(0, "something" , 1, {}) \
METHOD(1, "something" , 2, {}) \
METHOD(2, "doSomethin g", 3, {4,5,2})
GENERATE_GET(L)
GENERATE_CALL(L )
...
On the other hand, I'm not sure I see why you
can't go with a (macro-free) solution that just
uses an array:
int doSomethingPara m[] = {4,5,2};
method myMethods[] =
{
{"something" , 1, 0},
{"something" , 2, 0},
{"doSomethin g", 3, doSomethingPara m}
};
I would love to go with a macro free solution but the issue is exactly
what you mention here -- how tp pass the doSomethingPara m over to the
dynamic function call? Because it is not one array of int but it can
be an array of different types and should go directly into the
function which could look like doSomething(int aNumber, string
aValue, ..)
Regards
Alexander This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Quansheng Liang |
last post by:
Hello,
I struggled with the problem of "undefined reference to `vtable ...`"
while migrating a project from windows to linux. After searching the
google I removed all the inline functions and now the link errors
decreased from over 200 to 5. A great step!
But one of my class derived from wxValidator can't be linked correctly
though there is no any inline function in it.
The error message:
-----------------------
|
by: Nolan Martin |
last post by:
Hello, I was wondering if it were possible to access the vtable directly.
Are there any resources that detail the inner workings of the vtable?
|
by: Karl Ebener |
last post by:
Hi!
I have created a program using several classes with inheritage. When I
compile and link, I get the following error:
:$ g++ service2.cpp Service.cpp Application.cpp Message.cpp
MessageQueue.cpp MessageFragmenter.cpp SingleMessage.cpp
/tmp/ccsrT4jU.o(.gnu.linkonce.t._ZN9c_ServiceD1Ev+0xb): In function
`c_Service::~c_Service ()':
: undefined reference to `vtable for c_Service'
|
by: Clint Ruen |
last post by:
Hello all,
I have written out a data structure using the binary flag on an
ofstream. The struct/class is something like this
class SomeData
{
public:
int data1;
|
by: rahul8143 |
last post by:
hello,
what happens to VTABLE when base class has virtual function and
derived class does not override it? Does derived class also builds
VTABLE if it has no functions?
eg. if code is like this(only demo code)
class a{
public:
virtual void fun()
{
cout<<"Base class";
| |
by: kish_nand |
last post by:
Could someone please explain me the concept behind virtual functions
and vtables. I am little confused about this. Please refer to the
following code and tell me how many virtual tables would be created and
what they would contain:
class base
{
virtual void display()
{
cout<<"base display"<<endl;
|
by: ypjofficial |
last post by:
Hello All,
I have read in many c++ literature that vtable is nothing but an array
of pointer to virtual functions inside a class.And the class where the
virtual function/s are declared stores the vfptr i.e the pointer to
vtable internally.
What confuses me is
if vtable is an array of pointer to virtual functions then as per the
properties of the array all the entries inside the array must be
same.i.e all the pointers should be of similar...
|
by: druberego |
last post by:
I read google and tried to find the solution myself. YES I do know that
you can get undefined references if you:
a) forget to implement the code for a prototype/header file item, or
b) you forget to pass all the necessary object files to the linker.
Neither of those are my problem. Please bear with me as the question
I ask is rather long and I think it's beyond a CS101 level of linker
stupidity. If it is a stupid CS101 mistake I'm making...
|
by: Ole Nielsby |
last post by:
James Kanze <james.kanze@gmail.comwrote:
COM does rely on vtable layout. COM interfaces are declared
as pure virtual classes, all methods using stdcall convention, and
this works because most (if not all) C++ compilers for the MSW
use a very similar vtable layout.
In COM, this is handled by proxies provided by system dlls,
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |