On 08/13/2017 08:55 AM, R.Wieser wrote:
> Manfred
>
>> It looks as if you are trying to coerce two different C++
>> runtime implementations in the same process space
>
> Uhmmm. Not quite, but somewhat ?
In fact this seems to be the case, from your replies below.
>
> [Quote=me]
> I'm calling an external (to the VC++ program) object (stored in a
> dynamically loaded DLL) which methods are based on the COM model, meaning
> that the first argument is supposed to be a 'this' reference.
>
> The reason for that is *that object might be written in a language other
> than VC++*, meaning that I can't even be certain it can access the
> processors registers.
> [/Quote]
>
>> which would be trouble (it is undefined behaviour at best).
>
> If you know a better (and ofcourse defined by the language) way to call to
> an external object (by way of a pointer table) I'm willing (understatement)
> to listen.
I don't think there is a way defined by the language (the standard does
not define an ABI), and in fact you mentioning COM leads to the
consideration that COM is /neither/ part of the standard /nor/ portable,
it is instead a proprietary technology made by Microsoft that only works
with itself: a COM server and a COM client must both share the COM
framework.
It is worth recalling that there are very good reasons for which you
/cannot/ create a COM object with new, even if it is a C++ object, and
you must use CoCreateInstance instead. There are very good reasons as
well for which you /cannot/ destroy a COM object with delete, even if it
is a C++ object, and you /must/ call Release() instead (and the reasons
go beyond reference counting).
Note also that part of COM is definition of the ABI, and if you look
into the headers generated by MIDL you see that they are carefully
crafted to fit this ABI under the assumption that they are compiled with
a Microsoft compiler, and thus they are not portable.
>
>> The question is if it works by coincidence or because it is correct.
>
> :-) If, as Kalle, mentions it, the vtable structure has never been defined
> the conclusion is rather simple: its by sheer coincidence -- even though the
> code itself is (functions) correct (yeah, I know thats a bit of a
> contradiction).
>
> On the other hand, A vtable is a simple list of pointers, and does not
> really seem prone to a(ny) sudden changes.
>
>> It is not clear if you are trying to destroy an object by explicitly
>> calling its destructor, which could also be trouble.
>
> Please re-ead the initial post of this thread. That is what this thread is
> all about. Can I do it (call the, as virtual declared, destructor and
> access an external object) ? What "gotyas" do I need to be aware of ?
>
> But as it turns out vc++ does not allow me to do so, as it refuses, even for
> a pure virtual destructor, to deliver the 'this' reference as the first
> argument, so using it is already off the table.
>
>>> You already got the vc++ end. Anything wrong with it ? How ?
>>
>> It depends on what is on the other end,
>
> Than you have a *big* problem on your hands, as I *can't say* what is on the
> other end.
*I* don't have any problem, it looks like you have.
>
> As mentioned, it might be written in vc++, but even than it might be from
> fully different compiler version. It might also be written in delphi,
> pascal, vbasic or any other language.
I even had a similar problem with different versions of MSVC++.
I had a DLL that was compiled with VC++, exposing some C++ classes. I
was using it in a VC++ project, only a different version (say e.g. 2008
vs 2010, it could be anything, I don't remember which exactly).
It turned out that the runtime implementation of the 'new' and 'delete'
operators was different in the two versions, thus causing the program to
fail at runtime.
In short, *I'm* (pretty-much)
> defining the ABI.
>
> Ofcourse, I've already created an ABI. But if you have a good reason to
> change the vc++ side (and reference to how it *should* be done!) than again,
> I'm willing to listen.
You have to follow the ABI of the other end, you can't define an ABI of
your own if you don't know the one of the component you are trying to
connect to. If you have no idea of what's there, I guess it's too bad...
>
>> It's not poteto potato. The 'this' pointer (not reference) is passed
>> by the C++ implementation,
>
> So when I use it to refer to a classes method ("MyObject->Destructor") its
> called a reference, but when I provide it as an argument
> ("->Destructor(MyObject)") / its provided (implicitily) its suddenly a
> pointer ? Yeah, that really makes talking about it so much easier. :-(
This shows confusion about what pointers are.
>
>> you should make clear what is the ABI specified by your implementation
>
> I already did. Several times. Starting with the example call posted in
> the initial message of my previous thread and repeated thruout both the
> threads
> As a reference, see the first paragraph in my first quote in this message.
That was not an ABI.
https://en.wikipedia.org/wiki/Application_binary_interface
>
> How many more times do I need to repeat that requirement ? :-(
>
>>> I guess I ment reference than.
>>
>> I guess you guessed wrong...
>
> Now *thats* helpfull. Not. :-(
It could have directed you into looking for a correct definition of
pointers and references. It is up to you if you are willing to.
>
> Regards,
> Rudy Wieser
>
>