鉴于以下代码中包含的细节我认为不相关(但可能会被删除):
class __declspec(uuid("{AD72C6C5-E48F-40CA-8F46-98916229144D}")) TMyInterface
: public IUnknown {
public:
virtual void GetValue(String &value) = 0;
};
template <typename T> class TInterfaceable : public T, public TMyInterface {
public:
__fastcall TInterfaceable(TComponent *Owner) : T(Owner)
{
}
HRESULT __stdcall QueryInterface(const GUID &IID, void **Obj)
{
return TComponent::QueryInterface(IID, (void *)Obj);
}
ULONG __stdcall AddRef()
{
return TComponent::_AddRef();
}
ULONG __stdcall Release()
{
return TComponent::_Release();
}
};
class PACKAGE TMyLabel : public TInterfaceable<TLabel> {
public:
__fastcall TTuningLabel(TComponent *Owner) : TInterfaceable<TLabel>(Owner)
{
}
virtual void GetValue(String &value)
{
value = this->Caption;
/* I get an access violation here. Read of address FFFFFE6C.
I break here and examine the value of the this pointer.
The this pointer address is very close to the access violation value */
/* Note: If I change the code to `value = "test"` I get a different
AV, this time Write of Address 0x005DC9B0 */
}
};
int main(void)
{
for (/*control in list of controls...*/) {
TControl * control = c;/* im looping thru testing a collection of controls */
TMyInterface *p = System::interface_cast<TMyInterface>(control);
if (p != NULL) {
/* This has been tested to only evaluate not null on the one
* control that actually implements the interface. */
String v;
p->GetValue(v);
ShowMessage(v);
}
}
}
我收到了访问冲突(请参阅位置代码注释)。这个指针似乎在调试器中有一个不正确的值,但这并不能解释写入参数时的访问冲突。
我想我可能违反了一些多重继承的多态规则或某些关于模板类的内容?
由于